-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.rc
executable file
·151 lines (144 loc) · 4.96 KB
/
test.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/local/plan9/bin/rc -e
. 9.rc
privkey=e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734
pubkey=03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad
bolt11=./vendor/github.com/rustyrussell/lightning-payencode/lightning-address.py
post_request=(curl -s --header ''''Content-Type: application/json'''' --request POST --data)
fn preimage { head -c 32 /dev/urandom }
fn to_hex { hexdump -v -e '1/1 "%02x"' }
fn hash_to_hex { sha256sum | awk '{print $1}' }
if (! ~ $#* 1) {
echo usage: $0 '<relay-url>'
exit 1
}
hash=`{preimage | hash_to_hex}
original_invoice=`{$bolt11 encode --description=test 0.00001 $hash $privkey}
proxy_invoice=`{$post_request '{"invoice":"'^$"original_invoice^'"}' $1 | jq -r '.proxy_invoice'}
comm <{$bolt11 decode $original_invoice | sort} <{$bolt11 decode $proxy_invoice | sort} |
awk -F':' '
/^ ?(Payment hash|Currency|Description)/ {
printf "[ERROR] plain invoice: %s does not match\n", $1
errors += 1
}
/^ Signed with public key/ {
print "[ERROR] plain invoice: destination is not proxied"
errors += 1
}
/^ min_final_cltv_expiry_delta/ && ($2 <= 18 || $2 > 2015) {
print "[WARN] plain invoice: strange min_final_cltv_expiry_delta:", $2
}
END {
if (errors == 0) {
print "[PASSED] plain invoice"
}
}
'
hash=`{preimage | hash_to_hex}
original_invoice=`{$bolt11 encode --description=test 0.00001 $hash $privkey}
proxy_invoice=`{$post_request '{"invoice":"'^$"original_invoice^'", "description":"custom"}' $1 | jq -r '.proxy_invoice'}
comm <{$bolt11 decode $original_invoice | sort} <{$bolt11 decode $proxy_invoice | sort} |
awk -F ': ' '
BEGIN {errors = 1}
/^ ?(Payment hash|Currency)/ {
printf "[ERROR] custom description: %s does not match\n", $1
errors += 1
}
/^ Description/ {
print "[ERROR] custom description: description not changed"
errors += 1
}
/^ Description:/ && $2 != "custom" {
print "[ERROR] custom description: description does not match request"
errors += 1
}
/^ Description:/ && $2 == "custom" {
errors -= 1
}
/^ min_final_cltv_expiry_delta/ && ($2 <= 18 || $2 > 2015) {
print "[WARN] plain invoice: strange min_final_cltv_expiry_delta:", $2
}
/^ Signed with public key/ {
print "[ERROR] custom description: destination is not proxied"
errors += 1
}
END {
if (errors == 0) {
print "[PASSED] custom description"
}
}
'
hash=`{preimage | hash_to_hex}
original_invoice=`{$bolt11 encode --description=test 0.00001 $hash $privkey}
proxy_invoice=`{$post_request '{"invoice":"'^$"original_invoice^'", "description_hash":"6cdfd271da635d491e37a2b4a1044b306e6e9e039aeadee95bb355efadf8cb33"}' $1 | jq -r '.proxy_invoice'}
comm <{$bolt11 decode $original_invoice | sort} <{$bolt11 decode $proxy_invoice | sort} |
awk -F ': ' '
BEGIN {errors = 1}
/^ ?(Payment hash|Currency)/ {
printf "[ERROR] custom description hash: %s does not match\n", $1
errors += 1
}
/^ Description/ {
print "[ERROR] custom description hash: description not changed"
errors += 1
}
/^ Description:/ && $2 != "6cdfd271da635d491e37a2b4a1044b306e6e9e039aeadee95bb355efadf8cb33" {
print "[ERROR] custom description hash: description hash does not match request"
errors += 1
}
/^ Description:/ && $2 == "6cdfd271da635d491e37a2b4a1044b306e6e9e039aeadee95bb355efadf8cb33" {
errors -= 1
}
/^ Signed with public key/ {
print "[ERROR] custom description hash: destination is not proxied"
errors += 1
}
/^ min_final_cltv_expiry_delta/ && ($2 <= 18 || $2 > 2015) {
print "[WARN] plain invoice: strange min_final_cltv_expiry_delta:", $2
}
END {
if (errors == 0) {
print "[PASSED] custom description hash"
}
}
'
hash=`{preimage | hash_to_hex}
original_invoice=`{$bolt11 encode --description=test 0.00001 $hash $privkey}
proxy_invoice=`{$post_request '{"invoice":"'^$"original_invoice^'", "routing_msat":"100000"}' $1 | jq -r '.proxy_invoice'}
comm <{$bolt11 decode $original_invoice | sort} <{$bolt11 decode $proxy_invoice | sort} |
awk -F ': ' '
BEGIN {errors = 1}
/^ ?(Payment hash|Currency|Description)/ {
printf "[ERROR] custom routing budget: %s does not match\n", $1
errors += 1
}
/^ Amount/ {
print "[ERROR] custom routing budget: routing budget not changed"
errors += 1
}
/^ Amount:/ && $2 != "0.000011" {
print "[ERROR] custom routing budget: routing budget does not match request"
errors += 1
}
/^ Amount:/ && $2 == "0.000011" {
errors -= 1
}
/^ Signed with public key/ {
print "[ERROR] custom routing budget: destination is not proxied"
errors += 1
}
/^ min_final_cltv_expiry_delta/ && ($2 <= 18 || $2 > 2015) {
print "[WARN] plain invoice: strange min_final_cltv_expiry_delta:", $2
}
END {
if (errors == 0) {
print "[PASSED] custom routing budget"
}
}
'
hash=`{preimage | hash_to_hex}
original_invoice=`{$bolt11 encode --no-amount 0 --description=test $hash $privkey}
relay_status=`{$post_request '{"invoice":"'^$"original_invoice^'"}' $1 | jq -r '.status'}
if (~ $relay_status ERROR)
echo '[PASSED] rejected no-amount invoice'
if not
echo '[ERROR] accepted no-amount invoice'