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,35 +1,35 @@
1
1
  const asyncTimesSeries = require('async/timesSeries');
2
+ const {spawnLightningCluster} = require('ln-docker-daemons');
2
3
  const {test} = require('@alexbosworth/tap');
3
4
 
4
- const {createCluster} = require('./../macros');
5
5
  const {createInvoice} = require('./../../');
6
- const {delay} = require('./../macros');
7
6
  const {getPayments} = require('./../../');
8
7
  const {pay} = require('./../../');
9
8
  const {setupChannel} = require('./../macros');
10
9
 
11
10
  const start = new Date().toISOString();
11
+ const size = 2;
12
12
  const tokens = 100;
13
13
 
14
14
  // Getting payments should return the list of payments
15
15
  test('Get payments', async ({end, equal}) => {
16
- const cluster = await createCluster({is_remote_skipped: true});
16
+ const {kill, nodes} = await spawnLightningCluster({size});
17
17
 
18
- const {lnd} = cluster.control;
18
+ const [{generate, lnd}, target] = nodes;
19
19
 
20
- await setupChannel({lnd, generate: cluster.generate, to: cluster.target});
20
+ await setupChannel({generate, lnd, to: target});
21
21
 
22
- const invoice = await createInvoice({tokens, lnd: cluster.target.lnd});
22
+ const invoice = await createInvoice({tokens, lnd: target.lnd});
23
23
 
24
24
  const paid = await pay({lnd, request: invoice.request});
25
25
 
26
26
  const [payment] = (await getPayments({lnd})).payments;
27
27
 
28
- equal(payment.destination, cluster.target_node_public_key, 'Destination');
28
+ equal(payment.destination, target.id, 'Destination');
29
29
  equal(payment.confirmed_at > start, true, 'Got confirmed date');
30
30
  equal(payment.created_at.length, 24, 'Created at time');
31
31
  equal(payment.fee, 0, 'Fee paid');
32
- equal(payment.hops.length, 0, 'Hops');
32
+ equal(payment.hops.length, [].length, 'Hops');
33
33
  equal(payment.id, invoice.id, 'Id');
34
34
  equal(payment.is_confirmed, true, 'Confirmed');
35
35
  equal(payment.is_outgoing, true, 'Outgoing');
@@ -42,7 +42,7 @@ test('Get payments', async ({end, equal}) => {
42
42
  }
43
43
 
44
44
  await asyncTimesSeries(4, async () => {
45
- const {request} = await createInvoice({tokens, lnd: cluster.target.lnd});
45
+ const {request} = await createInvoice({tokens, lnd: target.lnd});
46
46
 
47
47
  const paid = await pay({lnd, request});
48
48
  });
@@ -61,7 +61,7 @@ test('Get payments', async ({end, equal}) => {
61
61
 
62
62
  equal(!!page3.next, false, 'There is no page 4');
63
63
 
64
- await cluster.kill({});
64
+ await kill({});
65
65
 
66
66
  return end();
67
67
  });
@@ -1,26 +1,23 @@
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 {getPeers} = require('./../../');
7
7
 
8
- const interval = retryCount => 50 * Math.pow(2, retryCount);
9
- const times = 10;
8
+ const interval = 10
9
+ const size = 2;
10
+ const times = 1000;
10
11
 
11
12
  // Getting peers should return the list of peers
12
13
  test('Get peers', async ({end, equal}) => {
13
- const cluster = await createCluster({});
14
+ const {kill, nodes} = await spawnLightningCluster({size});
14
15
 
15
- const {lnd} = cluster.control;
16
-
17
- await addPeer({
18
- lnd,
19
- public_key: cluster.remote.public_key,
20
- socket: cluster.remote.socket,
21
- });
16
+ const [{lnd}, target] = nodes;
22
17
 
23
18
  await asyncRetry({interval, times}, async () => {
19
+ await addPeer({lnd, public_key: target.id, socket: target.socket});
20
+
24
21
  const [peer] = (await getPeers({lnd})).peers;
25
22
 
26
23
  if (!peer || !peer.is_sync_peer) {
@@ -32,7 +29,7 @@ test('Get peers', async ({end, equal}) => {
32
29
  equal(peer.is_inbound, false, 'Is inbound peer');
33
30
  equal(peer.is_sync_peer, true, 'Is sync peer');
34
31
  equal(peer.ping_time, 0, 'Ping time');
35
- equal(!!peer.public_key, true, 'Public key');
32
+ equal(peer.public_key, target.id, 'Public key');
36
33
  equal(!!peer.socket, true, 'Socket');
37
34
  equal(peer.tokens_received, 0, 'Tokens received');
38
35
  equal(peer.tokens_sent, 0, 'Tokens sent');
@@ -40,7 +37,7 @@ test('Get peers', async ({end, equal}) => {
40
37
  return;
41
38
  });
42
39
 
43
- await cluster.kill({});
40
+ await kill({});
44
41
 
45
42
  return end();
46
43
  });
@@ -1,37 +1,32 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {closeChannel} = require('./../../');
4
- const {createCluster} = require('./../macros');
5
5
  const {getWalletInfo} = require('./../../');
6
6
  const {setupChannel} = require('./../macros');
7
7
  const {waitForPendingChannel} = require('./../macros');
8
8
 
9
+ const anchorsFeatureBit = 23;
9
10
  const defaultFee = 1e3;
10
- const giftTokens = 1e4;
11
+ const give = 1e4;
12
+ const size = 2;
11
13
 
12
14
  // Getting pending channels should show pending channels
13
15
  test(`Get pending channels`, async ({end, equal}) => {
14
- const cluster = await createCluster({is_remote_skipped: true});
16
+ const {kill, nodes} = await spawnLightningCluster({size});
15
17
 
16
- const {lnd} = cluster.control;
18
+ const [{generate, lnd}, target] = nodes;
17
19
 
18
20
  const {features} = await getWalletInfo({lnd});
19
21
 
20
- const isAnchors = !!features.find(n => n.bit === 23);
22
+ const isAnchors = !!features.find(n => n.bit === anchorsFeatureBit);
21
23
 
22
24
  // Target starts a channel with control
23
- const coopChan = await setupChannel({
24
- lnd,
25
- generate: cluster.generate,
26
- give: giftTokens,
27
- to: cluster.target,
28
- });
25
+ const coopChan = await setupChannel({generate, give, lnd, to: target});
29
26
 
30
27
  // Target closes the channel
31
28
  const niceClose = await closeChannel({
32
- lnd: cluster.target.lnd,
33
- public_key: cluster.target.public_key,
34
- socket: cluster.target.socket,
29
+ lnd: target.lnd,
35
30
  tokens_per_vbyte: defaultFee,
36
31
  transaction_id: coopChan.transaction_id,
37
32
  transaction_vout: coopChan.transaction_vout,
@@ -39,7 +34,7 @@ test(`Get pending channels`, async ({end, equal}) => {
39
34
 
40
35
  // Control views their pending channels
41
36
  const {channel} = await waitForPendingChannel({
42
- lnd: cluster.control.lnd,
37
+ lnd,
43
38
  id: coopChan.transaction_id,
44
39
  });
45
40
 
@@ -61,7 +56,7 @@ test(`Get pending channels`, async ({end, equal}) => {
61
56
  equal(channel.is_closing, true, 'Closing');
62
57
  equal(channel.is_opening, false, 'Not Opening');
63
58
  equal(channel.local_reserve, 10000, 'Local reserve');
64
- equal(channel.partner_public_key, cluster.target.public_key, 'target pubk');
59
+ equal(channel.partner_public_key, target.id, 'Target public key');
65
60
  equal(channel.pending_payments, undefined, 'No pending payments');
66
61
  equal(channel.received, 0, 'Never received');
67
62
  equal(channel.recovered_tokens, undefined, 'Nothing to recover in sweep');
@@ -74,10 +69,10 @@ test(`Get pending channels`, async ({end, equal}) => {
74
69
  equal(channel.transaction_weight, null, 'No funding tx weight data');
75
70
 
76
71
  if (!!channel.remote_balance) {
77
- equal(channel.remote_balance, giftTokens, 'Opposing channel balance');
72
+ equal(channel.remote_balance, give, 'Opposing channel balance');
78
73
  }
79
74
 
80
- await cluster.kill({});
75
+ await kill({});
81
76
 
82
77
  return end();
83
78
  });
@@ -1,9 +1,10 @@
1
1
  const asyncRetry = require('async/retry');
2
+ const {spawnLightningCluster} = require('ln-docker-daemons');
2
3
  const {test} = require('@alexbosworth/tap');
3
4
 
5
+ const {addPeer} = require('./../../');
4
6
  const {closeChannel} = require('./../../');
5
- const {createCluster} = require('./../macros');
6
- const {delay} = require('./../macros');
7
+ const {getChainBalance} = require('./../../');
7
8
  const {getChannels} = require('./../../');
8
9
  const {getHeight} = require('./../../');
9
10
  const {getPeers} = require('./../../');
@@ -14,35 +15,42 @@ const {waitChannel} = require('./../macros');
14
15
  const {waitPendingChannel} = require('./../macros');
15
16
  const {waitForUtxo} = require('./../macros');
16
17
 
18
+ const anchorFeatureBit = 23;
17
19
  const channelCapacityTokens = 1e6;
18
20
  const confirmationCount = 20;
21
+ const count = 100;
19
22
  const defaultFee = 1e3;
20
23
  const defaultVout = 0;
21
24
  const giftTokens = 1e4;
22
- const interval = retryCount => 10 * Math.pow(2, retryCount);
25
+ const interval = 10;
26
+ const size = 2;
23
27
  const spendableRatio = 0.99;
24
- const times = 20;
28
+ const times = 2000;
25
29
 
26
30
  // Getting pending channels should show pending channels
27
31
  test(`Get pending channels`, async ({end, equal}) => {
28
- const cluster = await createCluster({is_remote_skipped: true});
32
+ const {kill, nodes} = await spawnLightningCluster({size});
29
33
 
30
- const {lnd} = cluster.control;
34
+ const [{generate, lnd}, target] = nodes;
31
35
 
32
36
  const {features} = await getWalletInfo({lnd});
33
37
 
34
- const isAnchors = !!features.find(n => n.bit === 23);
35
- const startHeight = (await getHeight({lnd})).current_block_height
38
+ const isAnchors = !!features.find(n => n.bit === anchorFeatureBit);
39
+ const startHeight = (await getHeight({lnd})).current_block_height;
40
+
41
+ await generate({count});
36
42
 
37
43
  const channelOpen = await asyncRetry({interval, times}, async () => {
44
+ await addPeer({lnd, public_key: target.id, socket: target.socket});
45
+
38
46
  return await openChannel({
39
47
  lnd,
40
48
  chain_fee_tokens_per_vbyte: defaultFee,
41
49
  give_tokens: giftTokens,
42
50
  local_tokens: channelCapacityTokens,
43
51
  partner_csv_delay: 10,
44
- partner_public_key: cluster.target.public_key,
45
- socket: cluster.target.socket,
52
+ partner_public_key: target.id,
53
+ socket: target.socket,
46
54
  });
47
55
  });
48
56
 
@@ -65,7 +73,7 @@ test(`Get pending channels`, async ({end, equal}) => {
65
73
  equal(pendingOpen.is_closing, false, 'Not closing yet');
66
74
  equal(pendingOpen.is_opening, true, 'Channel is opening');
67
75
  equal(pendingOpen.local_reserve, 10000, 'Local reserve amount');
68
- equal(pendingOpen.partner_public_key, cluster.target_node_public_key, 'Key');
76
+ equal(pendingOpen.partner_public_key, target.id, 'Key');
69
77
  equal(pendingOpen.pending_balance, undefined, 'No pending chain balance');
70
78
  equal(pendingOpen.pending_payments, undefined, 'No pending payments');
71
79
  equal(pendingOpen.received, 0, 'Nothing received');
@@ -75,9 +83,9 @@ test(`Get pending channels`, async ({end, equal}) => {
75
83
  equal(pendingOpen.sent, 0, 'Nothing sent');
76
84
  equal(pendingOpen.timelock_expiration, undefined, 'Not timelocked');
77
85
  equal(pendingOpen.transaction_id, channelOpen.transaction_id, 'Open tx id');
78
- equal(pendingOpen.transaction_vout, channelOpen.transaction_vout, 'Tx vout');
86
+ equal(pendingOpen.transaction_vout, channelOpen.transaction_vout, 'Tx out');
79
87
 
80
- await cluster.generate({count: confirmationCount});
88
+ await generate({count: confirmationCount});
81
89
 
82
90
  await getChannels({lnd, id: channelOpen.transaction_id});
83
91
 
@@ -108,7 +116,7 @@ test(`Get pending channels`, async ({end, equal}) => {
108
116
  equal(waitClose.is_closing, true, 'Channel is closing');
109
117
  equal(waitClose.is_opening, false, 'Not opening channel');
110
118
  equal(waitClose.local_reserve, 10000, 'Local reserve of closing channel');
111
- equal(waitClose.partner_public_key, cluster.target_node_public_key, 'Pkey');
119
+ equal(waitClose.partner_public_key, target.id, 'Pkey');
112
120
  equal(waitClose.pending_payments, undefined, 'No pending payments data');
113
121
  equal(waitClose.received, 0, 'Nothing received');
114
122
  equal(waitClose.recovered_tokens, undefined, 'Funds not recovered yet');
@@ -116,7 +124,7 @@ test(`Get pending channels`, async ({end, equal}) => {
116
124
  equal(waitClose.sent, 0, 'No sent tokens');
117
125
  equal(waitClose.timelock_expiration, undefined, 'No timelock data');
118
126
  equal(waitClose.transaction_fee, null, 'No tx fee data');
119
- equal(waitClose.transaction_id, channelOpen.transaction_id, 'Funding tx id');
127
+ equal(waitClose.transaction_id, channelOpen.transaction_id, 'Funding txid');
120
128
  equal(waitClose.transaction_vout, channelOpen.transaction_vout, 'Tx vout');
121
129
  equal(waitClose.transaction_weight, null, 'No funding tx weight data');
122
130
 
@@ -127,12 +135,12 @@ test(`Get pending channels`, async ({end, equal}) => {
127
135
  equal(waitClose.sent, 0, 'Channel never sent funds');
128
136
  equal(waitClose.timelock_expiration, undefined, 'Not timelocked yet');
129
137
  equal(waitClose.transaction_id, channelOpen.transaction_id, 'Chan txid');
130
- equal(waitClose.transaction_vout, channelOpen.transaction_vout, 'Chan vout');
138
+ equal(waitClose.transaction_vout, channelOpen.transaction_vout, 'Chan out');
131
139
 
132
140
  // Wait for generation to be over
133
141
  await asyncRetry({interval, times}, async () => {
134
142
  // Generate to confirm the tx
135
- await cluster.generate({});
143
+ await generate({});
136
144
 
137
145
  const [forceClose] = (await getPendingChannels({lnd})).pending_channels;
138
146
 
@@ -163,17 +171,17 @@ test(`Get pending channels`, async ({end, equal}) => {
163
171
  equal(forceClose.is_closing, true, 'Channel is force closing');
164
172
  equal(forceClose.is_timelocked, true, 'Force close funds are timelocked')
165
173
  equal(forceClose.is_opening, false, 'Channel is not opening');
166
- equal(forceClose.partner_public_key, cluster.target_node_public_key, 'pk');
174
+ equal(forceClose.partner_public_key, target.id, 'pk');
167
175
  equal(forceClose.received, 0, 'No receive amount');
168
176
  equal(forceClose.recovered_tokens, undefined, 'No recovered amount');
169
177
  equal(forceClose.remote_balance, 0, 'No remote balance');
170
178
  equal(forceClose.sent, 0, 'No sent amount');
171
179
  equal(!!forceClose.timelock_blocks, true, 'Timelock blocks set');
172
- equal(forceClose.timelock_expiration, startHeight + 165, 'Funds timelocked');
180
+ equal(forceClose.timelock_expiration, startHeight + 265, 'Funds timelock');
173
181
  equal(forceClose.transaction_id, channelOpen.transaction_id, 'Chan-Txid');
174
- equal(forceClose.transaction_vout, channelOpen.transaction_vout, 'ChanVout');
182
+ equal(forceClose.transaction_vout, channelOpen.transaction_vout, 'ChanOut');
175
183
 
176
- await cluster.kill({});
184
+ await kill({});
177
185
 
178
186
  return end();
179
187
  });
@@ -1,10 +1,13 @@
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('./../../');
6
+ const {cancelHodlInvoice} = require('./../../');
5
7
  const {createCluster} = require('./../macros');
6
8
  const {createInvoice} = require('./../../');
7
9
  const {decodePaymentRequest} = require('./../../');
10
+ const {delay} = require('./../macros');
8
11
  const {getInvoice} = require('./../../');
9
12
  const {getRouteToDestination} = require('./../../');
10
13
  const {parsePaymentRequest} = require('./../../');
@@ -12,48 +15,52 @@ const {payViaRoutes} = require('./../../');
12
15
  const {setupChannel} = require('./../macros');
13
16
 
14
17
  const all = promise => Promise.all(promise);
15
- const interval = retryCount => 50 * Math.pow(2, retryCount);
18
+ const interval = 10;
16
19
  const {isArray} = Array;
17
20
  const message = {type: '85805', value: '01'};
18
- const times = 15;
19
- const tokens = 100;
21
+ const size = 3;
22
+ const times = 3000;
23
+ const tokens = 1000;
20
24
 
21
25
  // Getting a route to a destination should return a route to the destination
22
26
  test(`Get a route to a destination`, async ({end, equal, strictSame}) => {
23
- const cluster = await createCluster({});
27
+ const {kill, nodes} = await spawnLightningCluster({size});
24
28
 
25
- {
26
- const {lnd} = cluster.target;
29
+ const [control, target, remote] = nodes;
27
30
 
28
- const {request} = await createInvoice({lnd});
29
-
30
- // Exit test early if features are not supported
31
- if (!(await decodePaymentRequest({lnd, request})).features.length) {
32
- await cluster.kill({});
33
-
34
- return end();
35
- }
36
- }
31
+ await control.generate({count: 500});
37
32
 
38
33
  await setupChannel({
39
- generate: cluster.generate,
40
- lnd: cluster.control.lnd,
41
- to: cluster.target,
34
+ generate: control.generate,
35
+ lnd: control.lnd,
36
+ to: target,
42
37
  });
43
38
 
44
39
  await setupChannel({
45
- generate: cluster.generate,
46
- generator: cluster.target,
40
+ generate: target.generate,
47
41
  give: 1e5,
48
42
  hidden: true,
49
- lnd: cluster.target.lnd,
50
- to: cluster.remote,
43
+ lnd: target.lnd,
44
+ to: remote,
51
45
  });
52
46
 
53
- const invoice = await createInvoice({
54
- tokens,
55
- is_including_private_channels: true,
56
- lnd: cluster.remote.lnd,
47
+ const invoice = await asyncRetry({interval, times}, async () => {
48
+ const invoice = await createInvoice({
49
+ tokens,
50
+ is_including_private_channels: true,
51
+ lnd: remote.lnd,
52
+ });
53
+
54
+ const {routes} = parsePaymentRequest({request: invoice.request});
55
+
56
+ // Wait for private routes to get picked up
57
+ if (!routes) {
58
+ await cancelHodlInvoice({id: invoice.id, lnd: remote.lnd});
59
+
60
+ throw new Error('ExpectedRouteForInvoice');
61
+ }
62
+
63
+ return invoice;
57
64
  });
58
65
 
59
66
  const parsed = parsePaymentRequest({request: invoice.request});
@@ -62,7 +69,7 @@ test(`Get a route to a destination`, async ({end, equal, strictSame}) => {
62
69
  const {route} = await getRouteToDestination({
63
70
  destination: parsed.destination,
64
71
  features: parsed.features,
65
- lnd: cluster.control.lnd,
72
+ lnd: control.lnd,
66
73
  payment: parsed.payment,
67
74
  routes: parsed.routes,
68
75
  mtokens: parsed.mtokens,
@@ -71,37 +78,37 @@ test(`Get a route to a destination`, async ({end, equal, strictSame}) => {
71
78
 
72
79
  const paid = await payViaRoutes({
73
80
  id: parsed.id,
74
- lnd: cluster.control.lnd,
81
+ lnd: control.lnd,
75
82
  routes: [route],
76
83
  });
77
84
 
78
85
  equal(invoice.secret, paid.secret, 'Paid multi-hop private route');
79
86
  });
80
87
 
81
- const inv = await createInvoice({tokens, lnd: cluster.target.lnd});
88
+ const inv = await createInvoice({tokens, lnd: target.lnd});
82
89
 
83
90
  const invDetails = await decodePaymentRequest({
84
- lnd: cluster.control.lnd,
91
+ lnd: control.lnd,
85
92
  request: inv.request,
86
93
  });
87
94
 
88
95
  const controlToTarget = await getRouteToDestination({
89
- destination: cluster.target.public_key,
96
+ destination: target.id,
90
97
  features: invDetails.features,
91
- lnd: cluster.control.lnd,
98
+ lnd: control.lnd,
92
99
  messages: [message],
93
100
  payment: invDetails.payment,
94
- tokens: invDetails.tokens / [cluster.control, cluster.remote].length,
101
+ tokens: invDetails.tokens / [control, remote].length,
95
102
  total_mtokens: invDetails.mtokens,
96
103
  });
97
104
 
98
105
  const remoteToTarget = await getRouteToDestination({
99
- destination: cluster.target.public_key,
106
+ destination: target.id,
100
107
  features: invDetails.features,
101
- lnd: cluster.remote.lnd,
108
+ lnd: remote.lnd,
102
109
  messages: [message],
103
110
  payment: invDetails.payment,
104
- tokens: invDetails.tokens / [cluster.control, cluster.remote].length,
111
+ tokens: invDetails.tokens / [control, remote].length,
105
112
  total_mtokens: invDetails.mtokens,
106
113
  });
107
114
 
@@ -109,12 +116,12 @@ test(`Get a route to a destination`, async ({end, equal, strictSame}) => {
109
116
  const [controlPay, remotePay] = await all([
110
117
  payViaRoutes({
111
118
  id: invDetails.id,
112
- lnd: cluster.control.lnd,
119
+ lnd: control.lnd,
113
120
  routes: [controlToTarget.route],
114
121
  }),
115
122
  payViaRoutes({
116
123
  id: invDetails.id,
117
- lnd: cluster.remote.lnd,
124
+ lnd: remote.lnd,
118
125
  routes: [remoteToTarget.route],
119
126
  }),
120
127
  ]);
@@ -124,7 +131,7 @@ test(`Get a route to a destination`, async ({end, equal, strictSame}) => {
124
131
 
125
132
  const {payments} = await getInvoice({
126
133
  id: invDetails.id,
127
- lnd: cluster.target.lnd,
134
+ lnd: target.lnd,
128
135
  });
129
136
 
130
137
  const [payment1, payment2] = payments;
@@ -138,7 +145,7 @@ test(`Get a route to a destination`, async ({end, equal, strictSame}) => {
138
145
  equal(err, null, 'Unexpected error paying invoice');
139
146
  }
140
147
 
141
- await cluster.kill({});
148
+ await kill({});
142
149
 
143
150
  return end();
144
151
  });
@@ -1,72 +1,47 @@
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 {chainSendTransaction} = require('./../macros');
5
5
  const {createChainAddress} = require('./../../');
6
- const {generateBlocks} = require('./../macros');
6
+ const {getChainBalance} = require('./../../');
7
7
  const {getUtxos} = require('./../../');
8
- const {mineTransaction} = require('./../macros');
9
- const {spawnLnd} = require('./../macros');
10
- const {waitForTermination} = require('./../macros');
11
- const {waitForUtxo} = require('./../macros');
12
8
 
13
- const count = 100;
14
- const defaultFee = 1e3;
15
- const defaultVout = 0;
16
- const format = 'np2wpkh';
9
+ const format = 'p2wpkh';
10
+ const times = 300;
17
11
  const tokens = 1e8;
18
12
 
19
13
  // Getting utxos should list out the utxos
20
14
  test(`Get utxos`, async ({end, equal, fail, strictSame}) => {
21
- const node = await asyncRetry({}, async () => await spawnLnd({}));
15
+ const {kill, nodes} = await spawnLightningCluster({});
22
16
 
23
- const cert = node.chain_rpc_cert_file;
24
- const host = node.listen_ip;
25
- const {kill} = node;
26
- const pass = node.chain_rpc_pass;
27
- const port = node.chain_rpc_port;
28
- const {lnd} = node;
29
- const user = node.chain_rpc_user;
30
-
31
- const {address} = await createChainAddress({format, lnd});
17
+ const [{generate, lnd}] = nodes;
32
18
 
33
19
  // Generate some funds for LND
34
- const {blocks} = await node.generate({count});
35
-
36
- const [block] = blocks;
20
+ await asyncRetry({times}, async () => {
21
+ await generate({});
37
22
 
38
- const [coinbaseTransaction] = block.transaction_ids;
23
+ const wallet = await getChainBalance({lnd});
39
24
 
40
- const {transaction} = chainSendTransaction({
41
- tokens,
42
- destination: address,
43
- fee: defaultFee,
44
- private_key: node.mining_key,
45
- spend_transaction_id: coinbaseTransaction,
46
- spend_vout: defaultVout,
25
+ if (!wallet.chain_balance) {
26
+ throw new Error('ExpectedChainBalanceForNode');
27
+ }
47
28
  });
48
29
 
49
- await mineTransaction({cert, host, pass, port, transaction, user});
50
-
51
- await waitForUtxo({confirmations: 6, lnd, transaction});
52
-
53
30
  const {utxos} = await getUtxos({lnd});
54
31
 
55
- equal(utxos.length, [transaction].length, 'Unspent output returned');
32
+ equal(!!utxos.length, true, 'Unspent output returned');
56
33
 
57
34
  const [utxo] = utxos;
58
35
 
59
- equal(utxo.address, address, 'UTXO address returned');
36
+ equal(!!utxo.address, true, 'UTXO address returned');
60
37
  equal(utxo.address_format, format, 'UTXO address format returned');
61
- equal(utxo.confirmation_count, 6, 'Confirmation count returned');
38
+ equal(utxo.confirmation_count, 100, 'Confirmation count returned');
62
39
  equal(!!utxo.output_script, true, 'Output script returned');
63
- equal(utxo.tokens, tokens - defaultFee, 'UTXO amount returned');
40
+ equal(!!utxo.tokens, true, 'UTXO amount returned');
64
41
  equal(!!utxo.transaction_id, true, 'UTXO transaction id returned');
65
42
  equal(utxo.transaction_vout !== undefined, true, 'UTXO vout returned');
66
43
 
67
- kill();
68
-
69
- await waitForTermination({lnd});
44
+ await kill({});
70
45
 
71
46
  return end();
72
47
  });
@@ -1,8 +1,7 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {getWalletInfo} = require('./../../');
4
- const {spawnLnd} = require('./../macros');
5
- const {waitForTermination} = require('./../macros');
6
5
 
7
6
  const initHeight = 1;
8
7
  const pubKeyHexLength = Buffer.alloc(33).toString('hex').length;
@@ -11,31 +10,25 @@ const walletInfoType = 'wallet';
11
10
 
12
11
  // Getting the wallet info should return info about the wallet
13
12
  test(`Get wallet info`, async ({end, equal, strictSame}) => {
14
- const spawned = await spawnLnd({});
13
+ const {kill, nodes} = await spawnLightningCluster({});
15
14
 
16
- const {lnd} = spawned;
17
- const pubKey = spawned.public_key;
15
+ const [{lnd}] = nodes;
18
16
 
19
17
  const result = await getWalletInfo({lnd});
20
18
 
21
- const expectedUri = `${pubKey}@127.0.0.1:${spawned.listen_port}`;
22
-
23
19
  equal(result.active_channels_count, 0, 'Expected channels count');
24
20
  equal(!!result.alias, true, 'Expected alias');
25
21
  strictSame(result.chains, [regtestChainId], 'Got chains');
26
22
  equal(!!result.current_block_hash, true, 'Expected best block hash');
27
23
  equal(result.current_block_height, initHeight, 'Expected best block height');
28
- equal(result.is_synced_to_chain, true, 'Expected synced to chain status');
29
24
  equal(!!result.latest_block_at, true, 'Last block time');
30
25
  equal(result.peers_count, 0, 'Expected wallet peers count');
31
26
  equal(result.pending_channels_count, 0, 'Expected pending channels count');
32
27
  equal(result.public_key.length, pubKeyHexLength, 'Expected public key');
33
- strictSame(result.uris, [expectedUri], 'Expected node URI');
28
+ strictSame(result.uris.length, 1, 'Expected node URI');
34
29
  equal(!!result.version, true, 'Expected version');
35
30
 
36
- spawned.kill({});
37
-
38
- await waitForTermination({lnd});
31
+ await kill({});
39
32
 
40
33
  return end();
41
34
  });