ln-service 53.7.1 → 53.7.2

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.
@@ -20,36 +20,40 @@ test(`Subscribe to peers`, async ({end, equal}) => {
20
20
 
21
21
  const [{generate, lnd}, target] = nodes;
22
22
 
23
- const sub = subscribeToPeers({lnd});
23
+ try {
24
+ const sub = subscribeToPeers({lnd});
24
25
 
25
- sub.on('error', () => {});
26
+ sub.on('error', () => {});
26
27
 
27
- await asyncRetry({interval, times}, async () => {
28
- await addPeer({lnd, public_key: target.id, socket: target.socket});
29
- });
28
+ await asyncRetry({interval, times}, async () => {
29
+ await addPeer({lnd, public_key: target.id, socket: target.socket});
30
+ });
30
31
 
31
- const disconnect = removePeer({lnd, public_key: target.id});
32
- const receiveDisconnect = once(sub, 'disconnected');
32
+ const disconnect = removePeer({lnd, public_key: target.id});
33
+ const receiveDisconnect = once(sub, 'disconnected');
33
34
 
34
- const [disconectMessage] = await all([receiveDisconnect, disconnect]);
35
+ const [disconectMessage] = await all([receiveDisconnect, disconnect]);
35
36
 
36
- const [disconnected] = disconectMessage;
37
+ const [disconnected] = disconectMessage;
37
38
 
38
- equal(disconnected.public_key, target.id, 'Got d/c event');
39
+ equal(disconnected.public_key, target.id, 'Got d/c event');
39
40
 
40
- const connect = asyncRetry({interval, times}, async () => {
41
- return addPeer({lnd, public_key: target.id, socket: target.socket});
42
- });
41
+ const connect = asyncRetry({interval, times}, async () => {
42
+ return addPeer({lnd, public_key: target.id, socket: target.socket});
43
+ });
43
44
 
44
- const receiveConnectMessage = once(sub, 'connected');
45
+ const receiveConnectMessage = once(sub, 'connected');
45
46
 
46
- const [connectMessage] = await all([receiveConnectMessage, connect]);
47
+ const [connectMessage] = await all([receiveConnectMessage, connect]);
47
48
 
48
- const [connected] = connectMessage;
49
+ const [connected] = connectMessage;
49
50
 
50
- equal(connected.public_key, target.id, 'Got connected');
51
-
52
- await kill({});
51
+ equal(connected.public_key, target.id, 'Got connected');
52
+ } catch (err) {
53
+ equal(err, null, 'Expected no error');
54
+ } finally {
55
+ await kill({});
56
+ }
53
57
 
54
58
  return end();
55
59
  });
@@ -83,14 +83,16 @@ test(`Get route through hops`, async ({end, equal, strictSame}) => {
83
83
  }
84
84
  });
85
85
 
86
- const res = await getRouteThroughHops({
87
- lnd,
88
- messages,
89
- cltv_delta: decodedRequest.cltv_delta + 6,
90
- mtokens: (BigInt(invoice.tokens) * BigInt(1e3)).toString(),
91
- payment: decodedRequest.payment,
92
- public_keys: route.hops.map(n => n.public_key),
93
- total_mtokens: invoice.mtokens,
86
+ const res = await asyncRetry({interval, times}, async () => {
87
+ return await getRouteThroughHops({
88
+ lnd,
89
+ messages,
90
+ cltv_delta: decodedRequest.cltv_delta + 6,
91
+ mtokens: (BigInt(invoice.tokens) * BigInt(1e3)).toString(),
92
+ payment: decodedRequest.payment,
93
+ public_keys: route.hops.map(n => n.public_key),
94
+ total_mtokens: invoice.mtokens,
95
+ });
94
96
  });
95
97
 
96
98
  await payViaRoutes({lnd, id: invoice.id, routes: [res.route]});
@@ -25,140 +25,148 @@ test(`Pay`, async ({end, equal, rejects, strictSame}) => {
25
25
 
26
26
  const [{generate, lnd}, target, remote] = nodes;
27
27
 
28
- const channel = await setupChannel({lnd, generate, to: target});
29
-
30
- const remoteChan = await setupChannel({
31
- generate: target.generate,
32
- lnd: target.lnd,
33
- to: remote,
34
- });
35
-
36
- await addPeer({lnd, public_key: remote.id, socket: remote.socket});
37
-
38
- const height = (await getHeight({lnd})).current_block_height;
39
- const invoice = await createInvoice({tokens, lnd: remote.lnd});
40
-
41
- const {features} = await decodePaymentRequest({
42
- lnd,
43
- request: invoice.request,
44
- });
45
-
46
- const expectedHops = [
47
- {
48
- channel: channel.id,
49
- channel_capacity: 1000000,
50
- fee: 1,
51
- fee_mtokens: '1000',
52
- forward: invoice.tokens,
53
- forward_mtokens: (BigInt(invoice.tokens) * BigInt(1e3)).toString(),
54
- public_key: target.id,
55
- },
56
- {
57
- channel: remoteChan.id,
58
- channel_capacity: 1000000,
59
- fee: 0,
60
- fee_mtokens: '0',
61
- forward: invoice.tokens,
62
- forward_mtokens: '100000',
63
- public_key: remote.id,
64
- },
65
- ];
66
-
67
- await waitForRoute({lnd, destination: remote.id, tokens: invoice.tokens});
68
-
69
28
  try {
70
- const paid = await payViaPaymentDetails({
71
- features,
72
- lnd,
73
- destination: remote.id,
74
- payment: invoice.payment,
75
- tokens: invoice.tokens,
76
- });
77
- } catch (err) {
78
- strictSame(err, [503, 'PaymentRejectedByDestination']);
79
- }
29
+ const channel = await setupChannel({lnd, generate, to: target});
80
30
 
81
- try {
82
- const tooSoonCltv = await payViaPaymentDetails({
83
- features,
84
- lnd,
85
- destination: remote.id,
86
- id: invoice.id,
87
- max_timeout_height: height + 46,
88
- payment: invoice.payment,
89
- tokens: invoice.tokens,
31
+ const remoteChan = await setupChannel({
32
+ generate: target.generate,
33
+ lnd: target.lnd,
34
+ to: remote,
90
35
  });
91
36
 
92
- equal(tooSoonCltv, null, 'Should not be able to pay a too soon CLTV');
93
- } catch (err) {
94
- strictSame(err, [503, 'PaymentPathfindingFailedToFindPossibleRoute'], 'Fail');
95
- }
37
+ await addPeer({lnd, public_key: remote.id, socket: remote.socket});
96
38
 
97
- try {
98
- const paid = await payViaPaymentDetails({
99
- features,
39
+ const height = (await getHeight({lnd})).current_block_height;
40
+ const invoice = await createInvoice({tokens, lnd: remote.lnd});
41
+
42
+ const {features} = await decodePaymentRequest({
100
43
  lnd,
101
- destination: remote.id,
102
- id: invoice.id,
103
- max_timeout_height: height + 90,
104
- messages: [{type: tlvType, value: tlvData}],
105
- payment: invoice.payment,
106
- tokens: invoice.tokens,
44
+ request: invoice.request,
107
45
  });
108
46
 
109
- equal(paid.confirmed_at > start, true, 'Confirm date was received');
110
- equal(paid.fee, 1, 'Fee tokens paid');
111
- equal(paid.fee_mtokens, '1000', 'Fee mtokens tokens paid');
112
- equal(paid.id, invoice.id, 'Payment hash is equal on both sides');
113
- equal(paid.mtokens, '101000', 'Paid mtokens');
114
- equal(paid.secret, invoice.secret, 'Paid for invoice secret');
115
-
116
- paid.hops.forEach(n => {
117
- equal(n.timeout === height + 40 || n.timeout === height + 43, true);
118
-
119
- delete n.timeout;
47
+ const expectedHops = [
48
+ {
49
+ channel: channel.id,
50
+ channel_capacity: 1000000,
51
+ fee: 1,
52
+ fee_mtokens: '1000',
53
+ forward: invoice.tokens,
54
+ forward_mtokens: (BigInt(invoice.tokens) * BigInt(1e3)).toString(),
55
+ public_key: target.id,
56
+ },
57
+ {
58
+ channel: remoteChan.id,
59
+ channel_capacity: 1000000,
60
+ fee: 0,
61
+ fee_mtokens: '0',
62
+ forward: invoice.tokens,
63
+ forward_mtokens: '100000',
64
+ public_key: remote.id,
65
+ },
66
+ ];
67
+
68
+ await waitForRoute({lnd, destination: remote.id, tokens: invoice.tokens});
69
+
70
+ try {
71
+ const paid = await payViaPaymentDetails({
72
+ features,
73
+ lnd,
74
+ destination: remote.id,
75
+ payment: invoice.payment,
76
+ tokens: invoice.tokens,
77
+ });
78
+ } catch (err) {
79
+ strictSame(err, [503, 'PaymentRejectedByDestination']);
80
+ }
120
81
 
121
- return;
122
- });
82
+ try {
83
+ const tooSoonCltv = await payViaPaymentDetails({
84
+ features,
85
+ lnd,
86
+ destination: remote.id,
87
+ id: invoice.id,
88
+ max_timeout_height: height + 46,
89
+ payment: invoice.payment,
90
+ tokens: invoice.tokens,
91
+ });
92
+
93
+ equal(tooSoonCltv, null, 'Should not be able to pay a too soon CLTV');
94
+ } catch (err) {
95
+ strictSame(
96
+ err,
97
+ [503, 'PaymentPathfindingFailedToFindPossibleRoute'],
98
+ 'Fail'
99
+ );
100
+ }
123
101
 
124
- strictSame(paid.hops, expectedHops, 'Hops are returned');
125
- } catch (err) {
126
- equal(err, null, 'No error is thrown when payment is attempted');
127
- }
102
+ try {
103
+ const paid = await payViaPaymentDetails({
104
+ features,
105
+ lnd,
106
+ destination: remote.id,
107
+ id: invoice.id,
108
+ max_timeout_height: height + 90,
109
+ messages: [{type: tlvType, value: tlvData}],
110
+ payment: invoice.payment,
111
+ tokens: invoice.tokens,
112
+ });
113
+
114
+ equal(paid.confirmed_at > start, true, 'Confirm date was received');
115
+ equal(paid.fee, 1, 'Fee tokens paid');
116
+ equal(paid.fee_mtokens, '1000', 'Fee mtokens tokens paid');
117
+ equal(paid.id, invoice.id, 'Payment hash is equal on both sides');
118
+ equal(paid.mtokens, '101000', 'Paid mtokens');
119
+ equal(paid.secret, invoice.secret, 'Paid for invoice secret');
120
+
121
+ paid.hops.forEach(n => {
122
+ equal(n.timeout === height + 40 || n.timeout === height + 43, true);
123
+
124
+ delete n.timeout;
125
+
126
+ return;
127
+ });
128
+
129
+ strictSame(paid.hops, expectedHops, 'Hops are returned');
130
+ } catch (err) {
131
+ equal(err, null, 'No error is thrown when payment is attempted');
132
+ }
128
133
 
129
- {
130
- const {payments} = await getInvoice({id: invoice.id, lnd: remote.lnd});
134
+ {
135
+ const {payments} = await getInvoice({id: invoice.id, lnd: remote.lnd});
131
136
 
132
- if (!!payments) {
133
- const [payment] = payments;
137
+ if (!!payments) {
138
+ const [payment] = payments;
134
139
 
135
- if (!!payment && !!payment.messages.length) {
136
- const [message] = payment.messages;
140
+ if (!!payment && !!payment.messages.length) {
141
+ const [message] = payment.messages;
137
142
 
138
- equal(message.type, tlvType, 'Got TLV type');
139
- equal(message.value, tlvData, 'Got TLV value');
143
+ equal(message.type, tlvType, 'Got TLV type');
144
+ equal(message.value, tlvData, 'Got TLV value');
145
+ }
140
146
  }
141
147
  }
142
- }
143
148
 
144
- {
145
- const {invoices} = await getInvoices({lnd: remote.lnd});
149
+ {
150
+ const {invoices} = await getInvoices({lnd: remote.lnd});
146
151
 
147
- const [{payments}] = invoices;
152
+ const [{payments}] = invoices;
148
153
 
149
- if (!!payments.length) {
150
- const [payment] = payments;
154
+ if (!!payments.length) {
155
+ const [payment] = payments;
151
156
 
152
- if (!!payment && !!payment.messages.length) {
153
- const [message] = payment.messages;
157
+ if (!!payment && !!payment.messages.length) {
158
+ const [message] = payment.messages;
154
159
 
155
- equal(message.type, tlvType, 'Got TLV type');
156
- equal(message.value, tlvData, 'Got TLV value');
160
+ equal(message.type, tlvType, 'Got TLV type');
161
+ equal(message.value, tlvData, 'Got TLV value');
162
+ }
157
163
  }
158
164
  }
165
+ } catch (err) {
166
+ equal(err, null, 'Expected no error');
167
+ } finally {
168
+ await kill({});
159
169
  }
160
170
 
161
- await kill({});
162
-
163
171
  return end();
164
172
  });
@@ -34,96 +34,100 @@ test('Probe for route', async ({end, equal, strictSame}) => {
34
34
  // Send coins to remote so that it can accept a channel
35
35
  await remote.generate({count});
36
36
 
37
- await setupChannel({
38
- generate,
39
- lnd,
40
- capacity: channelCapacityTokens + channelCapacityTokens,
41
- to: target,
42
- });
43
-
44
- await setupChannel({
45
- capacity: channelCapacityTokens,
46
- lnd: target.lnd,
47
- generate: target.generate,
48
- give: Math.round(channelCapacityTokens / 2),
49
- to: remote,
50
- });
51
-
52
- await addPeer({lnd, public_key: remote.id, socket: remote.socket});
53
-
54
- const invoice = await createInvoice({tokens, lnd: remote.lnd});
55
-
56
- await delay(1000);
57
-
58
37
  try {
59
- await probeForRoute({
38
+ await setupChannel({
39
+ generate,
60
40
  lnd,
61
- destination: remote.id,
62
- is_ignoring_past_failures: true,
63
- tokens: invoice.tokens,
41
+ capacity: channelCapacityTokens + channelCapacityTokens,
42
+ to: target,
64
43
  });
65
- } catch (err) {
66
- const [code, message, {failure}] = err;
67
44
 
68
- equal(code, 503, 'Failed to find route');
69
- equal(message, 'RoutingFailure', 'Hit a routing failure');
70
- equal(failure.reason, 'TemporaryChannelFailure', 'Temporary failure');
71
- }
45
+ await setupChannel({
46
+ capacity: channelCapacityTokens,
47
+ lnd: target.lnd,
48
+ generate: target.generate,
49
+ give: Math.round(channelCapacityTokens / 2),
50
+ to: remote,
51
+ });
72
52
 
73
- const {version} = await getWalletVersion({lnd});
53
+ await addPeer({lnd, public_key: remote.id, socket: remote.socket});
74
54
 
75
- const [, minor] = (version || '').split('.');
55
+ const invoice = await createInvoice({tokens, lnd: remote.lnd});
76
56
 
77
- if (!version || parseInt(minor) > 13) {
78
- const {payments} = await getFailedPayments({lnd});
57
+ await delay(1000);
79
58
 
80
- strictSame(payments, [], 'Probes do not leave a failed state behind');
81
- }
59
+ try {
60
+ await probeForRoute({
61
+ lnd,
62
+ destination: remote.id,
63
+ is_ignoring_past_failures: true,
64
+ tokens: invoice.tokens,
65
+ });
66
+ } catch (err) {
67
+ const [code, message, {failure}] = err;
82
68
 
83
- // Create a new channel to increase total edge liquidity
84
- await setupChannel({
85
- capacity: channelCapacityTokens,
86
- lnd: target.lnd,
87
- generate: target.generate,
88
- to: remote,
89
- });
69
+ equal(code, 503, 'Failed to find route');
70
+ equal(message, 'RoutingFailure', 'Hit a routing failure');
71
+ equal(failure.reason, 'TemporaryChannelFailure', 'Temporary failure');
72
+ }
90
73
 
91
- await deleteForwardingReputations({lnd});
74
+ const {version} = await getWalletVersion({lnd});
92
75
 
93
- await waitForRoute({lnd, destination: remote.id, tokens: invoice.tokens});
76
+ const [, minor] = (version || '').split('.');
94
77
 
95
- try {
96
- const {route} = await probeForRoute({
97
- lnd,
98
- destination: remote.id,
99
- payment: invoice.payment,
100
- tokens: invoice.tokens,
101
- total_mtokens: !!invoice.payment ? invoice.mtokens : undefined,
102
- });
78
+ if (!version || parseInt(minor) > 13) {
79
+ const {payments} = await getFailedPayments({lnd});
103
80
 
104
- if (!route) {
105
- throw new Error('ExpectedRouteFromProbe');
81
+ strictSame(payments, [], 'Probes do not leave a failed state behind');
106
82
  }
107
83
 
108
- equal(route.fee, 1, 'Found route fee');
109
- equal(route.fee_mtokens, '1500', 'Found route fee mtokens');
110
- strictSame(route.hops.length, 2, 'Found route hops returned');
111
- equal(route.mtokens, '500001500', 'Found route mtokens');
112
- equal(route.timeout >= 400, true, 'Found route timeout');
113
- equal(route.tokens, 500001, 'Found route tokens');
114
-
115
- const {secret} = await payViaRoutes({
116
- lnd,
117
- id: invoice.id,
118
- routes: [route],
84
+ // Create a new channel to increase total edge liquidity
85
+ await setupChannel({
86
+ capacity: channelCapacityTokens,
87
+ lnd: target.lnd,
88
+ generate: target.generate,
89
+ to: remote,
119
90
  });
120
91
 
121
- equal(secret, invoice.secret, 'Route works');
92
+ await deleteForwardingReputations({lnd});
93
+
94
+ await waitForRoute({lnd, destination: remote.id, tokens: invoice.tokens});
95
+
96
+ try {
97
+ const {route} = await probeForRoute({
98
+ lnd,
99
+ destination: remote.id,
100
+ payment: invoice.payment,
101
+ tokens: invoice.tokens,
102
+ total_mtokens: !!invoice.payment ? invoice.mtokens : undefined,
103
+ });
104
+
105
+ if (!route) {
106
+ throw new Error('ExpectedRouteFromProbe');
107
+ }
108
+
109
+ equal(route.fee, 1, 'Found route fee');
110
+ equal(route.fee_mtokens, '1500', 'Found route fee mtokens');
111
+ strictSame(route.hops.length, 2, 'Found route hops returned');
112
+ equal(route.mtokens, '500001500', 'Found route mtokens');
113
+ equal(route.timeout >= 400, true, 'Found route timeout');
114
+ equal(route.tokens, 500001, 'Found route tokens');
115
+
116
+ const {secret} = await payViaRoutes({
117
+ lnd,
118
+ id: invoice.id,
119
+ routes: [route],
120
+ });
121
+
122
+ equal(secret, invoice.secret, 'Route works');
123
+ } catch (err) {
124
+ equal(err, null, 'No error when probing for route');
125
+ }
122
126
  } catch (err) {
123
- equal(err, null, 'No error when probing for route');
127
+ equal(err, null, 'Expected no error');
128
+ } finally {
129
+ await kill({});
124
130
  }
125
131
 
126
- await kill({});
127
-
128
132
  return end();
129
133
  });