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,10 +1,9 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {createInvoice} = require('./../../');
4
5
  const {decodePaymentRequest} = require('./../../');
5
6
  const {getIdentity} = require('./../../');
6
- const {spawnLnd} = require('./../macros');
7
- const {waitForTermination} = require('./../macros');
8
7
 
9
8
  const tests = [
10
9
  {
@@ -23,33 +22,35 @@ const tests = [
23
22
 
24
23
  tests.forEach(({description, expected}) => {
25
24
  return test(description, async ({end, equal}) => {
26
- const {kill, lnd} = await spawnLnd({});
27
-
28
- const {request} = await createInvoice({
29
- lnd,
30
- cltv_delta: expected.cltv_delta,
31
- description: expected.description,
32
- secret: expected.secret,
33
- tokens: expected.tokens,
34
- });
35
-
36
- const decoded = await decodePaymentRequest({lnd, request});
37
-
38
- equal(decoded.chain_addresses, expected.chain_addresses, 'Chain address');
39
- equal(decoded.cltv_delta, expected.cltv_delta, 'Decode cltv delta');
40
- equal(!!decoded.created_at, true, 'Created at date');
41
- equal(decoded.description, expected.description, 'Decode description');
42
- equal(decoded.description_hash, expected.description_hash, 'Desc hash');
43
- equal(decoded.destination, (await getIdentity({lnd})).public_key, 'Pk');
44
- equal(!!decoded.expires_at, true, 'Expiration date decoded');
45
- equal(decoded.id, expected.id, 'Decoded payment hash');
46
- equal(decoded.mtokens, expected.mtokens, 'Decode millitokens');
47
- equal(decoded.safe_tokens, expected.safe_tokens, 'Decode safe amount');
48
- equal(decoded.tokens, expected.tokens, 'Decode tokens amount');
49
-
50
- kill();
51
-
52
- await waitForTermination({lnd});
25
+ const [{kill, lnd}] = (await spawnLightningCluster({})).nodes;
26
+
27
+ try {
28
+ const {request} = await createInvoice({
29
+ lnd,
30
+ cltv_delta: expected.cltv_delta,
31
+ description: expected.description,
32
+ secret: expected.secret,
33
+ tokens: expected.tokens,
34
+ });
35
+
36
+ const decoded = await decodePaymentRequest({lnd, request});
37
+
38
+ equal(decoded.chain_addresses, expected.chain_addresses, 'Chain addr');
39
+ equal(decoded.cltv_delta, expected.cltv_delta, 'Decode cltv delta');
40
+ equal(!!decoded.created_at, true, 'Created at date');
41
+ equal(decoded.description, expected.description, 'Decode description');
42
+ equal(decoded.description_hash, expected.description_hash, 'Desc hash');
43
+ equal(decoded.destination, (await getIdentity({lnd})).public_key, 'Pk');
44
+ equal(!!decoded.expires_at, true, 'Expiration date decoded');
45
+ equal(decoded.id, expected.id, 'Decoded payment hash');
46
+ equal(decoded.mtokens, expected.mtokens, 'Decode millitokens');
47
+ equal(decoded.safe_tokens, expected.safe_tokens, 'Decode safe amount');
48
+ equal(decoded.tokens, expected.tokens, 'Decode tokens amount');
49
+ } catch (err) {
50
+ equal(err, null, 'Expected no error');
51
+ }
52
+
53
+ await kill({});
53
54
 
54
55
  return end();
55
56
  });
@@ -1,23 +1,26 @@
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 {deletePayment} = require('./../../');
6
6
  const {getPayments} = require('./../../');
7
7
  const {pay} = require('./../../');
8
8
  const {setupChannel} = require('./../macros');
9
9
 
10
+ const size = 2;
10
11
  const tokens = 100;
11
12
 
12
13
  // Deleting a payment should delete the payment record
13
14
  test('Delete payment', async ({afterEach, fail, end, equal, strictSame}) => {
14
- const cluster = await createCluster({is_remote_skipped: true});
15
+ const {kill, nodes} = await spawnLightningCluster({size});
15
16
 
16
- const {lnd} = cluster.control;
17
+ const [control, target] = nodes;
17
18
 
18
- await setupChannel({lnd, generate: cluster.generate, to: cluster.target});
19
+ const {lnd} = control;
19
20
 
20
- const invoice = await createInvoice({tokens, lnd: cluster.target.lnd});
21
+ await setupChannel({lnd, generate: control.generate, to: target});
22
+
23
+ const invoice = await createInvoice({tokens, lnd: target.lnd});
21
24
 
22
25
  let paid;
23
26
 
@@ -26,7 +29,7 @@ test('Delete payment', async ({afterEach, fail, end, equal, strictSame}) => {
26
29
  } catch (err) {
27
30
  fail('Payment should be made to destination');
28
31
 
29
- await cluster.kill({});
32
+ await kill({});
30
33
 
31
34
  return end();
32
35
  }
@@ -39,7 +42,7 @@ test('Delete payment', async ({afterEach, fail, end, equal, strictSame}) => {
39
42
  } catch (err) {
40
43
  strictSame(err, [501, 'DeletePaymentMethodNotSupported']);
41
44
 
42
- await cluster.kill({});
45
+ await kill({});
43
46
 
44
47
  return end();
45
48
  }
@@ -48,7 +51,7 @@ test('Delete payment', async ({afterEach, fail, end, equal, strictSame}) => {
48
51
 
49
52
  equal(priorLength - wipedLength, [paid].length, 'Payment deleted');
50
53
 
51
- await cluster.kill({});
54
+ await kill({});
52
55
 
53
56
  return end();
54
57
  });
@@ -1,35 +1,32 @@
1
+ const asyncRetry = require('async/retry');
2
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
3
  const {test} = require('@alexbosworth/tap');
2
4
 
3
- const {createCluster} = require('./../macros');
4
5
  const {createInvoice} = require('./../../');
5
6
  const {deletePayments} = require('./../../');
6
7
  const {getPayments} = require('./../../');
7
8
  const {pay} = require('./../../');
8
9
  const {setupChannel} = require('./../macros');
9
10
 
11
+ const size = 2;
12
+ const times = 1000;
10
13
  const tokens = 100;
11
14
 
12
15
  // Deleting payments should delete all payments
13
16
  test('Delete payments', async ({afterEach, fail, end, equal}) => {
14
- const cluster = await createCluster({is_remote_skipped: true});
17
+ const {kill, nodes} = await spawnLightningCluster({size});
15
18
 
16
- const {lnd} = cluster.control;
19
+ const [control, target] = nodes;
17
20
 
18
- await setupChannel({lnd, generate: cluster.generate, to: cluster.target});
21
+ const {generate, lnd} = control;
19
22
 
20
- const invoice = await createInvoice({tokens, lnd: cluster.target.lnd});
23
+ await setupChannel({generate, lnd, to: target});
21
24
 
22
- let paid;
25
+ const invoice = await createInvoice({tokens, lnd: target.lnd});
23
26
 
24
- try {
25
- paid = await pay({lnd, request: invoice.request});
26
- } catch (err) {
27
- fail('Payment should be made to destination');
28
-
29
- await cluster.kill({});
30
-
31
- return end();
32
- }
27
+ const paid = await asyncRetry({times}, async () => {
28
+ return await pay({lnd, request: invoice.request});
29
+ });
33
30
 
34
31
  const priorLength = (await getPayments({lnd})).payments.length;
35
32
 
@@ -39,7 +36,7 @@ test('Delete payments', async ({afterEach, fail, end, equal}) => {
39
36
 
40
37
  equal(priorLength - wipedLength, [paid].length, 'Payment history deleted');
41
38
 
42
- await cluster.kill({});
39
+ await kill({});
43
40
 
44
41
  return end();
45
42
  });
@@ -1,19 +1,18 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
- const {authenticatedLndGrpc} = require('./../../');
4
4
  const {getAccessIds} = require('./../../');
5
5
  const {grantAccess} = require('./../../');
6
6
  const {spawnLnd} = require('./../macros');
7
- const {waitForTermination} = require('./../macros');
8
7
 
9
8
  const defaultId = '0';
10
9
  const id = '1';
11
10
 
12
11
  // Getting access ids should return root macaroon ids
13
12
  test(`Get access ids`, async ({end, equal, rejects, strictSame}) => {
14
- const spawned = await spawnLnd({});
13
+ const {kill, nodes} = await spawnLightningCluster({});
15
14
 
16
- const {lnd, kill} = spawned;
15
+ const [{lnd}] = nodes;
17
16
 
18
17
  await grantAccess({id, lnd, is_ok_to_create_chain_addresses: true});
19
18
 
@@ -30,9 +29,7 @@ test(`Get access ids`, async ({end, equal, rejects, strictSame}) => {
30
29
  }
31
30
  }
32
31
 
33
- kill();
34
-
35
- await waitForTermination({lnd});
32
+ await kill({});
36
33
 
37
34
  return end();
38
35
  });
@@ -1,22 +1,26 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
- const {createCluster} = require('./../macros');
4
4
  const {getBackup} = require('./../../');
5
5
  const {setupChannel} = require('./../macros');
6
6
  const {verifyBackup} = require('./../../');
7
7
 
8
+ const size = 2;
9
+
8
10
  // Getting a channel backup should return a channel backup
9
11
  test(`Get channel backup`, async ({end, equal}) => {
10
- const cluster = await createCluster({is_remote_skipped: true});
12
+ const {kill, nodes} = await spawnLightningCluster({size});
13
+
14
+ const [control, target] = nodes;
11
15
 
12
16
  const channel = await setupChannel({
13
- generate: cluster.generate,
14
- lnd: cluster.control.lnd,
15
- to: cluster.target,
17
+ generate: control.generate,
18
+ lnd: control.lnd,
19
+ to: target,
16
20
  });
17
21
 
18
22
  const {backup} = await getBackup({
19
- lnd: cluster.control.lnd,
23
+ lnd: control.lnd,
20
24
  transaction_id: channel.transaction_id,
21
25
  transaction_vout: channel.transaction_vout,
22
26
  });
@@ -25,14 +29,14 @@ test(`Get channel backup`, async ({end, equal}) => {
25
29
 
26
30
  const channelBackup = await verifyBackup({
27
31
  backup,
28
- lnd: cluster.control.lnd,
32
+ lnd: control.lnd,
29
33
  transaction_id: channel.transaction_id,
30
34
  transaction_vout: channel.transaction_vout,
31
35
  });
32
36
 
33
37
  equal(channelBackup.is_valid, true, 'Channel backup is a valid backup');
34
38
 
35
- await cluster.kill({});
39
+ await kill({});
36
40
 
37
41
  return end();
38
42
  });
@@ -1,22 +1,20 @@
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 {getBackups} = require('./../../');
6
6
  const {setupChannel} = require('./../macros');
7
7
 
8
+ const size = 2;
9
+
8
10
  // Getting a set of channel backups should return channel backups
9
11
  test(`Get channel backup`, async ({end, equal}) => {
10
12
  await asyncRetry({}, async () => {
11
- const cluster = await createCluster({is_remote_skipped: true});
13
+ const {kill, nodes} = await spawnLightningCluster({size});
12
14
 
13
- const {lnd} = cluster.control;
15
+ const [{generate, lnd}, target] = nodes;
14
16
 
15
- const channel = await setupChannel({
16
- lnd,
17
- generate: cluster.generate,
18
- to: cluster.target,
19
- });
17
+ const channel = await setupChannel({generate, lnd, to: target});
20
18
 
21
19
  const {backup, channels} = await getBackups({lnd});
22
20
 
@@ -26,10 +24,10 @@ test(`Get channel backup`, async ({end, equal}) => {
26
24
  const [chanBackup] = channels;
27
25
 
28
26
  equal(!!chanBackup.backup.length, true, 'Channel backup has its own blob');
29
- equal(chanBackup.transaction_id, channel.transaction_id, 'Chan tx id given');
27
+ equal(chanBackup.transaction_id, channel.transaction_id, 'Chan tx id');
30
28
  equal(chanBackup.transaction_vout, channel.transaction_vout, 'Chan vout');
31
29
 
32
- await cluster.kill({});
30
+ await kill({});
33
31
 
34
32
  return;
35
33
  });
@@ -1,37 +1,19 @@
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
- const {createChainAddress} = require('./../../');
6
- const {generateBlocks} = require('./../macros');
7
5
  const {getChainBalance} = require('./../../');
8
- const {mineTransaction} = require('./../macros');
9
- const {spawnLnd} = require('./../macros');
10
- const {waitForTermination} = require('./../macros');
11
- const {waitForUtxo} = require('./../macros');
12
6
 
13
- const count = 100;
14
- const defaultFee = 1e3;
15
- const defaultVout = 0;
16
7
  const emptyChainBalance = 0;
17
- const format = 'np2wpkh';
18
- const interval = retryCount => 50 * Math.pow(2, retryCount);
19
- const times = 15;
20
- const tokens = 1e8;
8
+ const interval = 1;
9
+ const times = 150;
10
+ const tokens = 5000000000;
21
11
 
22
12
  // Getting chain balance should result in a chain balance
23
13
  test(`Get the chain balance`, async ({end, equal}) => {
24
- const node = await spawnLnd({});
14
+ const {kill, nodes} = await spawnLightningCluster({});
25
15
 
26
- const cert = node.chain_rpc_cert_file;
27
- const host = node.listen_ip;
28
- const {kill} = node;
29
- const pass = node.chain_rpc_pass;
30
- const port = node.chain_rpc_port;
31
- const {lnd} = node;
32
- const user = node.chain_rpc_user;
33
-
34
- const {address} = await createChainAddress({format, lnd});
16
+ const [{generate, lnd}] = nodes;
35
17
 
36
18
  // The initial chain balance should be zero
37
19
  {
@@ -41,40 +23,14 @@ test(`Get the chain balance`, async ({end, equal}) => {
41
23
  }
42
24
 
43
25
  // Generate some funds for LND
44
- const {blocks} = await node.generate({count});
45
-
46
- const [block] = blocks;
47
-
48
- const [coinbaseTransaction] = block.transaction_ids;
49
-
50
- const {transaction} = chainSendTransaction({
51
- tokens,
52
- destination: address,
53
- fee: defaultFee,
54
- private_key: node.mining_key,
55
- spend_transaction_id: coinbaseTransaction,
56
- spend_vout: defaultVout,
57
- });
58
-
59
- // Wait for generation to be over
60
- await asyncRetry({interval, times}, async () => {
61
- await mineTransaction({cert, host, pass, port, transaction, user});
62
-
63
- if (!(await getChainBalance({lnd})).chain_balance) {
64
- throw new Error('ExpectedChainBalanceReflected');
65
- }
66
-
67
- return;
68
- });
26
+ await generate({count: 100});
69
27
 
70
28
  // Check that the balance is updated
71
29
  const postDeposit = await getChainBalance({lnd});
72
30
 
73
- equal(postDeposit.chain_balance, tokens - defaultFee, 'Deposited funds');
74
-
75
- kill();
31
+ equal(postDeposit.chain_balance >= tokens, true, 'Got funds');
76
32
 
77
- await waitForTermination({lnd});
33
+ await kill({});
78
34
 
79
35
  return end();
80
36
  });
@@ -1,27 +1,38 @@
1
- const {address} = require('bitcoinjs-lib');
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 {createChainAddress} = require('./../../');
5
- const {createCluster} = require('./../macros');
6
- const {delay} = require('./../macros');
6
+ const {getChainBalance} = require('./../../');
7
7
  const {getChainFeeEstimate} = require('./../../');
8
8
 
9
- const expectedFee = 9750;
9
+ const expectedFee = 8650;
10
10
  const expectedFeeRate = 50;
11
- const format = 'p2wpkh';
11
+ const format = 'np2wpkh';
12
+ const size = 2;
13
+ const times = 200;
12
14
  const tokens = 1e6;
13
15
 
14
16
  // Getting a chain fee estimate should return an estimate of the chain fee
15
17
  test(`Get chain fee estimate`, async ({end, equal}) => {
16
- const cluster = await createCluster({is_remote_skipped: true});
18
+ const {kill, nodes} = await spawnLightningCluster({size});
17
19
 
18
- const {lnd} = cluster.target;
20
+ const [control, {lnd}] = nodes;
19
21
 
20
- const address1 = (await createChainAddress({format, lnd})).address;
22
+ const address1 = (await createChainAddress({lnd})).address;
21
23
  const address2 = (await createChainAddress({format, lnd})).address;
22
24
 
25
+ // Generate coins for the node
26
+ await asyncRetry({times}, async () => {
27
+ if (!(await getChainBalance({lnd: control.lnd})).chain_balance) {
28
+ await control.generate({});
29
+
30
+ throw new Error('ExpectedChainBalance');
31
+ }
32
+ });
33
+
23
34
  const estimate = await getChainFeeEstimate({
24
- lnd: cluster.control.lnd,
35
+ lnd: control.lnd,
25
36
  send_to: [
26
37
  {address: address1, tokens: tokens / [address1, address2].length},
27
38
  {address: address2, tokens: tokens / [address1, address2].length},
@@ -31,7 +42,7 @@ test(`Get chain fee estimate`, async ({end, equal}) => {
31
42
  equal(estimate.fee, expectedFee, 'Total fee is estimated');
32
43
  equal(estimate.tokens_per_vbyte, expectedFeeRate, 'Fee per vbyte is given');
33
44
 
34
- await cluster.kill({});
45
+ await kill({});
35
46
 
36
47
  return end();
37
48
  });
@@ -1,62 +1,35 @@
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
- const {createChainAddress} = require('./../../');
6
- const {delay} = require('./../macros');
7
- const {generateBlocks} = require('./../macros');
8
5
  const {getChainBalance} = require('./../../');
9
6
  const {getChainTransactions} = require('./../../');
10
- const {getWalletVersion} = require('./../../');
11
- const {mineTransaction} = require('./../macros');
12
- const {spawnLnd} = require('./../macros');
13
- const {waitForTermination} = require('./../macros');
14
- const {waitForUtxo} = require('./../macros');
7
+ const {getWalletInfo} = require('./../../');
15
8
 
16
9
  const count = 100;
17
10
  const defaultFee = 1e3;
18
- const defaultVout = 0;
19
- const emptyChainBalance = 0;
20
11
  const format = 'np2wpkh';
21
- const interval = retryCount => 10 * Math.pow(2, retryCount);
22
- const times = 20;
23
- const tokens = 1e8;
12
+ const times = 300;
24
13
 
25
14
  // Getting chain transactions should list out the chain transactions
26
- test(`Get chain transactions`, async ({end, equal, fail, strictSame}) => {
27
- const node = await spawnLnd({});
15
+ test(`Get chain transactions`, async ({end, equal, strictSame}) => {
16
+ const {kill, nodes} = await spawnLightningCluster({});
28
17
 
29
- const cert = node.chain_rpc_cert_file;
30
- const host = node.listen_ip;
31
- const {kill} = node;
32
- const pass = node.chain_rpc_pass;
33
- const port = node.chain_rpc_port;
34
- const {lnd} = node;
35
- const user = node.chain_rpc_user;
36
-
37
- const {address} = await createChainAddress({format, lnd});
18
+ const [{generate, lnd}] = nodes;
38
19
 
39
20
  // Generate some funds for LND
40
- const {blocks} = await node.generate({count});
41
-
42
- const [block] = blocks;
21
+ await generate({count});
43
22
 
44
- const [coinbaseTransaction] = block.transaction_ids;
23
+ await asyncRetry({interval: 10, times: 1000}, async () => {
24
+ const wallet = await getWalletInfo({lnd});
45
25
 
46
- const {transaction} = chainSendTransaction({
47
- tokens,
48
- destination: address,
49
- fee: defaultFee,
50
- private_key: node.mining_key,
51
- spend_transaction_id: coinbaseTransaction,
52
- spend_vout: defaultVout,
26
+ if (!wallet.is_synced_to_chain) {
27
+ throw new Error('ExpectedWalletSyncedToChain');
28
+ }
53
29
  });
54
30
 
55
31
  // Wait for generation to be over
56
- await asyncRetry({interval, times}, async () => {
57
- // Generate to confirm the tx
58
- await mineTransaction({cert, host, pass, port, transaction, user});
59
-
32
+ await asyncRetry({times}, async () => {
60
33
  const {transactions} = await getChainTransactions({lnd});
61
34
 
62
35
  const [tx] = transactions;
@@ -70,16 +43,22 @@ test(`Get chain transactions`, async ({end, equal, fail, strictSame}) => {
70
43
 
71
44
  const {transactions} = await getChainTransactions({lnd});
72
45
 
73
- equal(transactions.length, [transaction].length, 'Transaction found');
46
+ equal(transactions.length > 1, true, 'Transaction found');
74
47
 
75
48
  const [tx] = transactions;
76
49
 
50
+ equal(!!tx.block_id, true, 'Transaction has block id');
51
+ equal(!!tx.confirmation_count, true, 'Transaction confirm count');
52
+ equal(!!tx.confirmation_height, true, 'Transaction confirm height');
53
+ equal(!!tx.created_at, true, 'Transaction record create time');
54
+ equal(tx.description, undefined, 'No tx description');
55
+ equal(tx.fee, undefined, 'No transaction fee');
56
+ equal(!!tx.id, true, 'Transaction id');
77
57
  equal(tx.is_confirmed, true, 'Transaction is confirmed');
78
58
  equal(tx.is_outgoing, false, 'Transaction is incoming');
79
- strictSame(tx.output_addresses, [address], 'Address is returned');
80
- equal(tx.tokens, tokens - defaultFee, 'Chain tokens are returned');
81
-
82
- const wallet = await getWalletVersion({lnd});
59
+ equal(tx.output_addresses.length, 1, 'Tx output address');
60
+ equal(tx.tokens, 5000000000, 'Got coinbase reward tokens');
61
+ equal(!!tx.transaction, true, 'Got transaction hex');
83
62
 
84
63
  const onlyAfter = await getChainTransactions({
85
64
  lnd,
@@ -88,10 +67,11 @@ test(`Get chain transactions`, async ({end, equal, fail, strictSame}) => {
88
67
 
89
68
  equal(onlyAfter.transactions.length, [].length, 'No transactions after');
90
69
 
91
- const onlyBefore = await getChainTransactions({
92
- lnd,
93
- before: tx.confirmation_height,
94
- });
70
+ const [height] = transactions
71
+ .map(n => n.confirmation_height)
72
+ .sort((a, b) => a - b);
73
+
74
+ const onlyBefore = await getChainTransactions({lnd, before: height});
95
75
 
96
76
  equal(onlyBefore.transactions.length, [].length, 'No tx before');
97
77
 
@@ -103,9 +83,7 @@ test(`Get chain transactions`, async ({end, equal, fail, strictSame}) => {
103
83
 
104
84
  strictSame(between.transactions.length, [tx].length, 'One transaction');
105
85
 
106
- kill();
107
-
108
- await waitForTermination({lnd});
86
+ await kill({});
109
87
 
110
88
  return end();
111
89
  });
@@ -1,27 +1,27 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
- const {createCluster} = require('./../macros');
4
4
  const {getChannel} = require('./../../');
5
5
  const {getChannels} = require('./../../');
6
6
  const {setupChannel} = require('./../macros');
7
7
 
8
- const confirmationCount = 20;
9
8
  const {ceil} = Math;
9
+ const size = 2;
10
10
 
11
11
  // Getting a channel should return channel details from the channel graph
12
12
  test(`Get channel`, async ({end, equal}) => {
13
- const cluster = await createCluster({is_remote_skipped: true});
13
+ const {kill, nodes} = await spawnLightningCluster({size});
14
14
 
15
- const {lnd} = cluster.control;
15
+ const [{generate, lnd}, target] = nodes;
16
16
 
17
- await setupChannel({lnd, generate: cluster.generate, to: cluster.target});
17
+ await setupChannel({generate, lnd, to: target});
18
18
 
19
19
  const [channel] = (await getChannels({lnd})).channels;
20
20
 
21
21
  const details = await getChannel({lnd, id: channel.id});
22
22
 
23
23
  equal(details.capacity, channel.capacity, 'Capacity');
24
- equal(details.policies.length, [cluster.control, cluster.target].length);
24
+ equal(details.policies.length, size, 'Policies for both nodes');
25
25
 
26
26
  details.policies.forEach(policy => {
27
27
  equal(policy.base_fee_mtokens, '1000', 'Base fee mtokens');
@@ -41,7 +41,7 @@ test(`Get channel`, async ({end, equal}) => {
41
41
 
42
42
  equal(Date.now() - new Date(details.updated_at) < 1e5, true, 'Updated at');
43
43
 
44
- await cluster.kill({});
44
+ await kill({});
45
45
 
46
46
  return end();
47
47
  });
@@ -1,22 +1,21 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
1
2
  const {test} = require('@alexbosworth/tap');
2
3
 
3
4
  const {getChannelBalance} = require('./../../');
4
- const {spawnLnd} = require('./../macros');
5
- const {waitForTermination} = require('./../macros');
6
5
 
7
6
  const emptyBalance = 0;
8
7
 
9
8
  // Getting channel balance should result in a channel balance
10
9
  test(`Get the channel balance`, async ({end, equal}) => {
11
- const {kill, lnd} = await spawnLnd({});
10
+ const {kill, nodes} = await spawnLightningCluster({});
11
+
12
+ const [{lnd}] = nodes;
12
13
 
13
14
  const result = await getChannelBalance({lnd});
14
15
 
15
16
  equal(result.channel_balance, emptyBalance, 'Valid channel balance');
16
17
 
17
- kill();
18
-
19
- await waitForTermination({lnd});
18
+ await kill({});
20
19
 
21
20
  return end();
22
21
  });