lightning 4.10.1 → 4.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/grpc/protos/lightning.proto +20 -0
- package/grpc/protos/signer.proto +3 -0
- package/lnd_messages/close_channel_request.js +35 -0
- package/lnd_messages/index.js +5 -0
- package/lnd_messages/open_channel_request.js +51 -0
- package/lnd_messages/pay_via_route_request.js +61 -0
- package/lnd_methods/index.js +2 -0
- package/lnd_methods/macaroon/accept_rpc_request.js +44 -0
- package/lnd_methods/macaroon/handle_rpc_request_update.js +148 -0
- package/lnd_methods/macaroon/methods.json +9 -5
- package/lnd_methods/macaroon/reject_rpc_request.js +52 -0
- package/lnd_methods/macaroon/subscribe_to_rpc_requests.js +150 -49
- package/lnd_methods/macaroon/uris_for_method.js +8 -5
- package/lnd_methods/offchain/get_failed_payments.js +190 -0
- package/lnd_methods/offchain/get_payments.js +1 -3
- package/lnd_methods/offchain/index.js +2 -0
- package/lnd_methods/offchain/probe_for_route.js +5 -0
- package/lnd_responses/rpc_invoice_as_invoice.js +4 -2
- package/lnd_responses/rpc_payment_as_payment.js +71 -21
- package/package.json +3 -3
- package/test/lnd_messages/test_close_channel_request.js +72 -0
- package/test/lnd_messages/test_open_channel_request.js +87 -0
- package/test/lnd_messages/test_pay_via_route_request.js +79 -0
- package/test/lnd_methods/macaroon/test_accept_rpc_request.js +37 -0
- package/test/lnd_methods/macaroon/test_handle_rpc_request_update.js +237 -0
- package/test/lnd_methods/macaroon/test_reject_rpc_request.js +41 -0
- package/test/lnd_methods/macaroon/test_subscribe_to_rpc_requests.js +242 -0
- package/test/lnd_methods/macaroon/test_uris_for_method.js +10 -0
- package/test/lnd_methods/offchain/test_get_failed_payments.js +160 -0
- package/test/lnd_methods/offchain/test_get_payments.js +2 -2
- package/test/lnd_methods/onchain/test_close_channel.js +0 -1
- package/test/lnd_responses/test_rpc_invoice_as_invoice.js +34 -0
- package/test/lnd_responses/test_rpc_payment_as_payment.js +43 -8
- package/test/protos/protos.json +4 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const method = require('./../../../lnd_methods/macaroon/reject_rpc_request');
|
|
4
|
+
|
|
5
|
+
const tests = [
|
|
6
|
+
{
|
|
7
|
+
args: {},
|
|
8
|
+
description: 'A request id is required to reject an RPC request',
|
|
9
|
+
error: [400, 'ExpectedRequestIdToRejectRpcRequest'],
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
args: {id: 1},
|
|
13
|
+
description: 'A subscription is required to reject an RPC request',
|
|
14
|
+
error: [400, 'ExpectedRpcSubscriptionToRejectRpcRequest'],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
args: {id: 1, subscription: {write: ({}, cbk) => cbk('err')}},
|
|
18
|
+
description: 'Request error passed back',
|
|
19
|
+
error: [503, 'UnexpectedErrorRejectingRpcRequest', {err: 'err'}],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
args: {id: 1, subscription: {write: ({}, cbk) => cbk()}},
|
|
23
|
+
description: 'Request accepted',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
args: {id: 1, message: 'msg', subscription: {write: ({}, cbk) => cbk()}},
|
|
27
|
+
description: 'Request accepted with message',
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
32
|
+
return test(description, async ({end, equal, rejects}) => {
|
|
33
|
+
if (!!error) {
|
|
34
|
+
await rejects(() => method(args), error, 'Got expected error');
|
|
35
|
+
} else {
|
|
36
|
+
await method(args);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return end();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
const EventEmitter = require('events');
|
|
2
|
+
const {promisify} = require('util');
|
|
3
|
+
|
|
4
|
+
const {test} = require('@alexbosworth/tap');
|
|
5
|
+
|
|
6
|
+
const nextTick = promisify(process.nextTick);
|
|
7
|
+
const {subscribeToRpcRequests} = require('./../../../lnd_methods');
|
|
8
|
+
|
|
9
|
+
const makeArgs = overrides => {
|
|
10
|
+
const args = {
|
|
11
|
+
lnd: {
|
|
12
|
+
default: {
|
|
13
|
+
RegisterRPCMiddleware: ({}) => {
|
|
14
|
+
const emitter = new EventEmitter();
|
|
15
|
+
|
|
16
|
+
emitter.cancel = () => {};
|
|
17
|
+
emitter.write = ({}, cbk) => cbk();
|
|
18
|
+
|
|
19
|
+
process.nextTick(() => {
|
|
20
|
+
emitter.emit('data', {
|
|
21
|
+
request_id: '1',
|
|
22
|
+
raw_macaroon: Buffer.alloc(0),
|
|
23
|
+
custom_caveat_condition: '',
|
|
24
|
+
stream_auth: {method_full_uri: 'method_full_uri'},
|
|
25
|
+
intercept_type: 'stream_auth',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
emitter.emit('data', {});
|
|
29
|
+
|
|
30
|
+
emitter.emit('status', {status: 'status'});
|
|
31
|
+
emitter.emit('end', {});
|
|
32
|
+
emitter.emit('error', {details: 'Cancelled on client'});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return emitter;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
Object.keys(overrides).forEach(k => args[k] = overrides[k]);
|
|
42
|
+
|
|
43
|
+
return args;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const tests = [
|
|
47
|
+
{
|
|
48
|
+
args: makeArgs({id: '1234'}),
|
|
49
|
+
description: 'A long id is required to subscribe to RPC requests',
|
|
50
|
+
error: [400, 'ExpectedLongerIdLengthToSpecifyMiddlewareName'],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
args: makeArgs({lnd: undefined}),
|
|
54
|
+
description: 'LND is required to subscribe to rpc requests',
|
|
55
|
+
error: [400, 'ExpectedLndToSubscribeToRpcRequests'],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
args: makeArgs({
|
|
59
|
+
lnd: {
|
|
60
|
+
default: {
|
|
61
|
+
RegisterRPCMiddleware: ({}) => ({
|
|
62
|
+
on: (event, cbk) => {},
|
|
63
|
+
write: ({}, cbk) => cbk('err'),
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
description: 'RPC write errors are passed back',
|
|
69
|
+
error: [503, 'UnexpectedErrInterceptingRpcRequests', {err: 'err'}],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
args: makeArgs({
|
|
73
|
+
lnd: {
|
|
74
|
+
default: {
|
|
75
|
+
RegisterRPCMiddleware: ({}) => {
|
|
76
|
+
const emitter = new EventEmitter();
|
|
77
|
+
|
|
78
|
+
emitter.cancel = () => {};
|
|
79
|
+
emitter.write = (args, cbk) => {
|
|
80
|
+
if (!!args.feedback) {
|
|
81
|
+
return cbk('err');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return cbk();
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
process.nextTick(() => {
|
|
88
|
+
emitter.emit('data', {
|
|
89
|
+
request_id: '1',
|
|
90
|
+
raw_macaroon: Buffer.alloc(0),
|
|
91
|
+
custom_caveat_condition: '',
|
|
92
|
+
stream_auth: {method_full_uri: 'method_full_uri'},
|
|
93
|
+
intercept_type: 'stream_auth',
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return emitter;
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
description: 'RPC write errors are passed back',
|
|
103
|
+
expected: {
|
|
104
|
+
events: [
|
|
105
|
+
{id: 1, macaroon: undefined, uri: 'method_full_uri'},
|
|
106
|
+
[503, 'UnexpectedErrorAcceptingRpcRequest', {err: 'err'}],
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
args: makeArgs({}),
|
|
112
|
+
description: 'RPC request subscription is returned',
|
|
113
|
+
expected: {
|
|
114
|
+
events: [
|
|
115
|
+
{id: 1, macaroon: undefined, uri: 'method_full_uri'},
|
|
116
|
+
[503, 'ExpectedCustomCaveatConditionInRpcRequestUpdate'],
|
|
117
|
+
{details: 'Cancelled on client'},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
args: makeArgs({
|
|
123
|
+
lnd: {
|
|
124
|
+
default: {
|
|
125
|
+
RegisterRPCMiddleware: ({}) => ({
|
|
126
|
+
on: (event, cbk) => {},
|
|
127
|
+
write: ({}, cbk) => cbk('err'),
|
|
128
|
+
}),
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
}),
|
|
132
|
+
description: 'RPC write errors are passed back',
|
|
133
|
+
error: [503, 'UnexpectedErrInterceptingRpcRequests', {err: 'err'}],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
args: makeArgs({
|
|
137
|
+
is_intercepting_open_channel_requests: true,
|
|
138
|
+
lnd: {
|
|
139
|
+
default: {
|
|
140
|
+
OpenChannel: {
|
|
141
|
+
requestDeserialize: () => ({
|
|
142
|
+
close_address: 'close_address',
|
|
143
|
+
local_funding_amount: '1',
|
|
144
|
+
min_htlc_msat: '1',
|
|
145
|
+
node_pubkey: Buffer.alloc(33, 3),
|
|
146
|
+
node_pubkey_string: Buffer.alloc(33, 3).toString('hex'),
|
|
147
|
+
private: false,
|
|
148
|
+
push_sat: '1',
|
|
149
|
+
remote_csv_delay: 1,
|
|
150
|
+
sat_per_byte: '1',
|
|
151
|
+
sat_per_vbyte: '1',
|
|
152
|
+
spend_unconfirmed: true,
|
|
153
|
+
target_conf: 1,
|
|
154
|
+
}),
|
|
155
|
+
},
|
|
156
|
+
RegisterRPCMiddleware: ({}) => {
|
|
157
|
+
const emitter = new EventEmitter();
|
|
158
|
+
|
|
159
|
+
emitter.cancel = () => {};
|
|
160
|
+
emitter.write = ({}, cbk) => cbk();
|
|
161
|
+
|
|
162
|
+
process.nextTick(() => {
|
|
163
|
+
emitter.emit('data', {
|
|
164
|
+
request_id: '1',
|
|
165
|
+
raw_macaroon: Buffer.alloc(0),
|
|
166
|
+
custom_caveat_condition: '',
|
|
167
|
+
request: {
|
|
168
|
+
method_full_uri: '/lnrpc.Lightning/OpenChannel',
|
|
169
|
+
serialized: Buffer.alloc(0),
|
|
170
|
+
stream_rpc: false,
|
|
171
|
+
type_name: '',
|
|
172
|
+
},
|
|
173
|
+
intercept_type: 'request',
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return emitter;
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
}),
|
|
182
|
+
description: 'An open channel request is intercepted',
|
|
183
|
+
expected: {
|
|
184
|
+
events: [],
|
|
185
|
+
intercepts: [{
|
|
186
|
+
accept: true,
|
|
187
|
+
id: 1,
|
|
188
|
+
macaroon: undefined,
|
|
189
|
+
reject: true,
|
|
190
|
+
request: {
|
|
191
|
+
chain_fee_tokens_per_vbyte: 1,
|
|
192
|
+
cooperative_close_address: 'close_address',
|
|
193
|
+
give_tokens: 1,
|
|
194
|
+
is_private: undefined,
|
|
195
|
+
local_tokens: 1,
|
|
196
|
+
min_confirmations: 0,
|
|
197
|
+
min_htlc_mtokens: '1',
|
|
198
|
+
partner_public_key: '030303030303030303030303030303030303030303030303030303030303030303',
|
|
199
|
+
partner_csv_delay: 1,
|
|
200
|
+
},
|
|
201
|
+
uri: '/lnrpc.Lightning/OpenChannel',
|
|
202
|
+
}],
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
208
|
+
return test(description, async ({end, rejects, strictSame}) => {
|
|
209
|
+
if (!!error) {
|
|
210
|
+
await rejects(() => subscribeToRpcRequests(args), error, 'Got err');
|
|
211
|
+
} else {
|
|
212
|
+
const events = [];
|
|
213
|
+
const intercepts = [];
|
|
214
|
+
const res = await subscribeToRpcRequests(args);
|
|
215
|
+
|
|
216
|
+
res.subscription.on('error', event => events.push(event));
|
|
217
|
+
res.subscription.on('request', event => events.push(event));
|
|
218
|
+
|
|
219
|
+
res.subscription.on('open_channel_request', openRequest => {
|
|
220
|
+
return intercepts.push({
|
|
221
|
+
accept: !!openRequest.accept,
|
|
222
|
+
id: openRequest.id,
|
|
223
|
+
macaroon: openRequest.macaroon,
|
|
224
|
+
reject: !!openRequest.reject,
|
|
225
|
+
uri: openRequest.uri,
|
|
226
|
+
request: openRequest.request,
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
await nextTick();
|
|
231
|
+
|
|
232
|
+
if (!!expected.intercepts) {
|
|
233
|
+
strictSame(intercepts, expected.intercepts, 'Got expected intercepts');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
strictSame(events, expected.events, 'Got expected events');
|
|
237
|
+
strictSame(!!res.subscription, true, 'Got subscription');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return end();
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -9,6 +9,16 @@ const tests = [
|
|
|
9
9
|
description: 'A method is required',
|
|
10
10
|
error: 'ExpectedMethodNameToDeriveMacaroonUris',
|
|
11
11
|
},
|
|
12
|
+
{
|
|
13
|
+
args: {method: 'unknown'},
|
|
14
|
+
description: 'A known method is required',
|
|
15
|
+
error: 'ExpectedKnownMethodNameToDeriveMacaroonUris',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
args: {method: 'getPayment'},
|
|
19
|
+
description: 'Router server URI is returned',
|
|
20
|
+
expected: {uris: ['/routerrpc.Router/TrackPaymentV2']},
|
|
21
|
+
},
|
|
12
22
|
{
|
|
13
23
|
args: {method: 'grantAccess'},
|
|
14
24
|
description: 'Method URI is returned',
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {getPayments} = require('./../../../');
|
|
4
|
+
|
|
5
|
+
const makeLnd = args => {
|
|
6
|
+
return {
|
|
7
|
+
default: {
|
|
8
|
+
listPayments: ({}, cbk) => cbk(null, {
|
|
9
|
+
first_index_offset: args.first_index_offset || '1',
|
|
10
|
+
payments: [{
|
|
11
|
+
creation_date: '1',
|
|
12
|
+
creation_time_ns: '1',
|
|
13
|
+
failure_reason: '',
|
|
14
|
+
fee_msat: '1000',
|
|
15
|
+
fee_sat: '1',
|
|
16
|
+
htlcs: [],
|
|
17
|
+
path: [Buffer.alloc(33, 2).toString('hex')],
|
|
18
|
+
payment_hash: Buffer.alloc(32).toString('hex'),
|
|
19
|
+
payment_index: '1',
|
|
20
|
+
payment_preimage: Buffer.alloc(32).toString('hex'),
|
|
21
|
+
payment_request: '',
|
|
22
|
+
status: 'FAILED',
|
|
23
|
+
value: '1',
|
|
24
|
+
value_msat: '1000',
|
|
25
|
+
value_sat: '1',
|
|
26
|
+
}],
|
|
27
|
+
last_index_offset: args.last_index_offset || '1',
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const makeArgs = overrides => {
|
|
34
|
+
const args = {lnd: makeLnd({})};
|
|
35
|
+
|
|
36
|
+
Object.keys(overrides).forEach(k => args[k] = overrides[k]);
|
|
37
|
+
|
|
38
|
+
return args;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const makeExpectedPayment = ({}) => {
|
|
42
|
+
return {
|
|
43
|
+
destination: undefined,
|
|
44
|
+
attempts: [],
|
|
45
|
+
confirmed_at: undefined,
|
|
46
|
+
created_at: '1970-01-01T00:00:00.000Z',
|
|
47
|
+
fee: undefined,
|
|
48
|
+
fee_mtokens: undefined,
|
|
49
|
+
hops: [],
|
|
50
|
+
id: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
51
|
+
index: 1,
|
|
52
|
+
is_confirmed: false,
|
|
53
|
+
is_outgoing: true,
|
|
54
|
+
mtokens: '1000',
|
|
55
|
+
request: undefined,
|
|
56
|
+
secret: undefined,
|
|
57
|
+
safe_fee: undefined,
|
|
58
|
+
safe_tokens: 1,
|
|
59
|
+
tokens: 1,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const tests = [
|
|
64
|
+
{
|
|
65
|
+
args: makeArgs({limit: 1, token: 'token'}),
|
|
66
|
+
description: 'A limit cannot be passed with a token',
|
|
67
|
+
error: [400, 'UnexpectedLimitWhenPagingPaymentsWithToken'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
args: makeArgs({lnd: undefined}),
|
|
71
|
+
description: 'LND is required',
|
|
72
|
+
error: [400, 'ExpectedLndForGetPaymentsRequest'],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
args: makeArgs({token: 'token'}),
|
|
76
|
+
description: 'A valid token is required',
|
|
77
|
+
error: [400, 'ExpectedValidPagingTokenForPaymentReq'],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
args: makeArgs({lnd: {default: {listPayments: ({}, cbk) => cbk('err')}}}),
|
|
81
|
+
description: 'Errors from LND are passed back',
|
|
82
|
+
error: [503, 'UnexpectedGetPaymentsError', {err: 'err'}],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
args: makeArgs({lnd: {default: {listPayments: ({}, cbk) => cbk()}}}),
|
|
86
|
+
description: 'A response is expected from LND',
|
|
87
|
+
error: [503, 'ExpectedPaymentsInListPaymentsResponse'],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
args: makeArgs({
|
|
91
|
+
lnd: {default: {listPayments: ({}, cbk) => cbk(null, {})}},
|
|
92
|
+
}),
|
|
93
|
+
description: 'A response with payments is expected from LND',
|
|
94
|
+
error: [503, 'ExpectedPaymentsInListPaymentsResponse'],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
args: makeArgs({
|
|
98
|
+
lnd: {default: {listPayments: ({}, cbk) => cbk(null, {payments: []})}},
|
|
99
|
+
}),
|
|
100
|
+
description: 'A response with payments and last index is expected',
|
|
101
|
+
error: [503, 'ExpectedLastIndexOffsetWhenRequestingPayments'],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
args: makeArgs({
|
|
105
|
+
lnd: {
|
|
106
|
+
default: {
|
|
107
|
+
listPayments: ({}, cbk) => cbk(null, {
|
|
108
|
+
last_index_offset: '1',
|
|
109
|
+
payments: [{}],
|
|
110
|
+
}),
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
description: 'A response with valid payments is expected',
|
|
115
|
+
error: [503, 'ExpectedCreationDateInRpcPaymentDetails'],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
args: makeArgs({}),
|
|
119
|
+
description: 'A payment is returned',
|
|
120
|
+
expected: {payment: makeExpectedPayment({})},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
args: makeArgs({
|
|
124
|
+
lnd: {
|
|
125
|
+
default: {
|
|
126
|
+
listPayments: ({}, cbk) => cbk(null, {
|
|
127
|
+
last_index_offset: '1',
|
|
128
|
+
payments: [],
|
|
129
|
+
}),
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
description: 'No payments are returned',
|
|
134
|
+
expected: {},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
args: makeArgs({
|
|
138
|
+
lnd: makeLnd({first_index_offset: '2'}),
|
|
139
|
+
token: JSON.stringify({limit: 1, offset: 1})
|
|
140
|
+
}),
|
|
141
|
+
description: 'A payment is returned when a token is specified',
|
|
142
|
+
expected: {payment: makeExpectedPayment({})},
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
147
|
+
return test(description, async ({end, rejects, strictSame}) => {
|
|
148
|
+
if (!!error) {
|
|
149
|
+
await rejects(() => getPayments(args), error, 'Got expected error');
|
|
150
|
+
} else {
|
|
151
|
+
const {payments} = await getPayments(args);
|
|
152
|
+
|
|
153
|
+
const [payment] = payments;
|
|
154
|
+
|
|
155
|
+
strictSame(payment, expected.payment, 'Got expected payment');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return end();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -39,7 +39,7 @@ const makeLnd = args => {
|
|
|
39
39
|
path: [Buffer.alloc(33, 2).toString('hex')],
|
|
40
40
|
payment_hash: Buffer.alloc(32).toString('hex'),
|
|
41
41
|
payment_index: '1',
|
|
42
|
-
payment_preimage: Buffer.alloc(32).toString('hex'),
|
|
42
|
+
payment_preimage: Buffer.alloc(32, 1).toString('hex'),
|
|
43
43
|
payment_request: '',
|
|
44
44
|
status: 'SETTLED',
|
|
45
45
|
value: '1',
|
|
@@ -99,7 +99,7 @@ const makeExpectedPayment = ({}) => {
|
|
|
99
99
|
is_outgoing: true,
|
|
100
100
|
mtokens: '1000',
|
|
101
101
|
request: undefined,
|
|
102
|
-
secret: '
|
|
102
|
+
secret: Buffer.alloc(32, 1).toString('hex'),
|
|
103
103
|
safe_fee: 1,
|
|
104
104
|
safe_tokens: 1,
|
|
105
105
|
tokens: 1,
|
|
@@ -221,6 +221,40 @@ const tests = [
|
|
|
221
221
|
request: undefined,
|
|
222
222
|
}),
|
|
223
223
|
},
|
|
224
|
+
{
|
|
225
|
+
args: makeInput({payment_addr: Buffer.alloc(32)}),
|
|
226
|
+
description: 'Empty payment address is not returned as a pay addr',
|
|
227
|
+
expected: makeExpected({}),
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
args: makeInput({is_keysend: false}),
|
|
231
|
+
description: 'Non keysend is not push',
|
|
232
|
+
expected: makeExpected({is_push: undefined}),
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
args: makeInput({payment_addr: Buffer.alloc(32, 1)}),
|
|
236
|
+
description: 'Pay addr is returned as a payment id',
|
|
237
|
+
expected: makeExpected({
|
|
238
|
+
payment: '0101010101010101010101010101010101010101010101010101010101010101',
|
|
239
|
+
}),
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
args: makeInput({
|
|
243
|
+
fallback_addr: '',
|
|
244
|
+
description_hash: Buffer.alloc(0),
|
|
245
|
+
is_amp: true,
|
|
246
|
+
is_keysend: false,
|
|
247
|
+
payment_request: '',
|
|
248
|
+
settle_index: '0',
|
|
249
|
+
}),
|
|
250
|
+
description: 'Values are undefined',
|
|
251
|
+
expected: makeExpected({
|
|
252
|
+
chain_address: undefined,
|
|
253
|
+
confirmed_index: undefined,
|
|
254
|
+
description_hash: undefined,
|
|
255
|
+
request: undefined,
|
|
256
|
+
}),
|
|
257
|
+
},
|
|
224
258
|
];
|
|
225
259
|
|
|
226
260
|
tests.forEach(({args, description, error, expected}) => {
|
|
@@ -57,9 +57,9 @@ const makeArgs = overrides => {
|
|
|
57
57
|
path: [Buffer.alloc(33).toString('hex'), Buffer.alloc(33).toString('hex')],
|
|
58
58
|
payment_hash: Buffer.alloc(32).toString('hex'),
|
|
59
59
|
payment_index: '1',
|
|
60
|
-
payment_preimage: Buffer.alloc(32).toString('hex'),
|
|
60
|
+
payment_preimage: Buffer.alloc(32, 1).toString('hex'),
|
|
61
61
|
payment_request: 'lntb1500n1pdn4czkpp5ugdqer05qrrxuchrzkcue94th9w2xzasp9qm7d0yxcgp4uh4kn4qdpa2fjkzep6yprkcmmzv9kzqsmj09c8gmmrw4e8yetwvdujq5n9va6kcct5d9hkucqzysdlghdpua7uvjjkcfj49psxtlqzkp5pdncffdfk2cp3mp76thrl29qhqgzufm503pjj96586n5w6edgw3n66j4rxxs707y4zdjuhyt6qqe5weu4',
|
|
62
|
-
status: '
|
|
62
|
+
status: 'SETTLED',
|
|
63
63
|
value: '1',
|
|
64
64
|
value_msat: '1000',
|
|
65
65
|
value_sat: '1',
|
|
@@ -111,7 +111,7 @@ const makeExpected = overrides => {
|
|
|
111
111
|
request: 'lntb1500n1pdn4czkpp5ugdqer05qrrxuchrzkcue94th9w2xzasp9qm7d0yxcgp4uh4kn4qdpa2fjkzep6yprkcmmzv9kzqsmj09c8gmmrw4e8yetwvdujq5n9va6kcct5d9hkucqzysdlghdpua7uvjjkcfj49psxtlqzkp5pdncffdfk2cp3mp76thrl29qhqgzufm503pjj96586n5w6edgw3n66j4rxxs707y4zdjuhyt6qqe5weu4',
|
|
112
112
|
safe_fee: 1,
|
|
113
113
|
safe_tokens: 1,
|
|
114
|
-
secret: Buffer.alloc(32).toString('hex'),
|
|
114
|
+
secret: Buffer.alloc(32, 1).toString('hex'),
|
|
115
115
|
tokens: 1,
|
|
116
116
|
};
|
|
117
117
|
|
|
@@ -141,11 +141,6 @@ const tests = [
|
|
|
141
141
|
description: 'HTLC array is expected to be present',
|
|
142
142
|
error: 'ExpectedHtlcsArrayInRpcPaymentDetails',
|
|
143
143
|
},
|
|
144
|
-
{
|
|
145
|
-
args: makeArgs({htlcs: [], path: []}),
|
|
146
|
-
description: 'HTLC or path array is expected to be filled',
|
|
147
|
-
error: 'ExpectedAttemptInPaymentDetails',
|
|
148
|
-
},
|
|
149
144
|
{
|
|
150
145
|
args: makeArgs({path: undefined}),
|
|
151
146
|
description: 'A path is expected to be present',
|
|
@@ -186,6 +181,46 @@ const tests = [
|
|
|
186
181
|
description: 'A payment request is optional',
|
|
187
182
|
expected: makeExpected({request: undefined}),
|
|
188
183
|
},
|
|
184
|
+
{
|
|
185
|
+
args: makeArgs({htlcs: []}),
|
|
186
|
+
description: 'Attempts are optional',
|
|
187
|
+
expected: makeExpected({
|
|
188
|
+
attempts: [],
|
|
189
|
+
destination: '02212d3ec887188b284dbb7b2e6eb40629a6e14fb049673f22d2a0aa05f902090e',
|
|
190
|
+
fee: undefined,
|
|
191
|
+
fee_mtokens: undefined,
|
|
192
|
+
hops: [],
|
|
193
|
+
is_confirmed: false,
|
|
194
|
+
safe_fee: undefined,
|
|
195
|
+
secret: undefined,
|
|
196
|
+
}),
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
args: makeArgs({htlcs: [], payment_request: ''}),
|
|
200
|
+
description: 'Payment requests are optional when there are no attempts',
|
|
201
|
+
expected: makeExpected({
|
|
202
|
+
attempts: [],
|
|
203
|
+
destination: undefined,
|
|
204
|
+
fee: undefined,
|
|
205
|
+
fee_mtokens: undefined,
|
|
206
|
+
hops: [],
|
|
207
|
+
is_confirmed: false,
|
|
208
|
+
request: undefined,
|
|
209
|
+
safe_fee: undefined,
|
|
210
|
+
secret: undefined,
|
|
211
|
+
}),
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
args: makeArgs({payment_preimage: Buffer.alloc(32).toString('hex')}),
|
|
215
|
+
description: 'Empty preimage means not settled',
|
|
216
|
+
expected: makeExpected({
|
|
217
|
+
fee: undefined,
|
|
218
|
+
fee_mtokens: undefined,
|
|
219
|
+
is_confirmed: false,
|
|
220
|
+
safe_fee: undefined,
|
|
221
|
+
secret: undefined,
|
|
222
|
+
}),
|
|
223
|
+
},
|
|
189
224
|
{
|
|
190
225
|
args: makeArgs({
|
|
191
226
|
creation_date: '1587410235',
|
package/test/protos/protos.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"overrides": [
|
|
3
|
-
["lightning", 1162],
|
|
4
3
|
["lightning", 1168],
|
|
5
|
-
["lightning",
|
|
6
|
-
["lightning",
|
|
7
|
-
["lightning",
|
|
4
|
+
["lightning", 1174],
|
|
5
|
+
["lightning", 1182],
|
|
6
|
+
["lightning", 1189],
|
|
7
|
+
["lightning", 3378],
|
|
8
8
|
["router", 100],
|
|
9
9
|
["walletkit", 3],
|
|
10
10
|
["walletunlocker", 2]
|