ln-service 53.6.0 → 53.7.3

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +11 -3
  3. package/index.js +2 -2
  4. package/package.json +5 -4
  5. package/test/integration/test_add_peer.js +26 -20
  6. package/test/integration/test_delete_pending_channel.js +5 -2
  7. package/test/integration/test_get_closed_channels.js +0 -2
  8. package/test/integration/test_get_failed_payments.js +123 -119
  9. package/test/integration/test_get_invoice.js +0 -1
  10. package/test/integration/test_get_node.js +65 -49
  11. package/test/integration/test_get_peers.js +32 -21
  12. package/test/integration/test_get_pending_force.js +1 -1
  13. package/test/integration/test_get_wallet_info.js +35 -18
  14. package/test/integration/test_open_channels.js +22 -15
  15. package/test/integration/test_pay.js +0 -1
  16. package/test/integration/test_pay_private_invoice.js +0 -1
  17. package/test/integration/test_propose_channel.js +438 -421
  18. package/test/integration/test_remove_peer.js +13 -9
  19. package/test/integration/test_send_message_to_peer.js +39 -28
  20. package/test/integration/test_subscribe_to_channels.js +1 -2
  21. package/test/integration/test_subscribe_to_invoices.js +80 -78
  22. package/test/integration/test_subscribe_to_peer_messages.js +81 -73
  23. package/test/integration/test_subscribe_to_peers.js +23 -19
  24. package/test/invoicesrpc-integration/test_get_sweep_transactions.js +0 -2
  25. package/test/invoicesrpc-integration/test_subscribe_cancel_invoice.js +0 -1
  26. package/test/macros/wait_for_channel.js +1 -1
  27. package/test/routerrpc-integration/test_delete_forwarding_reputations.js +61 -27
  28. package/test/routerrpc-integration/test_get_forwarding_reputations.js +74 -42
  29. package/test/routerrpc-integration/test_get_route_confidence.js +38 -34
  30. package/test/routerrpc-integration/test_get_route_through_hops.js +45 -17
  31. package/test/routerrpc-integration/test_multipath_payment.js +0 -1
  32. package/test/routerrpc-integration/test_pay_via_payment_details.js +118 -111
  33. package/test/routerrpc-integration/test_pay_via_payment_request.js +92 -80
  34. package/test/routerrpc-integration/test_pay_via_routes.js +19 -1
  35. package/test/routerrpc-integration/test_probe_for_route.js +78 -74
  36. package/test/routerrpc-integration/test_subscribe_to_forward_requests.js +2 -3
  37. package/test/routerrpc-integration/test_subscribe_to_forwards.js +518 -505
  38. package/test/routerrpc-integration/test_subscribe_to_past_payments.js +0 -3
  39. package/test/tower_clientrpc-integration/test_get_connected_watchtowers.js +0 -3
  40. package/test/walletrpc-integration/test_fund_psbt.js +113 -1
  41. package/test/walletrpc-integration/test_partially_sign_psbt.js +12 -5
  42. package/test/walletrpc-integration/test_sign_psbt.js +4 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Versions
2
2
 
3
+ ## 53.7.3
4
+
5
+ - `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
6
+
3
7
  ## 53.6.0
4
8
 
5
9
  - `partiallySignPsbt`: Add method to add a partial signature to a PSBT
package/README.md CHANGED
@@ -9,7 +9,7 @@ through npm.
9
9
 
10
10
  Supported LND versions:
11
11
 
12
- - v0.14.0-beta to v0.14.1-beta
12
+ - v0.14.0-beta to v0.14.2-beta
13
13
  - v0.13.0-beta to v0.13.4-beta
14
14
  - v0.12.0-beta to v0.12.1-beta
15
15
  - v0.11.0-beta to v0.11.1-beta
@@ -2530,7 +2530,7 @@ LND 0.11.1 and below do not return `last_reconnected` or `reconnection_rate`
2530
2530
  }]
2531
2531
  is_inbound: <Is Inbound Peer Bool>
2532
2532
  [is_sync_peer]: <Is Syncing Graph Data Bool>
2533
- [last_reconnected]: <Peer Last Reconnected At ISO 8601 Date String>
2533
+ [last_reconnection]: <Peer Last Reconnected At ISO 8601 Date String>
2534
2534
  ping_time: <Ping Latency Milliseconds Number>
2535
2535
  public_key: <Node Identity Public Key String>
2536
2536
  [reconnection_rate]: <Count of Reconnections Over Time Number>
@@ -3401,7 +3401,7 @@ Requires `onchain:write` permission
3401
3401
 
3402
3402
  Requires LND built with `walletrpc` tag
3403
3403
 
3404
- This method is not supported in LND 0.14.1 and below
3404
+ This method is not supported in LND 0.14.2 and below
3405
3405
 
3406
3406
  {
3407
3407
  lnd: <Authenticated LND API Object>
@@ -3706,6 +3706,10 @@ Requires `offchain:write` permission
3706
3706
  fee_mtokens: <Fee Millitokens String>
3707
3707
  forward: <Forward Tokens Number>
3708
3708
  forward_mtokens: <Forward Millitokens String>
3709
+ [messages]: [{
3710
+ type: <Message Type Number String>
3711
+ value: <Message Raw Value Hex Encoded String>
3712
+ }]
3709
3713
  [public_key]: <Public Key Hex String>
3710
3714
  timeout: <Timeout Block Height Number>
3711
3715
  }]
@@ -5692,6 +5696,10 @@ Requires `offchain:write` permission
5692
5696
  fee_mtokens: <Fee Millitokens String>
5693
5697
  forward: <Forward Tokens Number>
5694
5698
  forward_mtokens: <Forward Millitokens String>
5699
+ [messages]: [{
5700
+ type: <Message Type Number String>
5701
+ value: <Message Raw Value Hex Encoded String>
5702
+ }]
5695
5703
  public_key: <Public Key Hex String>
5696
5704
  timeout: <Timeout Block Height Number>
5697
5705
  }]
package/index.js CHANGED
@@ -91,7 +91,7 @@ const {requestChainFeeIncrease} = require('lightning');
91
91
  const {restrictMacaroon} = require('./macaroons');
92
92
  const {revokeAccess} = require('lightning');
93
93
  const {routeFromChannels} = require('bolt07');
94
- const {sendMessageToPeer} = require('lightning/lnd_methods');
94
+ const {sendMessageToPeer} = require('lightning');
95
95
  const {sendToChainAddress} = require('lightning');
96
96
  const {sendToChainAddresses} = require('lightning');
97
97
  const {sendToChainOutputScripts} = require('lightning');
@@ -118,7 +118,7 @@ const {subscribeToPastPayments} = require('lightning');
118
118
  const {subscribeToPayViaDetails} = require('lightning');
119
119
  const {subscribeToPayViaRequest} = require('lightning');
120
120
  const {subscribeToPayViaRoutes} = require('lightning');
121
- const {subscribeToPeerMessages} = require('lightning/lnd_methods');
121
+ const {subscribeToPeerMessages} = require('lightning');
122
122
  const {subscribeToPeers} = require('lightning');
123
123
  const {subscribeToProbeForRoute} = require('lightning');
124
124
  const {subscribeToRpcRequests} = require('lightning');
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "cors": "2.8.5",
12
12
  "express": "4.17.2",
13
13
  "invoices": "2.0.3",
14
- "lightning": "5.4.1",
14
+ "lightning": "5.6.2",
15
15
  "macaroon": "3.0.4",
16
16
  "morgan": "1.10.0",
17
17
  "ws": "8.4.2"
@@ -26,9 +26,9 @@
26
26
  "bitcoinjs-lib": "6.0.1",
27
27
  "bn.js": "5.2.0",
28
28
  "ecpair": "2.0.1",
29
- "ln-docker-daemons": "2.2.1",
29
+ "ln-docker-daemons": "2.2.4",
30
30
  "portfinder": "1.0.28",
31
- "psbt": "1.1.11",
31
+ "psbt": "2.0.0",
32
32
  "rimraf": "3.0.2",
33
33
  "secp256k1": "4.0.3",
34
34
  "tiny-secp256k1": "2.2.0",
@@ -54,6 +54,7 @@
54
54
  },
55
55
  "scripts": {
56
56
  "integration-test-daily-lnd-build": "DOCKER_LND_VERSION=daily-testing-only npm run test",
57
+ "integration-test-0.14.2": "DOCKER_LND_VERSION=v0.14.2-beta npm run test",
57
58
  "integration-test-0.14.1": "DOCKER_LND_VERSION=v0.14.1-beta npm run test",
58
59
  "integration-test-0.14.0": "DOCKER_LND_VERSION=v0.14.0-beta npm run test",
59
60
  "integration-test-0.13.4": "DOCKER_LND_VERSION=v0.13.4-beta npm run test",
@@ -65,5 +66,5 @@
65
66
  "integration-test-0.12.0": "DOCKER_LND_VERSION=v0.12.0-beta npm run test",
66
67
  "test": "echo $DOCKER_LND_VERSION && tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 200 test/autopilotrpc-integration/*.js test/chainrpc-integration/*.js test/integration/*.js test/invoicesrpc-integration/*.js test/routerrpc-integration/*.js test/signerrpc-integration/*.js test/tower_clientrpc-integration/*.js test/tower_serverrpc-integration/*.js test/walletrpc-integration/*.js"
67
68
  },
68
- "version": "53.6.0"
69
+ "version": "53.7.3"
69
70
  }
@@ -8,8 +8,8 @@ const {getPeers} = require('./../../');
8
8
 
9
9
  const interval = 100;
10
10
  const size = 2;
11
- const times = 100;
12
- const timeout = 1;
11
+ const times = 2000;
12
+ const timeout = 100;
13
13
 
14
14
  // Adding peers should result in a connected peer
15
15
  test(`Add a peer`, async ({end, equal}) => {
@@ -17,30 +17,36 @@ test(`Add a peer`, async ({end, equal}) => {
17
17
 
18
18
  const [{lnd}, target] = nodes;
19
19
 
20
- const connectedKeys = (await getPeers({lnd})).peers.map(n => n.public_key);
20
+ try {
21
+ const connectedKeys = (await getPeers({lnd})).peers.map(n => n.public_key);
21
22
 
22
- equal(connectedKeys.find(n => n === target.id), undefined, 'No peer');
23
+ equal(connectedKeys.find(n => n === target.id), undefined, 'No peer');
23
24
 
24
- await asyncRetry({interval, times}, async () => {
25
- await addPeer({
26
- lnd,
27
- timeout,
28
- public_key: target.id,
29
- socket: target.socket,
30
- });
31
-
32
- const {peers} = await getPeers({lnd});
25
+ await asyncRetry({interval, times}, async () => {
26
+ await addPeer({
27
+ lnd,
28
+ timeout,
29
+ public_key: target.id,
30
+ retry_count: 1,
31
+ retry_delay: 1,
32
+ socket: target.socket,
33
+ });
33
34
 
34
- const connected = peers.find(n => n.public_key === target.id);
35
+ const {peers} = await getPeers({lnd});
35
36
 
36
- if (!connected) {
37
- throw new Error('ExpectedConnectionToTarget');
38
- }
37
+ const connected = peers.find(n => n.public_key === target.id);
39
38
 
40
- equal(connected.public_key, target.id, 'Connected to remote node');
41
- });
39
+ if (!connected) {
40
+ throw new Error('ExpectedConnectionToTarget');
41
+ }
42
42
 
43
- await kill({});
43
+ equal(connected.public_key, target.id, 'Connected to remote node');
44
+ });
45
+ } catch (err) {
46
+ equal(err, null, 'Expected no error');
47
+ } finally {
48
+ await kill({});
49
+ }
44
50
 
45
51
  return end();
46
52
  });
@@ -5,6 +5,7 @@ const asyncRetry = require('async/retry');
5
5
  const {extractTransaction} = require('psbt');
6
6
  const {spawnLightningCluster} = require('ln-docker-daemons');
7
7
  const {test} = require('@alexbosworth/tap');
8
+ const tinysecp = require('tiny-secp256k1');
8
9
 
9
10
  const {addPeer} = require('./../../');
10
11
  const {broadcastChainTransaction} = require('./../../');
@@ -27,11 +28,13 @@ const count = 100;
27
28
  const interval = 100;
28
29
  const race = promises => Promise.race(promises);
29
30
  const size = 3;
30
- const timeout = 1000 * 5;
31
+ const timeout = 1000 * 20;
31
32
  const times = 200;
32
33
 
33
34
  // Forfeiting a pending channel should remove the pending channel
34
35
  test(`Forfeit pending channel`, async ({end, equal, strictSame}) => {
36
+ const ecp = (await import('ecpair')).ECPairFactory(tinysecp);
37
+
35
38
  const {kill, nodes} = await spawnLightningCluster({size});
36
39
 
37
40
  const [control, target, remote] = nodes;
@@ -105,7 +108,7 @@ test(`Forfeit pending channel`, async ({end, equal, strictSame}) => {
105
108
  funding: signRemote.psbt,
106
109
  });
107
110
 
108
- const {transaction} = extractTransaction({psbt: signRemote.psbt});
111
+ const {transaction} = extractTransaction({ecp, psbt: signRemote.psbt});
109
112
 
110
113
  await broadcastChainTransaction({lnd, transaction});
111
114
 
@@ -9,9 +9,7 @@ const {createHodlInvoice} = require('./../../');
9
9
  const {delay} = require('./../macros');
10
10
  const {payViaPaymentRequest} = require('./../../');
11
11
  const {getChainTransactions} = require('./../../');
12
- const {getChannels} = require('./../../');
13
12
  const {getClosedChannels} = require('./../../');
14
- const {getHeight} = require('./../../');
15
13
  const {getPendingChannels} = require('./../../');
16
14
  const {getSweepTransactions} = require('./../../');
17
15
  const {getUtxos} = require('./../../');
@@ -28,128 +28,132 @@ test('Get failed payments', async ({end, equal, strictSame}) => {
28
28
 
29
29
  const [{generate, lnd}, target, remote] = nodes;
30
30
 
31
- const {address} = await createChainAddress({lnd: remote.lnd});
32
-
33
- await generate({count});
34
-
35
- // Send coins to remote so that it can accept the channel
36
- await sendToChainAddress({lnd, address, tokens: channelCapacityTokens});
37
-
38
- // Generate to confirm the tx
39
- await generate({count: confirmationCount});
40
- await remote.generate({count: confirmationCount});
41
-
42
- await setupChannel({
43
- generate,
44
- lnd,
45
- capacity: channelCapacityTokens + channelCapacityTokens,
46
- to: target,
47
- });
48
-
49
- await setupChannel({
50
- capacity: channelCapacityTokens,
51
- lnd: target.lnd,
52
- generate: target.generate,
53
- generator: target,
54
- give: Math.round(channelCapacityTokens / 2),
55
- to: remote,
56
- });
57
-
58
- await addPeer({lnd, public_key: remote.id, socket: remote.socket});
59
-
60
- const invoice = await createInvoice({tokens, lnd: remote.lnd});
61
-
62
- const bigInvoice = await createInvoice({
63
- tokens: (channelCapacityTokens / 2) + (channelCapacityTokens / 4),
64
- lnd: remote.lnd,
65
- });
66
-
67
31
  try {
68
- await pay({lnd, request: bigInvoice.request});
69
- } catch (err) {
70
- }
71
-
72
- // Create a new channel to increase total edge liquidity
73
- await setupChannel({
74
- capacity: channelCapacityTokens,
75
- lnd: target.lnd,
76
- generate: target.generate,
77
- generator: target,
78
- to: remote,
79
- });
80
-
81
- await deleteForwardingReputations({lnd});
82
-
83
- await asyncRetry({times}, async () => {
84
- await pay({lnd, request: invoice.request});
85
- });
86
-
87
- {
88
- const {payments} = await getFailedPayments({lnd});
89
-
90
- const [payment] = payments.filter(n => n.mtokens === bigInvoice.mtokens);
91
-
92
- equal(payment.destination, remote.id, 'Payment to');
93
- equal(payment.confirmed_at, undefined, 'No confirmation date');
94
- equal(!!payment.created_at, true, 'Got payment created date');
95
- equal(payment.fee, undefined, 'No fee when not paid');
96
- equal(payment.fee_mtokens, undefined, 'No fee mtokens when not paid');
97
- equal(!!payment.id, true, 'Got a payment id');
98
- equal(!!payment.index, true, 'Got payment index');
99
- equal(payment.is_confirmed, false, 'Failed payment is not confirmed');
100
- equal(payment.is_outgoing, true, 'Failed payment is outgoing');
101
- equal(payment.mtokens, bigInvoice.mtokens, 'Payment has mtokens');
102
- equal(payment.request, bigInvoice.request, 'Probe has a request');
103
- equal(payment.secret, undefined, 'Failed has no secret');
104
- equal(payment.safe_fee, undefined, 'Failed has no fee');
105
- equal(payment.safe_tokens, bigInvoice.tokens, 'Failed has safe tokens');
106
- equal(payment.tokens, bigInvoice.tokens, 'Failed has tokens');
107
-
108
- const gotFailed = await getPayment({lnd, id: payment.id});
109
-
110
- strictSame(
111
- gotFailed,
112
- {
113
- failed: {
114
- is_insufficient_balance: false,
115
- is_invalid_payment: false,
116
- is_pathfinding_timeout: false,
117
- is_route_not_found: true,
32
+ const {address} = await createChainAddress({lnd: remote.lnd});
33
+
34
+ await generate({count});
35
+
36
+ // Send coins to remote so that it can accept the channel
37
+ await sendToChainAddress({lnd, address, tokens: channelCapacityTokens});
38
+
39
+ // Generate to confirm the tx
40
+ await generate({count: confirmationCount});
41
+ await remote.generate({count: confirmationCount});
42
+
43
+ await setupChannel({
44
+ generate,
45
+ lnd,
46
+ capacity: channelCapacityTokens + channelCapacityTokens,
47
+ to: target,
48
+ });
49
+
50
+ await setupChannel({
51
+ capacity: channelCapacityTokens,
52
+ lnd: target.lnd,
53
+ generate: target.generate,
54
+ generator: target,
55
+ give: Math.round(channelCapacityTokens / 2),
56
+ to: remote,
57
+ });
58
+
59
+ await addPeer({lnd, public_key: remote.id, socket: remote.socket});
60
+
61
+ const invoice = await createInvoice({tokens, lnd: remote.lnd});
62
+
63
+ const bigInvoice = await createInvoice({
64
+ tokens: (channelCapacityTokens / 2) + (channelCapacityTokens / 4),
65
+ lnd: remote.lnd,
66
+ });
67
+
68
+ try {
69
+ await pay({lnd, request: bigInvoice.request});
70
+ } catch (err) {
71
+ }
72
+
73
+ // Create a new channel to increase total edge liquidity
74
+ await setupChannel({
75
+ capacity: channelCapacityTokens,
76
+ lnd: target.lnd,
77
+ generate: target.generate,
78
+ generator: target,
79
+ to: remote,
80
+ });
81
+
82
+ await deleteForwardingReputations({lnd});
83
+
84
+ await asyncRetry({times}, async () => {
85
+ await pay({lnd, request: invoice.request});
86
+ });
87
+
88
+ {
89
+ const {payments} = await getFailedPayments({lnd});
90
+
91
+ const [payment] = payments.filter(n => n.mtokens === bigInvoice.mtokens);
92
+
93
+ equal(payment.destination, remote.id, 'Payment to');
94
+ equal(payment.confirmed_at, undefined, 'No confirmation date');
95
+ equal(!!payment.created_at, true, 'Got payment created date');
96
+ equal(payment.fee, undefined, 'No fee when not paid');
97
+ equal(payment.fee_mtokens, undefined, 'No fee mtokens when not paid');
98
+ equal(!!payment.id, true, 'Got a payment id');
99
+ equal(!!payment.index, true, 'Got payment index');
100
+ equal(payment.is_confirmed, false, 'Failed payment is not confirmed');
101
+ equal(payment.is_outgoing, true, 'Failed payment is outgoing');
102
+ equal(payment.mtokens, bigInvoice.mtokens, 'Payment has mtokens');
103
+ equal(payment.request, bigInvoice.request, 'Probe has a request');
104
+ equal(payment.secret, undefined, 'Failed has no secret');
105
+ equal(payment.safe_fee, undefined, 'Failed has no fee');
106
+ equal(payment.safe_tokens, bigInvoice.tokens, 'Failed has safe tokens');
107
+ equal(payment.tokens, bigInvoice.tokens, 'Failed has tokens');
108
+
109
+ const gotFailed = await getPayment({lnd, id: payment.id});
110
+
111
+ strictSame(
112
+ gotFailed,
113
+ {
114
+ failed: {
115
+ is_insufficient_balance: false,
116
+ is_invalid_payment: false,
117
+ is_pathfinding_timeout: false,
118
+ is_route_not_found: true,
119
+ },
120
+ is_confirmed: false,
121
+ is_failed: true,
122
+ is_pending: false,
123
+ payment: undefined,
124
+ pending: undefined,
118
125
  },
119
- is_confirmed: false,
120
- is_failed: true,
121
- is_pending: false,
122
- payment: undefined,
123
- pending: undefined,
124
- },
125
- 'Got failed state'
126
- );
127
- }
128
-
129
- {
130
- const {payments} = await getPayments({lnd});
131
-
132
- const [payment] = payments;
133
-
134
- equal(payment.destination, remote.id, 'Paid to');
135
- equal(!!payment.confirmed_at, true, 'Got confirmation date');
136
- equal(!!payment.created_at, true, 'Got payment start date');
137
- equal(payment.fee, 1, 'Got fee paid');
138
- equal(payment.fee_mtokens, '1500', 'Got fee mtokens paid');
139
- strictSame(payment.hops, [target.id], 'Got hops');
140
- equal(!!payment.id, true, 'Got a payment id');
141
- equal(!!payment.index, true, 'Got payment index');
142
- equal(payment.is_confirmed, true, 'Failed payment is not confirmed');
143
- equal(payment.is_outgoing, true, 'Failed payment is outgoing');
144
- equal(payment.mtokens, invoice.mtokens, 'Payment has mtokens');
145
- equal(payment.request, invoice.request, 'Payment has a request');
146
- equal(!!payment.secret, true, 'Failed has no secret');
147
- equal(payment.safe_fee, 2, 'Failed has no fee');
148
- equal(payment.safe_tokens, invoice.tokens, 'Failed has safe tokens');
149
- equal(payment.tokens, invoice.tokens, 'Failed has tokens');
126
+ 'Got failed state'
127
+ );
128
+ }
129
+
130
+ {
131
+ const {payments} = await getPayments({lnd});
132
+
133
+ const [payment] = payments;
134
+
135
+ equal(payment.destination, remote.id, 'Paid to');
136
+ equal(!!payment.confirmed_at, true, 'Got confirmation date');
137
+ equal(!!payment.created_at, true, 'Got payment start date');
138
+ equal(payment.fee, 1, 'Got fee paid');
139
+ equal(payment.fee_mtokens, '1500', 'Got fee mtokens paid');
140
+ strictSame(payment.hops, [target.id], 'Got hops');
141
+ equal(!!payment.id, true, 'Got a payment id');
142
+ equal(!!payment.index, true, 'Got payment index');
143
+ equal(payment.is_confirmed, true, 'Failed payment is not confirmed');
144
+ equal(payment.is_outgoing, true, 'Failed payment is outgoing');
145
+ equal(payment.mtokens, invoice.mtokens, 'Payment has mtokens');
146
+ equal(payment.request, invoice.request, 'Payment has a request');
147
+ equal(!!payment.secret, true, 'Failed has no secret');
148
+ equal(payment.safe_fee, 2, 'Failed has no fee');
149
+ equal(payment.safe_tokens, invoice.tokens, 'Failed has safe tokens');
150
+ equal(payment.tokens, invoice.tokens, 'Failed has tokens');
151
+ }
152
+ } catch (err) {
153
+ strictSame(err, null, 'Expected no error');
154
+ } finally {
155
+ await kill({});
150
156
  }
151
157
 
152
- await kill({});
153
-
154
158
  return end();
155
159
  });
@@ -2,7 +2,6 @@ const {spawnLightningCluster} = require('ln-docker-daemons');
2
2
  const {test} = require('@alexbosworth/tap');
3
3
 
4
4
  const {createInvoice} = require('./../../');
5
- const {getHeight} = require('./../../');
6
5
  const {getInvoice} = require('./../../');
7
6
  const {pay} = require('./../../');
8
7
  const {setupChannel} = require('./../macros');
@@ -1,3 +1,4 @@
1
+ const asyncRetry = require('async/retry');
1
2
  const {spawnLightningCluster} = require('ln-docker-daemons');
2
3
  const {test} = require('@alexbosworth/tap');
3
4
 
@@ -15,8 +16,10 @@ const confirmationCount = 20;
15
16
  const defaultFee = 1e3;
16
17
  const defaultAliasLength = '00000000000000000000'.length;
17
18
  const feeRate = 21;
19
+ const interval = 10;
18
20
  const mtokPerTok = BigInt(1e3);
19
21
  const size = 3;
22
+ const times = 1000;
20
23
 
21
24
  // Getting a node should return the public graph node info
22
25
  test(`Get node`, async ({end, equal, strictSame}) => {
@@ -24,62 +27,75 @@ test(`Get node`, async ({end, equal, strictSame}) => {
24
27
 
25
28
  const [{generate, id, lnd}, target, remote] = nodes;
26
29
 
27
- const controlToTarget = await setupChannel({generate, lnd, to: target});
30
+ try {
31
+ const controlToTarget = await setupChannel({generate, lnd, to: target});
28
32
 
29
- const targetToRemote = await setupChannel({
30
- generate: target.generate,
31
- lnd: target.lnd,
32
- to: remote,
33
- });
34
-
35
- await updateRoutingFees({
36
- lnd,
37
- base_fee_tokens: baseFee,
38
- cltv_delta: cltvDelta,
39
- fee_rate: feeRate,
40
- transaction_id: controlToTarget.transaction_id,
41
- transaction_vout: controlToTarget.transaction_vout,
42
- });
43
-
44
- await addPeer({lnd, public_key: remote.id, socket: remote.socket});
45
-
46
- await delay(3000);
47
-
48
- const node = await getNode({lnd, public_key: id});
33
+ const targetToRemote = await setupChannel({
34
+ generate: target.generate,
35
+ lnd: target.lnd,
36
+ to: remote,
37
+ });
49
38
 
50
- {
51
- const {channels} = await getNode({
39
+ await updateRoutingFees({
52
40
  lnd,
53
- is_omitting_channels: true,
54
- public_key: id,
41
+ base_fee_tokens: baseFee,
42
+ cltv_delta: cltvDelta,
43
+ fee_rate: feeRate,
44
+ transaction_id: controlToTarget.transaction_id,
45
+ transaction_vout: controlToTarget.transaction_vout,
55
46
  });
56
47
 
57
- equal(channels.length, [].length, 'Channels are omitted')
58
- }
59
-
60
- if (!!node.channels.length) {
61
- const [{policies}] = node.channels;
62
-
63
- const policy = policies.find(n => n.public_key === id);
48
+ await asyncRetry({interval, times}, async () => {
49
+ await addPeer({
50
+ lnd,
51
+ public_key: remote.id,
52
+ retry_count: 1,
53
+ retry_delay: 1,
54
+ socket: remote.socket,
55
+ timeout: 1000,
56
+ });
57
+ });
64
58
 
65
- equal(BigInt(policy.base_fee_mtokens), BigInt(baseFee)*mtokPerTok, 'Base');
66
- equal(policy.cltv_delta, cltvDelta, 'Got expected cltv delta');
67
- equal(policy.fee_rate, feeRate, 'Got expected fee rate');
68
- equal(policy.is_disabled, false, 'Channel is not disabled');
69
- equal(policy.max_htlc_mtokens, '990000000', 'Max HTLC mtokens returned');
70
- equal(policy.min_htlc_mtokens, '1000', 'Min HTLC mtokens returned');
59
+ await delay(3000);
60
+
61
+ const node = await getNode({lnd, public_key: id});
62
+
63
+ {
64
+ const {channels} = await getNode({
65
+ lnd,
66
+ is_omitting_channels: true,
67
+ public_key: id,
68
+ });
69
+
70
+ equal(channels.length, [].length, 'Channels are omitted')
71
+ }
72
+
73
+ if (!!node.channels.length) {
74
+ const [{policies}] = node.channels;
75
+
76
+ const policy = policies.find(n => n.public_key === id);
77
+
78
+ equal(BigInt(policy.base_fee_mtokens), BigInt(baseFee)*mtokPerTok, 'bf');
79
+ equal(policy.cltv_delta, cltvDelta, 'Got expected cltv delta');
80
+ equal(policy.fee_rate, feeRate, 'Got expected fee rate');
81
+ equal(policy.is_disabled, false, 'Channel is not disabled');
82
+ equal(policy.max_htlc_mtokens, '990000000', 'Max HTLC mtokens returned');
83
+ equal(policy.min_htlc_mtokens, '1000', 'Min HTLC mtokens returned');
84
+ }
85
+
86
+ const [socket] = node.sockets;
87
+
88
+ equal(node.alias, id.slice(0, defaultAliasLength), 'Alias');
89
+ equal(node.color, '#3399ff', 'Color');
90
+ equal(node.sockets.length, 1, 'Socket');
91
+ equal(!!socket.socket, true, 'Ip, port');
92
+ equal(socket.type, 'tcp', 'Socket type');
93
+ equal(node.updated_at.length, 24, 'Update date');
94
+ } catch (err) {
95
+ strictSame(err, null, 'Expected no error');
96
+ } finally {
97
+ await kill({});
71
98
  }
72
99
 
73
- const [socket] = node.sockets;
74
-
75
- equal(node.alias, id.slice(0, defaultAliasLength), 'Alias');
76
- equal(node.color, '#3399ff', 'Color');
77
- equal(node.sockets.length, 1, 'Socket');
78
- equal(!!socket.socket, true, 'Ip, port');
79
- equal(socket.type, 'tcp', 'Socket type');
80
- equal(node.updated_at.length, 24, 'Update date');
81
-
82
- await kill({});
83
-
84
100
  return end();
85
101
  });