ln-service 52.14.4 → 53.0.0

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 (121) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +163 -11
  3. package/package.json +7 -14
  4. package/test/autopilotrpc-integration/test_autopilot.js +9 -15
  5. package/test/chainrpc-integration/test_get_height.js +7 -10
  6. package/test/chainrpc-integration/test_subscribe_to_blocks.js +52 -31
  7. package/test/chainrpc-integration/test_subscribe_to_chain_address.js +72 -66
  8. package/test/chainrpc-integration/test_subscribe_to_chain_spend.js +47 -16
  9. package/test/{integration → extra-integration}/test_recover_funds_from_channel.js +0 -0
  10. package/test/{integration → extra-integration}/test_recover_funds_from_channels.js +0 -0
  11. package/test/{integration → extra-integration}/test_restrict_macaroon.js +0 -0
  12. package/test/{integration → extra-integration}/test_revoke_access.js +0 -0
  13. package/test/{integration → extra-integration}/test_subscribe_to_rpc_requests.js +1 -1
  14. package/test/integration/test_add_peer.js +16 -12
  15. package/test/integration/test_cancel_pending_channel.js +20 -6
  16. package/test/integration/test_close_channel.js +15 -10
  17. package/test/integration/test_create_chain_address.js +3 -6
  18. package/test/integration/test_create_invoice.js +27 -23
  19. package/test/integration/test_decode_payment_request.js +30 -29
  20. package/test/integration/test_delete_payment.js +11 -8
  21. package/test/integration/test_delete_payments.js +13 -16
  22. package/test/integration/test_get_access_ids.js +4 -7
  23. package/test/integration/test_get_backup.js +12 -8
  24. package/test/integration/test_get_backups.js +8 -10
  25. package/test/integration/test_get_chain_balance.js +9 -53
  26. package/test/integration/test_get_chain_fee_estimate.js +21 -10
  27. package/test/integration/test_get_chain_transactions.js +30 -52
  28. package/test/integration/test_get_channel.js +7 -7
  29. package/test/integration/test_get_channel_balance.js +5 -6
  30. package/test/integration/test_get_channels.js +11 -10
  31. package/test/integration/test_get_closed_channels.js +169 -139
  32. package/test/integration/test_get_failed_payments.js +37 -39
  33. package/test/integration/test_get_fee_rates.js +6 -9
  34. package/test/integration/test_get_forwards.js +34 -35
  35. package/test/integration/test_get_invoice.js +7 -11
  36. package/test/integration/test_get_invoices.js +33 -30
  37. package/test/integration/test_get_methods.js +4 -7
  38. package/test/integration/test_get_network_centrality.js +14 -17
  39. package/test/integration/test_get_network_graph.js +12 -15
  40. package/test/integration/test_get_network_info.js +5 -6
  41. package/test/integration/test_get_node.js +15 -31
  42. package/test/integration/test_get_payments.js +10 -10
  43. package/test/integration/test_get_peers.js +10 -13
  44. package/test/integration/test_get_pending_coop.js +13 -18
  45. package/test/integration/test_get_pending_force.js +29 -21
  46. package/test/integration/test_get_route_to_destination.js +47 -40
  47. package/test/integration/test_get_utxos.js +17 -42
  48. package/test/integration/test_get_wallet_info.js +5 -12
  49. package/test/integration/test_open_channel.js +16 -9
  50. package/test/integration/test_open_channels.js +66 -66
  51. package/test/integration/test_pay.js +39 -36
  52. package/test/integration/test_pay_private_invoice.js +78 -72
  53. package/test/integration/test_payment_errors.js +13 -11
  54. package/test/integration/test_propose_channel.js +74 -53
  55. package/test/integration/test_push_funds.js +11 -15
  56. package/test/integration/test_rebalance.js +11 -22
  57. package/test/integration/test_remove_peer.js +13 -48
  58. package/test/integration/test_send_message_to_peer.js +25 -17
  59. package/test/integration/test_send_to_chain_address.js +60 -51
  60. package/test/integration/test_send_to_chain_addresses.js +30 -18
  61. package/test/integration/test_sign_message.js +3 -6
  62. package/test/integration/test_stop_daemon.js +3 -9
  63. package/test/integration/test_subscribe_to_backups.js +19 -11
  64. package/test/integration/test_subscribe_to_channels.js +28 -20
  65. package/test/integration/test_subscribe_to_graph.js +43 -22
  66. package/test/integration/test_subscribe_to_invoices.js +89 -103
  67. package/test/integration/test_subscribe_to_open_requests.js +47 -31
  68. package/test/integration/test_subscribe_to_peer_messages.js +51 -21
  69. package/test/integration/test_subscribe_to_peers.js +11 -16
  70. package/test/integration/test_subscribe_to_transactions.js +49 -45
  71. package/test/integration/test_update_routing_fees.js +12 -16
  72. package/test/integration/test_verify_access.js +5 -10
  73. package/test/integration/test_verify_backup.js +10 -8
  74. package/test/integration/test_verify_backups.js +11 -16
  75. package/test/integration/test_verify_message.js +6 -9
  76. package/test/invoicesrpc-integration/test_cancel_invoice.js +15 -22
  77. package/test/invoicesrpc-integration/test_get_sweep_transactions.js +15 -11
  78. package/test/invoicesrpc-integration/test_push_payment.js +53 -55
  79. package/test/invoicesrpc-integration/test_settle_invoice.js +25 -19
  80. package/test/invoicesrpc-integration/test_subscribe_cancel_invoice.js +13 -11
  81. package/test/invoicesrpc-integration/test_subscribe_settle_invoice.js +20 -15
  82. package/test/macros/btcsuite_type_daemon.js +1 -1
  83. package/test/macros/chain_send_transaction.js +1 -1
  84. package/test/macros/change_password.js +15 -13
  85. package/test/macros/generate_blocks.js +24 -29
  86. package/test/macros/rpc.js +1 -0
  87. package/test/macros/setup_channel.js +23 -9
  88. package/test/macros/spawn_lnd.js +3 -1
  89. package/test/macros/wait_for_channel.js +8 -3
  90. package/test/macros/wait_for_route.js +2 -2
  91. package/test/routerrpc-integration/test_delete_forwarding_reputations.js +15 -22
  92. package/test/routerrpc-integration/test_disable_channel.js +8 -12
  93. package/test/routerrpc-integration/test_get_forwarding_confidence.js +17 -37
  94. package/test/routerrpc-integration/test_get_forwarding_reputations.js +26 -25
  95. package/test/routerrpc-integration/test_get_pathfinding_settings.js +6 -12
  96. package/test/routerrpc-integration/test_get_payment.js +19 -26
  97. package/test/routerrpc-integration/test_get_route_confidence.js +15 -21
  98. package/test/routerrpc-integration/test_get_route_through_hops.js +29 -32
  99. package/test/routerrpc-integration/test_multipath_payment.js +18 -20
  100. package/test/routerrpc-integration/test_pay_via_payment_details.js +19 -34
  101. package/test/routerrpc-integration/test_pay_via_payment_request.js +17 -27
  102. package/test/routerrpc-integration/test_pay_via_routes.js +37 -37
  103. package/test/routerrpc-integration/test_probe_for_route.js +27 -33
  104. package/test/routerrpc-integration/test_subscribe_to_forward_requests.js +138 -32
  105. package/test/routerrpc-integration/test_subscribe_to_forwards.js +83 -77
  106. package/test/routerrpc-integration/test_subscribe_to_past_payments.js +34 -28
  107. package/test/routerrpc-integration/test_update_pathfinding_settings.js +7 -10
  108. package/test/signerrpc-integration/test_diffie_hellman_compute_secret.js +15 -14
  109. package/test/signerrpc-integration/test_sign_bytes.js +11 -15
  110. package/test/signerrpc-integration/test_sign_transaction.js +6 -7
  111. package/test/signerrpc-integration/test_verify_bytes_signature.js +11 -12
  112. package/test/versionrpc-integration/test_get_wallet_version.js +6 -7
  113. package/test/walletrpc-integration/test_fund_psbt.js +13 -12
  114. package/test/walletrpc-integration/test_get_chain_fee_rate.js +4 -8
  115. package/test/walletrpc-integration/test_get_locked_utxos.js +11 -27
  116. package/test/walletrpc-integration/test_get_public_key.js +5 -13
  117. package/test/walletrpc-integration/test_lock_utxo.js +16 -23
  118. package/test/walletrpc-integration/test_send_to_chain_output_scripts.js +25 -6
  119. package/test/walletrpc-integration/test_sign_psbt.js +28 -19
  120. package/test/walletrpc-integration/test_unlock_utxo.js +16 -27
  121. package/test/walletrpc-integration/test_update_chain_transaction.js +6 -31
@@ -1,23 +1,20 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
- const {createCluster} = require('./../macros');
4
4
  const {getFeeRates} = require('./../../');
5
5
  const {setupChannel} = require('./../macros');
6
6
 
7
7
  const defaultBaseFee = 1;
8
8
  const defaultFeeRate = 1;
9
+ const size = 2;
9
10
 
10
11
  // Getting fee rates should return the fee rates of nodes in the channel graph
11
12
  test(`Get fee rates`, async ({end, equal}) => {
12
- const cluster = await createCluster({is_remote_skipped: true});
13
+ const {kill, nodes} = await spawnLightningCluster({size});
13
14
 
14
- const {lnd} = cluster.control;
15
+ const [{generate, lnd}, to] = nodes;
15
16
 
16
- const channelOpen = await setupChannel({
17
- lnd,
18
- generate: cluster.generate,
19
- to: cluster.target,
20
- });
17
+ const channelOpen = await setupChannel({generate, lnd, to});
21
18
 
22
19
  const {channels} = await getFeeRates({lnd});
23
20
 
@@ -35,7 +32,7 @@ test(`Get fee rates`, async ({end, equal}) => {
35
32
  equal(channel.transaction_id, channelOpen.transaction_id, 'Channel tx id');
36
33
  equal(channel.transaction_vout, channelOpen.transaction_vout, 'Tx vout');
37
34
 
38
- await cluster.kill({});
35
+ await kill({});
39
36
 
40
37
  return end();
41
38
  });
@@ -1,7 +1,8 @@
1
+ const asyncRetry = require('async/retry');
2
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
3
  const {test} = require('@alexbosworth/tap');
2
4
 
3
5
  const {addPeer} = require('./../../');
4
- const {createCluster} = require('./../macros');
5
6
  const {createInvoice} = require('./../../');
6
7
  const {delay} = require('./../macros');
7
8
  const {getForwards} = require('./../../');
@@ -9,45 +10,39 @@ const {pay} = require('./../../');
9
10
  const {setupChannel} = require('./../macros');
10
11
 
11
12
  const limit = 1;
13
+ const size = 3;
12
14
  const tokens = 100;
13
15
 
14
16
  // Getting forwarded payments should return all forwarded payments
15
17
  test('Get forwards', async ({end, equal, strictSame}) => {
16
- const cluster = await createCluster({});
18
+ const {kill, nodes} = await spawnLightningCluster({size});
17
19
 
18
- await setupChannel({
19
- generate: cluster.generate,
20
- lnd: cluster.control.lnd,
21
- to: cluster.target,
22
- });
20
+ const [{generate, lnd}, target, remote] = nodes;
21
+
22
+ await setupChannel({generate, lnd, to: target});
23
23
 
24
24
  await setupChannel({
25
- lnd: cluster.target.lnd,
26
- generate: cluster.generate,
27
- generator: cluster.target,
28
- to: cluster.remote,
25
+ lnd: target.lnd,
26
+ generate: target.generate,
27
+ to: remote,
29
28
  });
30
29
 
31
- await addPeer({
32
- lnd: cluster.control.lnd,
33
- public_key: cluster.remote.public_key,
34
- socket: cluster.remote.socket,
35
- });
30
+ await addPeer({lnd, public_key: remote.id, socket: remote.socket});
36
31
 
37
32
  await delay(2000);
38
33
 
39
- for (let i = 0, lnd = cluster.remote.lnd; i < 3; i++) {
40
- await pay({
41
- lnd: cluster.control.lnd,
42
- request: (await createInvoice({lnd, tokens: tokens + i})).request,
43
- });
34
+ for (let i = 0, l = remote.lnd; i < 3; i++) {
35
+ await asyncRetry({}, async () => {
36
+ await delay(1000);
44
37
 
45
- await delay(1000);
38
+ await pay({
39
+ lnd,
40
+ request: (await createInvoice({lnd: l, tokens: tokens + i})).request,
41
+ });
42
+ });
46
43
  }
47
44
 
48
- const {lnd} = cluster.target;
49
-
50
- const page1 = await getForwards({limit, lnd});
45
+ const page1 = await getForwards({limit, lnd: target.lnd});
51
46
 
52
47
  equal(!!page1.next, true, 'Page 1 leads to page 2');
53
48
 
@@ -62,7 +57,7 @@ test('Get forwards', async ({end, equal, strictSame}) => {
62
57
  equal(!!forward.outgoing_channel, true, 'Forward outgoing channel');
63
58
  }
64
59
 
65
- const page2 = await getForwards({lnd, token: page1.next});
60
+ const page2 = await getForwards({lnd: target.lnd, token: page1.next});
66
61
 
67
62
  equal(!!page2.next, true, 'Page 2 leads to page 3');
68
63
 
@@ -72,7 +67,7 @@ test('Get forwards', async ({end, equal, strictSame}) => {
72
67
  equal(forward.tokens, 101, 'Second forward tokens count');
73
68
  }
74
69
 
75
- const page3 = await getForwards({lnd, token: page2.next});
70
+ const page3 = await getForwards({lnd: target.lnd, token: page2.next});
76
71
 
77
72
  equal(!!page3.next, true, 'Page 3 leads to page 4');
78
73
 
@@ -82,47 +77,51 @@ test('Get forwards', async ({end, equal, strictSame}) => {
82
77
  equal(forward.tokens, 102, 'Third forward tokens count');
83
78
 
84
79
  // Check "before" based paging
85
- const prev0 = await getForwards({limit, lnd, before: forward.created_at});
80
+ const prev0 = await getForwards({
81
+ limit,
82
+ before: forward.created_at,
83
+ lnd: target.lnd,
84
+ });
86
85
 
87
86
  const [firstForward] = prev0.forwards;
88
87
 
89
88
  equal(firstForward.tokens, 100, 'Previous row #1');
90
89
 
91
- const prev1 = await getForwards({lnd, token: prev0.next});
90
+ const prev1 = await getForwards({lnd: target.lnd, token: prev0.next});
92
91
 
93
92
  const [secondForward] = prev1.forwards;
94
93
 
95
94
  equal(secondForward.tokens, 101, 'Previous row #2');
96
95
 
97
- const prev2 = await getForwards({lnd, token: prev1.next});
96
+ const prev2 = await getForwards({lnd: target.lnd, token: prev1.next});
98
97
 
99
98
  equal(prev2.next, undefined, 'Ended paging of previous rows');
100
99
 
101
100
  // Check "after" based paging
102
101
  const after0 = await getForwards({
103
102
  limit,
104
- lnd,
105
103
  before: forward.created_at,
106
104
  after: firstForward.created_at,
105
+ lnd: target.lnd,
107
106
  });
108
107
 
109
108
  strictSame(after0.forwards, prev0.forwards, 'After is inclusive of start');
110
109
 
111
- const after1 = await getForwards({lnd, token: after0.next});
110
+ const after1 = await getForwards({lnd: target.lnd, token: after0.next});
112
111
 
113
112
  strictSame(after1.forwards, prev1.forwards, 'Iterating before, after');
114
113
 
115
- const after2 = await getForwards({lnd, token: after1.next});
114
+ const after2 = await getForwards({lnd: target.lnd, token: after1.next});
116
115
 
117
116
  equal(after2.next, undefined, 'Before is non-inclusive');
118
117
  }
119
118
 
120
- const page4 = await getForwards({lnd, token: page3.next});
119
+ const page4 = await getForwards({lnd: target.lnd, token: page3.next});
121
120
 
122
121
  equal(page4.forwards.length, [].length, 'Page 4 has no results');
123
122
  equal(page4.next, undefined, 'Page 4 leads to nowhere');
124
123
 
125
- await cluster.kill({});
124
+ await kill({});
126
125
 
127
126
  return end();
128
127
  });
@@ -1,6 +1,6 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
- const {createCluster} = require('./../macros');
4
4
  const {createInvoice} = require('./../../');
5
5
  const {getHeight} = require('./../../');
6
6
  const {getInvoice} = require('./../../');
@@ -9,20 +9,16 @@ const {setupChannel} = require('./../macros');
9
9
 
10
10
  const description = 'description';
11
11
  const secret = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
12
+ const size = 2;
12
13
  const tokens = 42;
13
14
 
14
15
  // getInvoice results in invoice details
15
16
  test(`Get an invoice`, async ({end, equal}) => {
16
- const cluster = await createCluster({is_remote_skipped: true})
17
+ const {kill, nodes} = await spawnLightningCluster({size});
17
18
 
18
- const {lnd} = cluster.control;
19
+ const [{generate, lnd}, target] = nodes;
19
20
 
20
- const channel = await setupChannel({
21
- lnd,
22
- generate: cluster.generate,
23
- give: 1e5,
24
- to: cluster.target,
25
- });
21
+ const channel = await setupChannel({generate, lnd, give: 1e5, to: target});
26
22
 
27
23
  const created = await createInvoice({description, lnd, secret, tokens});
28
24
 
@@ -35,7 +31,7 @@ test(`Get an invoice`, async ({end, equal}) => {
35
31
  equal(invoice.secret, secret, 'Invoice secret');
36
32
  equal(invoice.tokens, tokens, 'Invoice tokens');
37
33
 
38
- await pay({lnd: cluster.target.lnd, request: created.request});
34
+ await pay({lnd: target.lnd, request: created.request});
39
35
 
40
36
  const paid = await getInvoice({lnd, id: created.id});
41
37
 
@@ -59,7 +55,7 @@ test(`Get an invoice`, async ({end, equal}) => {
59
55
 
60
56
  equal(paid.is_confirmed, true, 'Invoice has been paid');
61
57
 
62
- await cluster.kill({});
58
+ await kill({});
63
59
 
64
60
  return end();
65
61
  });
@@ -1,55 +1,58 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {createInvoice} = require('./../../');
4
5
  const {getInvoices} = require('./../../');
5
- const {spawnLnd} = require('./../macros');
6
- const {waitForTermination} = require('./../macros');
7
6
 
8
7
  const limit = 1;
9
8
 
10
9
  // createInvoice should result in a created invoice
11
10
  test(`Create an invoice`, async ({end, equal}) => {
12
- const {kill, lnd} = await spawnLnd({});
11
+ const {kill, nodes} = await spawnLightningCluster({});
13
12
 
14
- const invoices = [
15
- await createInvoice({lnd, description: '3'}),
16
- await createInvoice({lnd, description: '2'}),
17
- await createInvoice({lnd, description: '1'}),
18
- ];
13
+ try {
14
+ const [{generate, lnd}] = nodes;
19
15
 
20
- invoices.reverse();
16
+ const invoices = [
17
+ await createInvoice({lnd, description: '3'}),
18
+ await createInvoice({lnd, description: '2'}),
19
+ await createInvoice({lnd, description: '1'}),
20
+ ];
21
21
 
22
- const firstPage = await getInvoices({limit, lnd});
22
+ invoices.reverse();
23
23
 
24
- equal(!!firstPage.next, true, 'First page has a next token');
24
+ const firstPage = await getInvoices({limit, lnd});
25
25
 
26
- const secondPage = await getInvoices({lnd, token: firstPage.next});
26
+ equal(!!firstPage.next, true, 'First page has a next token');
27
27
 
28
- equal(!!secondPage.next, true, 'Second page has a next token');
28
+ const secondPage = await getInvoices({lnd, token: firstPage.next});
29
29
 
30
- const thirdPage = await getInvoices({lnd, token: secondPage.next});
30
+ equal(!!secondPage.next, true, 'Second page has a next token');
31
31
 
32
- equal(!!thirdPage.next, false, 'Third page has no next token');
32
+ const thirdPage = await getInvoices({lnd, token: secondPage.next});
33
33
 
34
- const receivedInvoices = []
35
- .concat(firstPage.invoices)
36
- .concat(secondPage.invoices)
37
- .concat(thirdPage.invoices);
34
+ equal(!!thirdPage.next, false, 'Third page has no next token');
38
35
 
39
- receivedInvoices.forEach((invoice, i) => {
40
- const expected = invoices[i];
36
+ const receivedInvoices = []
37
+ .concat(firstPage.invoices)
38
+ .concat(secondPage.invoices)
39
+ .concat(thirdPage.invoices);
41
40
 
42
- equal(invoice.chain_address, expected.chain_address, 'Chain address');
43
- equal(invoice.confirmed_at, expected.confirmed_at, 'Confirmed at');
44
- equal(invoice.id, expected.id, 'Invoice id');
45
- equal(invoice.request, expected.request, 'Payment request');
46
- equal(invoice.secret, expected.secret, 'Payment secret');
47
- equal(invoice.tokens, expected.tokens, 'Tokens');
48
- });
41
+ receivedInvoices.forEach((invoice, i) => {
42
+ const expected = invoices[i];
49
43
 
50
- kill();
44
+ equal(invoice.chain_address, expected.chain_address, 'Chain address');
45
+ equal(invoice.confirmed_at, expected.confirmed_at, 'Confirmed at');
46
+ equal(invoice.id, expected.id, 'Invoice id');
47
+ equal(invoice.request, expected.request, 'Payment request');
48
+ equal(invoice.secret, expected.secret, 'Payment secret');
49
+ equal(invoice.tokens, expected.tokens, 'Tokens');
50
+ });
51
+ } catch (err) {
52
+ equal(err, null, 'No error is expected');
53
+ }
51
54
 
52
- await waitForTermination({lnd});
55
+ await kill({});
53
56
 
54
57
  return end();
55
58
  });
@@ -1,14 +1,13 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {getMethods} = require('./../../');
4
- const {spawnLnd} = require('./../macros');
5
- const {waitForTermination} = require('./../macros');
6
5
 
7
6
  // Getting LND methods should result in LND methods returned
8
7
  test(`Get LND methods`, async ({end, equal, type}) => {
9
- const node = await spawnLnd({});
8
+ const {kill, nodes} = await spawnLightningCluster({});
10
9
 
11
- const {kill, lnd} = node;
10
+ const [{lnd}] = nodes;
12
11
 
13
12
  try {
14
13
  const {methods} = await getMethods({lnd});
@@ -28,9 +27,7 @@ test(`Get LND methods`, async ({end, equal, type}) => {
28
27
  equal(message, 'ListPermissionsMethodNotSupported', 'Not supported msg');
29
28
  }
30
29
 
31
- kill();
32
-
33
- await waitForTermination({lnd});
30
+ await kill({});
34
31
 
35
32
  return end();
36
33
  });
@@ -1,43 +1,40 @@
1
1
  const asyncRetry = require('async/retry');
2
+ const {spawnLightningCluster} = require('ln-docker-daemons');
2
3
  const {test} = require('@alexbosworth/tap');
3
4
 
4
5
  const {addPeer} = require('./../../');
5
- const {createCluster} = require('./../macros');
6
6
  const {getNetworkCentrality} = require('./../../');
7
+ const {getWalletInfo} = require('./../../');
7
8
  const {setupChannel} = require('./../macros');
8
9
 
9
- const interval = 1e4;
10
- const times = 100;
10
+ const interval = 100;
11
+ const size = 3;
12
+ const times = 300;
11
13
 
12
14
  // Getting the network centrality should return the centrality scores
13
15
  test(`Get network centrality`, async ({end, equal, strictSame}) => {
14
- const cluster = await createCluster({});
16
+ const {kill, nodes} = await spawnLightningCluster({size});
15
17
 
16
- await getNetworkCentrality({lnd: cluster.control.lnd});
17
-
18
- const {control} = cluster;
19
- const {remote} = cluster;
20
- const {target} = cluster;
18
+ const [control, target, remote] = nodes;
21
19
 
22
20
  const {lnd} = control;
23
21
 
24
- await setupChannel({lnd, generate: cluster.generate, to: target});
22
+ await setupChannel({lnd, generate: control.generate, to: target});
25
23
 
26
24
  await setupChannel({
27
- generate: cluster.generate,
28
- generator: target,
25
+ generate: target.generate,
29
26
  lnd: target.lnd,
30
27
  to: remote,
31
28
  });
32
29
 
33
30
  await asyncRetry({interval, times}, async () => {
34
- await addPeer({lnd, public_key: remote.public_key, socket: remote.socket});
31
+ await addPeer({lnd, public_key: remote.id, socket: remote.socket});
35
32
 
36
33
  const {nodes} = await getNetworkCentrality({lnd});
37
34
 
38
- const controlScore = nodes.find(n => n.public_key === control.public_key);
39
- const remoteScore = nodes.find(n => n.public_key === remote.public_key);
40
- const targetScore = nodes.find(n => n.public_key === target.public_key);
35
+ const controlScore = nodes.find(n => n.public_key === control.id);
36
+ const remoteScore = nodes.find(n => n.public_key === remote.id);
37
+ const targetScore = nodes.find(n => n.public_key === target.id);
41
38
 
42
39
  if (!targetScore.betweenness || !targetScore.betweenness_normalized) {
43
40
  throw new Error('UnexpectedValueForTargetScoreBetweenness');
@@ -57,7 +54,7 @@ test(`Get network centrality`, async ({end, equal, strictSame}) => {
57
54
  return;
58
55
  });
59
56
 
60
- await cluster.kill({});
57
+ await kill({});
61
58
 
62
59
  return end();
63
60
  });
@@ -1,41 +1,38 @@
1
1
  const asyncRetry = require('async/retry');
2
+ const {spawnLightningCluster} = require('ln-docker-daemons');
2
3
  const {test} = require('@alexbosworth/tap');
3
4
 
4
- const {createCluster} = require('./../macros');
5
5
  const {getNetworkGraph} = require('./../../');
6
6
  const {getNode} = require('./../../');
7
7
  const {setupChannel} = require('./../macros');
8
8
 
9
9
  const {ceil} = Math;
10
10
  const interval = 250;
11
+ const size = 3;
11
12
  const times = 50;
12
13
 
13
14
  // Getting the network graph should return the public nodes and connections
14
15
  test(`Get network graph`, async ({end, equal, strictSame}) => {
15
- const cluster = await createCluster({});
16
+ const {kill, nodes} = await spawnLightningCluster({size});
16
17
 
17
- const {control} = cluster;
18
+ const [control, target] = nodes;
18
19
 
19
- const {lnd} = control;
20
+ const {generate, lnd} = control;
20
21
 
21
- const expectedChannel = await setupChannel({
22
- lnd,
23
- generate: cluster.generate,
24
- to: cluster.target,
25
- });
22
+ const expectedChannel = await setupChannel({generate, lnd, to: target});
26
23
 
27
24
  // Wait until the node shows up in the graph
28
25
  const graph = await asyncRetry({interval, times}, async () => {
29
26
  const networkGraph = await getNetworkGraph({lnd});
30
27
 
31
- if (!networkGraph.nodes.find(n => n.public_key === control.public_key)) {
28
+ if (!networkGraph.nodes.find(n => n.public_key === control.id)) {
32
29
  throw new Error('ExpectedToFindNodeInGraph');
33
30
  }
34
31
 
35
32
  return networkGraph;
36
33
  });
37
34
 
38
- const node = graph.nodes.find(n => n.public_key === control.public_key);
35
+ const node = graph.nodes.find(n => n.public_key === control.id);
39
36
  const [channel] = graph.channels;
40
37
 
41
38
  const nodeDetails = await getNode({lnd, public_key: node.public_key});
@@ -46,10 +43,10 @@ test(`Get network graph`, async ({end, equal, strictSame}) => {
46
43
  strictSame(chan, channel, 'Graph channel matches node details channel');
47
44
  }
48
45
 
49
- equal(node.alias, control.public_key.slice(0, 20), 'Node alias is own');
46
+ equal(node.alias, control.id.slice(0, 20), 'Node alias is own');
50
47
  equal(node.color, '#3399ff', 'Node color is default');
51
- equal(node.public_key, control.public_key, 'Node pubkey is own');
52
- strictSame(node.sockets, [`127.0.0.1:${control.listen_port}`], 'Socket');
48
+ equal(node.public_key, control.id, 'Node pubkey is own');
49
+ equal(node.sockets.length, 1, 'Socket');
53
50
  equal(new Date() - new Date(node.updated_at) < 1e5, true, 'Recent update');
54
51
 
55
52
  channel.policies.forEach(policy => {
@@ -71,7 +68,7 @@ test(`Get network graph`, async ({end, equal, strictSame}) => {
71
68
  equal(channel.transaction_vout, expectedChannel.transaction_vout, 'Tx Vout');
72
69
  equal(new Date() - new Date(channel.updated_at) < 1e5, true, 'Updated at');
73
70
 
74
- await cluster.kill({});
71
+ await kill({});
75
72
 
76
73
  return end();
77
74
  });
@@ -1,12 +1,13 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {getNetworkInfo} = require('./../../');
4
- const {spawnLnd} = require('./../macros');
5
- const {waitForTermination} = require('./../macros');
6
5
 
7
6
  // Getting the network info should return basic network statistics
8
7
  test(`Get network info`, async ({end, equal}) => {
9
- const {kill, lnd} = await spawnLnd({});
8
+ const {kill, nodes} = await spawnLightningCluster({});
9
+
10
+ const [{lnd}] = nodes;
10
11
 
11
12
  const result = await getNetworkInfo({lnd});
12
13
 
@@ -18,9 +19,7 @@ test(`Get network info`, async ({end, equal}) => {
18
19
  equal(result.not_recently_updated_policy_count, 0, 'Not updated count');
19
20
  equal(result.total_capacity, 0, 'Total capacity');
20
21
 
21
- kill();
22
-
23
- await waitForTermination({lnd});
22
+ await kill({});
24
23
 
25
24
  return end();
26
25
  });
@@ -1,7 +1,7 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {addPeer} = require('./../../');
4
- const {createCluster} = require('./../macros');
5
5
  const {delay} = require('./../macros');
6
6
  const {getIdentity} = require('./../../');
7
7
  const {getNode} = require('./../../');
@@ -16,27 +16,20 @@ const defaultFee = 1e3;
16
16
  const defaultAliasLength = '00000000000000000000'.length;
17
17
  const feeRate = 21;
18
18
  const mtokPerTok = BigInt(1e3);
19
+ const size = 3;
19
20
 
20
21
  // Getting a node should return the public graph node info
21
22
  test(`Get node`, async ({end, equal, strictSame}) => {
22
- const cluster = await createCluster({});
23
+ const {kill, nodes} = await spawnLightningCluster({size});
23
24
 
24
- const {control} = cluster;
25
+ const [{generate, id, lnd}, target, remote] = nodes;
25
26
 
26
- const {generate} = cluster;
27
- const {lnd} = control;
28
-
29
- const controlToTarget = await setupChannel({
30
- lnd,
31
- generate: cluster.generate,
32
- to: cluster.target,
33
- });
27
+ const controlToTarget = await setupChannel({generate, lnd, to: target});
34
28
 
35
29
  const targetToRemote = await setupChannel({
36
- generate: cluster.generate,
37
- generator: cluster.target,
38
- lnd: cluster.target.lnd,
39
- to: cluster.remote,
30
+ generate: target.generate,
31
+ lnd: target.lnd,
32
+ to: remote,
40
33
  });
41
34
 
42
35
  await updateRoutingFees({
@@ -48,26 +41,17 @@ test(`Get node`, async ({end, equal, strictSame}) => {
48
41
  transaction_vout: controlToTarget.transaction_vout,
49
42
  });
50
43
 
51
- await addPeer({
52
- lnd,
53
- public_key: cluster.remote.public_key,
54
- socket: cluster.remote.socket,
55
- });
44
+ await addPeer({lnd, public_key: remote.id, socket: remote.socket});
56
45
 
57
46
  await delay(3000);
58
47
 
59
- const controlListenIp = cluster.control.listen_ip;
60
- const controlListenPort = cluster.control.listen_port;
61
-
62
- const controlPublicKey = (await getIdentity({lnd})).public_key;
63
-
64
- const node = await getNode({lnd, public_key: controlPublicKey});
48
+ const node = await getNode({lnd, public_key: id});
65
49
 
66
50
  {
67
51
  const {channels} = await getNode({
68
52
  lnd,
69
53
  is_omitting_channels: true,
70
- public_key: controlPublicKey,
54
+ public_key: id,
71
55
  });
72
56
 
73
57
  equal(channels.length, [].length, 'Channels are omitted')
@@ -76,7 +60,7 @@ test(`Get node`, async ({end, equal, strictSame}) => {
76
60
  if (!!node.channels.length) {
77
61
  const [{policies}] = node.channels;
78
62
 
79
- const policy = policies.find(n => n.public_key === control.public_key);
63
+ const policy = policies.find(n => n.public_key === id);
80
64
 
81
65
  equal(BigInt(policy.base_fee_mtokens), BigInt(baseFee)*mtokPerTok, 'Base');
82
66
  equal(policy.cltv_delta, cltvDelta, 'Got expected cltv delta');
@@ -88,14 +72,14 @@ test(`Get node`, async ({end, equal, strictSame}) => {
88
72
 
89
73
  const [socket] = node.sockets;
90
74
 
91
- equal(node.alias, controlPublicKey.slice(0, defaultAliasLength), 'Alias');
75
+ equal(node.alias, id.slice(0, defaultAliasLength), 'Alias');
92
76
  equal(node.color, '#3399ff', 'Color');
93
77
  equal(node.sockets.length, 1, 'Socket');
94
- equal(socket.socket, `127.0.0.1:${controlListenPort}`, 'Ip, port');
78
+ equal(!!socket.socket, true, 'Ip, port');
95
79
  equal(socket.type, 'tcp', 'Socket type');
96
80
  equal(node.updated_at.length, 24, 'Update date');
97
81
 
98
- await cluster.kill({});
82
+ await kill({});
99
83
 
100
84
  return end();
101
85
  });