ln-service 59.4.1 → 59.6.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.
- package/CHANGELOG.md +15 -0
- package/README.md +57 -8
- package/package.json +9 -4
- package/.gitattributes +0 -1
- package/.tm_properties +0 -1
- package/test/autopilotrpc-integration/test_autopilot.js +0 -87
- package/test/chainrpc-integration/test_get_block.js +0 -58
- package/test/chainrpc-integration/test_get_block_header.js +0 -62
- package/test/chainrpc-integration/test_get_height.js +0 -42
- package/test/chainrpc-integration/test_subscribe_to_blocks.js +0 -97
- package/test/chainrpc-integration/test_subscribe_to_chain_address.js +0 -119
- package/test/chainrpc-integration/test_subscribe_to_chain_spend.js +0 -116
- package/test/integration/test_add_peer.js +0 -59
- package/test/integration/test_cancel_pending_channel.js +0 -46
- package/test/integration/test_close_channel.js +0 -60
- package/test/integration/test_close_wait_pending.js +0 -121
- package/test/integration/test_create_chain_address.js +0 -63
- package/test/integration/test_create_invoice.js +0 -49
- package/test/integration/test_decode_payment_request.js +0 -75
- package/test/integration/test_delete_payment.js +0 -38
- package/test/integration/test_delete_payments.js +0 -42
- package/test/integration/test_delete_pending_channel.js +0 -202
- package/test/integration/test_encrypted_routes.js +0 -66
- package/test/integration/test_get_access_ids.js +0 -27
- package/test/integration/test_get_backup.js +0 -40
- package/test/integration/test_get_backups.js +0 -38
- package/test/integration/test_get_chain_balance.js +0 -36
- package/test/integration/test_get_chain_fee_estimate.js +0 -63
- package/test/integration/test_get_chain_transactions.js +0 -83
- package/test/integration/test_get_channel.js +0 -64
- package/test/integration/test_get_channel_balance.js +0 -23
- package/test/integration/test_get_channels.js +0 -84
- package/test/integration/test_get_closed_channels.js +0 -275
- package/test/integration/test_get_configuration.js +0 -35
- package/test/integration/test_get_failed_payments.js +0 -164
- package/test/integration/test_get_fee_rates.js +0 -40
- package/test/integration/test_get_forwards.js +0 -144
- package/test/integration/test_get_invoice.js +0 -67
- package/test/integration/test_get_invoices.js +0 -88
- package/test/integration/test_get_methods.js +0 -30
- package/test/integration/test_get_network_centrality.js +0 -72
- package/test/integration/test_get_network_graph.js +0 -87
- package/test/integration/test_get_network_info.js +0 -33
- package/test/integration/test_get_node.js +0 -117
- package/test/integration/test_get_payments.js +0 -69
- package/test/integration/test_get_peers.js +0 -58
- package/test/integration/test_get_pending_coop.js +0 -122
- package/test/integration/test_get_pending_force.js +0 -172
- package/test/integration/test_get_pending_payments.js +0 -86
- package/test/integration/test_get_route_to_destination.js +0 -153
- package/test/integration/test_get_settlement_status.js +0 -78
- package/test/integration/test_get_utxos.js +0 -49
- package/test/integration/test_get_wallet_info.js +0 -55
- package/test/integration/test_grant_access.js +0 -69
- package/test/integration/test_open_channel.js +0 -93
- package/test/integration/test_open_channel_max.js +0 -92
- package/test/integration/test_open_channels.js +0 -164
- package/test/integration/test_open_low_reserve.js +0 -92
- package/test/integration/test_open_simplified_taproot.js +0 -174
- package/test/integration/test_open_standard_taproot.js +0 -94
- package/test/integration/test_pay.js +0 -149
- package/test/integration/test_pay_private_invoice.js +0 -120
- package/test/integration/test_payment_errors.js +0 -102
- package/test/integration/test_propose_channel.js +0 -474
- package/test/integration/test_push_funds.js +0 -82
- package/test/integration/test_rebalance.js +0 -70
- package/test/integration/test_recover_funds_from_channel.js +0 -207
- package/test/integration/test_recover_funds_from_channels.js +0 -203
- package/test/integration/test_remove_peer.js +0 -52
- package/test/integration/test_restrict_macaroon.js +0 -96
- package/test/integration/test_revoke_access.js +0 -41
- package/test/integration/test_send_message_to_peer.js +0 -91
- package/test/integration/test_send_to_chain_address.js +0 -109
- package/test/integration/test_send_to_chain_addresses.js +0 -71
- package/test/integration/test_sign_message.js +0 -22
- package/test/integration/test_stop_daemon.js +0 -33
- package/test/integration/test_subscribe_to_backups.js +0 -94
- package/test/integration/test_subscribe_to_channels.js +0 -186
- package/test/integration/test_subscribe_to_graph.js +0 -176
- package/test/integration/test_subscribe_to_invoices.js +0 -147
- package/test/integration/test_subscribe_to_messages.js +0 -180
- package/test/integration/test_subscribe_to_open_requests.js +0 -167
- package/test/integration/test_subscribe_to_peer_messages.js +0 -130
- package/test/integration/test_subscribe_to_peers.js +0 -61
- package/test/integration/test_subscribe_to_rpc_requests.js +0 -309
- package/test/integration/test_subscribe_to_transactions.js +0 -93
- package/test/integration/test_trusted_funding.js +0 -298
- package/test/integration/test_trusted_open.js +0 -94
- package/test/integration/test_update_routing_fees.js +0 -108
- package/test/integration/test_verify_access.js +0 -38
- package/test/integration/test_verify_backup.js +0 -53
- package/test/integration/test_verify_backups.js +0 -54
- package/test/integration/test_verify_message.js +0 -24
- package/test/invoicesrpc-integration/test_cancel_invoice.js +0 -91
- package/test/invoicesrpc-integration/test_create_hinted_invoice.js +0 -95
- package/test/invoicesrpc-integration/test_get_sweep_transactions.js +0 -124
- package/test/invoicesrpc-integration/test_push_payment.js +0 -92
- package/test/invoicesrpc-integration/test_settle_invoice.js +0 -136
- package/test/invoicesrpc-integration/test_subscribe_cancel_invoice.js +0 -124
- package/test/invoicesrpc-integration/test_subscribe_settle_invoice.js +0 -123
- package/test/macros/index.js +0 -19
- package/test/macros/setup_channel.js +0 -101
- package/test/macros/wait_for_channel.js +0 -99
- package/test/macros/wait_for_pending_channel.js +0 -52
- package/test/macros/wait_for_route.js +0 -76
- package/test/macros/wait_for_termination.js +0 -29
- package/test/macros/wait_for_utxo.js +0 -56
- package/test/peersrpc-integration/test_add_advertised_feature.js +0 -43
- package/test/peersrpc-integration/test_add_external_socket.js +0 -36
- package/test/peersrpc-integration/test_remove_advertised_feature.js +0 -37
- package/test/peersrpc-integration/test_remove_external_socket.js +0 -34
- package/test/peersrpc-integration/test_update_alias.js +0 -33
- package/test/peersrpc-integration/test_update_color.js +0 -33
- package/test/routerrpc-integration/test_delete_forwarding_reputations.js +0 -101
- package/test/routerrpc-integration/test_disable_channel.js +0 -41
- package/test/routerrpc-integration/test_get_forwarding_confidence.js +0 -90
- package/test/routerrpc-integration/test_get_forwarding_reputations.js +0 -128
- package/test/routerrpc-integration/test_get_pathfinding_settings.js +0 -40
- package/test/routerrpc-integration/test_get_payment.js +0 -130
- package/test/routerrpc-integration/test_get_route_confidence.js +0 -77
- package/test/routerrpc-integration/test_get_route_through_hops.js +0 -148
- package/test/routerrpc-integration/test_get_routing_fee_estimate.js +0 -76
- package/test/routerrpc-integration/test_is_destination_payable.js +0 -53
- package/test/routerrpc-integration/test_multipath_payment.js +0 -178
- package/test/routerrpc-integration/test_pay_via_payment_details.js +0 -175
- package/test/routerrpc-integration/test_pay_via_payment_request.js +0 -151
- package/test/routerrpc-integration/test_pay_via_routes.js +0 -224
- package/test/routerrpc-integration/test_probe_for_route.js +0 -150
- package/test/routerrpc-integration/test_route_from_channels_complex.js +0 -327
- package/test/routerrpc-integration/test_route_from_channels_simple.js +0 -151
- package/test/routerrpc-integration/test_subscribe_to_forward_requests.js +0 -225
- package/test/routerrpc-integration/test_subscribe_to_forwards.js +0 -552
- package/test/routerrpc-integration/test_subscribe_to_past_payments.js +0 -81
- package/test/routerrpc-integration/test_subscribe_to_payments.js +0 -115
- package/test/routerrpc-integration/test_update_pathfinding_settings.js +0 -71
- package/test/runner.js +0 -30
- package/test/signerrpc-integration/test_begin_group_signing_session.js +0 -505
- package/test/signerrpc-integration/test_diffie_hellman_compute_secret.js +0 -37
- package/test/signerrpc-integration/test_sign_bytes.js +0 -76
- package/test/signerrpc-integration/test_sign_taproot.js +0 -436
- package/test/signerrpc-integration/test_sign_transaction.js +0 -35
- package/test/signerrpc-integration/test_verify_bytes_signature.js +0 -103
- package/test/tower_clientrpc-integration/test_connect_watchtower.js +0 -60
- package/test/tower_clientrpc-integration/test_get_connected_watchtowers.js +0 -70
- package/test/tower_serverrpc-integration/test_get_tower_server_info.js +0 -34
- package/test/versionrpc-integration/test_get_wallet_version.js +0 -38
- package/test/walletrpc-integration/test_broadcast_chain_transaction.js +0 -62
- package/test/walletrpc-integration/test_create_funded_psbt.js +0 -141
- package/test/walletrpc-integration/test_delete_chain_transaction.js +0 -82
- package/test/walletrpc-integration/test_fund_psbt.js +0 -489
- package/test/walletrpc-integration/test_get_chain_addresses.js +0 -60
- package/test/walletrpc-integration/test_get_chain_fee_rate.js +0 -24
- package/test/walletrpc-integration/test_get_chain_transaction.js +0 -70
- package/test/walletrpc-integration/test_get_locked_utxos.js +0 -67
- package/test/walletrpc-integration/test_get_master_public_keys.js +0 -84
- package/test/walletrpc-integration/test_get_minimum_relay_fee.js +0 -26
- package/test/walletrpc-integration/test_get_pending_sweeps.js +0 -83
- package/test/walletrpc-integration/test_get_public_key.js +0 -28
- package/test/walletrpc-integration/test_lock_utxo.js +0 -80
- package/test/walletrpc-integration/test_partially_sign_psbt.js +0 -224
- package/test/walletrpc-integration/test_request_batched_fee_increase.js +0 -60
- package/test/walletrpc-integration/test_request_chain_fee_increase.js +0 -63
- package/test/walletrpc-integration/test_send_to_chain_output_scripts.js +0 -69
- package/test/walletrpc-integration/test_sign_chain_address_message.js +0 -32
- package/test/walletrpc-integration/test_sign_psbt.js +0 -108
- package/test/walletrpc-integration/test_unlock_utxo.js +0 -72
- package/test/walletrpc-integration/test_update_chain_transaction.js +0 -43
- package/test/walletrpc-integration/test_verify_chain_address_message.js +0 -60
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
const {strictEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
|
|
4
|
-
const asyncRetry = require('async/retry');
|
|
5
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
6
|
-
|
|
7
|
-
const {createChainAddress} = require('./../../');
|
|
8
|
-
const {getChainBalance} = require('./../../');
|
|
9
|
-
const {getChainTransactions} = require('./../../');
|
|
10
|
-
const {getHeight} = require('./../../');
|
|
11
|
-
const {sendToChainAddress} = require('./../../');
|
|
12
|
-
const {subscribeToChainAddress} = require('./../../');
|
|
13
|
-
|
|
14
|
-
const count = 100;
|
|
15
|
-
const defaultFee = 1e3;
|
|
16
|
-
const defaultVout = 0;
|
|
17
|
-
const format = 'np2wpkh';
|
|
18
|
-
const interval = 1;
|
|
19
|
-
const times = 1500;
|
|
20
|
-
const tokens = 1e8;
|
|
21
|
-
|
|
22
|
-
// Subscribing to chain transaction confirmations should trigger events
|
|
23
|
-
test(`Subscribe to chain transactions`, async () => {
|
|
24
|
-
await asyncRetry({interval, times}, async () => {
|
|
25
|
-
const {kill, nodes} = await spawnLightningCluster({});
|
|
26
|
-
|
|
27
|
-
const [{chain, generate, lnd}] = nodes;
|
|
28
|
-
|
|
29
|
-
// Wait for chainrpc to be active
|
|
30
|
-
await asyncRetry({interval, times}, async () => {
|
|
31
|
-
if (!!(await getChainBalance({lnd})).chain_balance) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
await generate({});
|
|
36
|
-
|
|
37
|
-
await getHeight({lnd});
|
|
38
|
-
|
|
39
|
-
throw new Error('ExpectedChainBalance');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
let firstConf;
|
|
43
|
-
const {address} = await createChainAddress({format, lnd});
|
|
44
|
-
const startHeight = (await getHeight({lnd})).current_block_height;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const sub = subscribeToChainAddress({
|
|
48
|
-
lnd,
|
|
49
|
-
min_height: startHeight,
|
|
50
|
-
p2sh_address: address,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
sub.on('confirmation', conf => firstConf = conf);
|
|
54
|
-
sub.on('error', err => {});
|
|
55
|
-
|
|
56
|
-
await generate({count});
|
|
57
|
-
|
|
58
|
-
await sendToChainAddress({lnd, address, tokens});
|
|
59
|
-
|
|
60
|
-
const {transactions} = await getChainTransactions({lnd});
|
|
61
|
-
|
|
62
|
-
const [{transaction}] = transactions
|
|
63
|
-
.filter(n => !n.is_confirmed)
|
|
64
|
-
.filter(n => !!n.is_outgoing);
|
|
65
|
-
|
|
66
|
-
if (!transaction) {
|
|
67
|
-
throw new Error('ExpectedTransactionInSubscribeToChainAddressResult');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Wait for generation to be over
|
|
71
|
-
await asyncRetry({interval, times}, async () => {
|
|
72
|
-
await generate({});
|
|
73
|
-
|
|
74
|
-
if (!firstConf) {
|
|
75
|
-
throw new Error('ExpectedSubscribeToChainAddressSeesConf');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
strictEqual(firstConf.block.length, 64, 'Confirmation hash returned');
|
|
79
|
-
strictEqual(firstConf.height >= 102, true, 'Got confirmation height');
|
|
80
|
-
strictEqual(firstConf.transaction, transaction, 'Confirmation raw tx');
|
|
81
|
-
|
|
82
|
-
return;
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
let secondConf;
|
|
86
|
-
|
|
87
|
-
const sub2 = subscribeToChainAddress({
|
|
88
|
-
lnd,
|
|
89
|
-
min_confirmations: 6,
|
|
90
|
-
min_height: startHeight,
|
|
91
|
-
p2sh_address: address,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
sub2.on('error', () => {});
|
|
95
|
-
|
|
96
|
-
sub2.on('confirmation', conf => secondConf = conf);
|
|
97
|
-
|
|
98
|
-
// Wait for generation to be over
|
|
99
|
-
await asyncRetry({interval, times}, async () => {
|
|
100
|
-
await generate({});
|
|
101
|
-
|
|
102
|
-
if (!secondConf) {
|
|
103
|
-
throw new Error('ExpectedSubscribeToChainAddressSeesConfirmation');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
strictEqual(secondConf.block.length, 64, 'Confirmation hash returned');
|
|
107
|
-
strictEqual(secondConf.height >= 102, true, 'Confirmation block height');
|
|
108
|
-
strictEqual(secondConf.transaction, transaction, '2nd conf tx returned');
|
|
109
|
-
|
|
110
|
-
return;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
[sub, sub2].forEach(n => n.removeAllListeners());
|
|
114
|
-
|
|
115
|
-
await kill({});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return;
|
|
119
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
const {once} = require('node:events');
|
|
2
|
-
const {strictEqual} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const asyncRetry = require('async/retry');
|
|
6
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
7
|
-
|
|
8
|
-
const {createChainAddress} = require('./../../');
|
|
9
|
-
const {getChainBalance} = require('./../../');
|
|
10
|
-
const {getHeight} = require('./../../');
|
|
11
|
-
const {getUtxos} = require('./../../');
|
|
12
|
-
const {sendToChainAddress} = require('./../../');
|
|
13
|
-
const {subscribeToBlocks} = require('./../../');
|
|
14
|
-
const {subscribeToChainSpend} = require('./../../');
|
|
15
|
-
|
|
16
|
-
const confirmationCount = 6;
|
|
17
|
-
const count = 100;
|
|
18
|
-
const format = 'p2wpkh';
|
|
19
|
-
const interval = 1;
|
|
20
|
-
const race = promises => Promise.race(promises);
|
|
21
|
-
const size = 2;
|
|
22
|
-
const times = 1000;
|
|
23
|
-
const tokens = 1e6;
|
|
24
|
-
|
|
25
|
-
// Subscribing to chain spend should push events on spend confirmations
|
|
26
|
-
test(`Subscribe to chain spend`, async () => {
|
|
27
|
-
let gotAddressConf = false;
|
|
28
|
-
|
|
29
|
-
const {kill, nodes} = await spawnLightningCluster({size});
|
|
30
|
-
|
|
31
|
-
const [control, target] = nodes;
|
|
32
|
-
|
|
33
|
-
const cluster = {control, target};
|
|
34
|
-
|
|
35
|
-
const {address} = await createChainAddress({lnd: target.lnd});
|
|
36
|
-
const {lnd} = control;
|
|
37
|
-
|
|
38
|
-
// Wait for chainrpc to be active
|
|
39
|
-
await control.generate({count});
|
|
40
|
-
|
|
41
|
-
const startHeight = (await getHeight({lnd})).current_block_height;
|
|
42
|
-
|
|
43
|
-
await asyncRetry({interval, times}, async () => {
|
|
44
|
-
const subBlocks = subscribeToBlocks({lnd});
|
|
45
|
-
|
|
46
|
-
const [event] = await race([
|
|
47
|
-
once(subBlocks, 'block'),
|
|
48
|
-
once(subBlocks, 'error'),
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
if (!event.height) {
|
|
52
|
-
throw new Error('ExpectedBlockEvent');
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const sent = await asyncRetry({times}, async () => {
|
|
57
|
-
await control.generate({});
|
|
58
|
-
|
|
59
|
-
return await sendToChainAddress({address, lnd, tokens});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
await control.generate({count: 1});
|
|
63
|
-
|
|
64
|
-
const {utxos} = await getUtxos({lnd});
|
|
65
|
-
|
|
66
|
-
const [utxo] = utxos.filter(n => n.address_format === 'p2wpkh');
|
|
67
|
-
|
|
68
|
-
await control.generate({count});
|
|
69
|
-
|
|
70
|
-
const sub = subscribeToChainSpend({
|
|
71
|
-
lnd,
|
|
72
|
-
bech32_address: utxo.address,
|
|
73
|
-
min_height: startHeight,
|
|
74
|
-
transaction_id: utxo.transaction_id,
|
|
75
|
-
transaction_vout: utxo.transaction_vout,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
sub.on('error', err => {});
|
|
79
|
-
|
|
80
|
-
sub.once('confirmation', ({height, transaction, vin}) => {
|
|
81
|
-
strictEqual(!!height, true, 'Height of the confirmation is returned');
|
|
82
|
-
strictEqual(!!transaction, true, 'Raw transaction is returned');
|
|
83
|
-
strictEqual(vin !== undefined, true, 'Transaction input index returned');
|
|
84
|
-
|
|
85
|
-
return gotAddressConf = true;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const toTarget = await createChainAddress({lnd: target.lnd});
|
|
89
|
-
|
|
90
|
-
// Wait for generation to be over
|
|
91
|
-
await asyncRetry({interval, times}, async () => {
|
|
92
|
-
try {
|
|
93
|
-
await sendToChainAddress({
|
|
94
|
-
lnd,
|
|
95
|
-
address: toTarget.address,
|
|
96
|
-
is_send_all: true,
|
|
97
|
-
});
|
|
98
|
-
} catch (err) {
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Generate to confirm the tx
|
|
102
|
-
await control.generate({count: confirmationCount});
|
|
103
|
-
|
|
104
|
-
if (!gotAddressConf) {
|
|
105
|
-
throw new Error('ExpectedSubscribeToAddressSeesConfirmation');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
await kill({});
|
|
112
|
-
|
|
113
|
-
strictEqual(gotAddressConf, true, 'Subscribe to address sees confirmation');
|
|
114
|
-
|
|
115
|
-
return;
|
|
116
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
const {strictEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
|
|
4
|
-
const asyncRetry = require('async/retry');
|
|
5
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
6
|
-
|
|
7
|
-
const {addPeer} = require('./../../');
|
|
8
|
-
const {getPeers} = require('./../../');
|
|
9
|
-
|
|
10
|
-
const interval = 100;
|
|
11
|
-
const size = 2;
|
|
12
|
-
const times = 4000;
|
|
13
|
-
const timeout = 100;
|
|
14
|
-
|
|
15
|
-
// Adding peers should result in a connected peer
|
|
16
|
-
test(`Add a peer`, async () => {
|
|
17
|
-
const {kill, nodes} = await spawnLightningCluster({size});
|
|
18
|
-
|
|
19
|
-
const [{generate, lnd}, target] = nodes;
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const connectedKeys = (await getPeers({lnd})).peers.map(n => n.public_key);
|
|
23
|
-
|
|
24
|
-
strictEqual(
|
|
25
|
-
connectedKeys.find(n => n === target.id),
|
|
26
|
-
undefined,
|
|
27
|
-
'No peer'
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
await asyncRetry({interval, times}, async () => {
|
|
31
|
-
await generate({});
|
|
32
|
-
|
|
33
|
-
await addPeer({
|
|
34
|
-
lnd,
|
|
35
|
-
timeout,
|
|
36
|
-
public_key: target.id,
|
|
37
|
-
retry_count: 1,
|
|
38
|
-
retry_delay: 1,
|
|
39
|
-
socket: target.socket,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const {peers} = await getPeers({lnd});
|
|
43
|
-
|
|
44
|
-
const connected = peers.find(n => n.public_key === target.id);
|
|
45
|
-
|
|
46
|
-
if (!connected) {
|
|
47
|
-
throw new Error('ExpectedConnectionToTarget');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
strictEqual(connected.public_key, target.id, 'Connected to remote node');
|
|
51
|
-
});
|
|
52
|
-
} catch (err) {
|
|
53
|
-
strictEqual(err, null, 'Expected no error');
|
|
54
|
-
} finally {
|
|
55
|
-
await kill({});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return;
|
|
59
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const test = require('node:test');
|
|
2
|
-
|
|
3
|
-
const asyncEach = require('async/each');
|
|
4
|
-
const asyncRetry = require('async/retry');
|
|
5
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
6
|
-
|
|
7
|
-
const {addPeer} = require('./../../');
|
|
8
|
-
const {cancelPendingChannel} = require('./../../');
|
|
9
|
-
const {openChannels} = require('./../../');
|
|
10
|
-
|
|
11
|
-
const capacity = 1e6;
|
|
12
|
-
const count = 100;
|
|
13
|
-
const delay = n => new Promise(resolve => setTimeout(resolve, n));
|
|
14
|
-
const interval = 100;
|
|
15
|
-
const race = promises => Promise.race(promises);
|
|
16
|
-
const size = 2;
|
|
17
|
-
const timeout = 1000 * 5;
|
|
18
|
-
const times = 200;
|
|
19
|
-
|
|
20
|
-
// Cancel a channel should result in no pending channels
|
|
21
|
-
test(`Cancel pending channel`, async () => {
|
|
22
|
-
const {kill, nodes} = await spawnLightningCluster({size});
|
|
23
|
-
|
|
24
|
-
const [{generate, lnd}, target] = nodes;
|
|
25
|
-
|
|
26
|
-
await generate({count});
|
|
27
|
-
|
|
28
|
-
const channels = [{capacity, partner_public_key: target.id}];
|
|
29
|
-
|
|
30
|
-
await asyncRetry({interval, times}, async () => {
|
|
31
|
-
await addPeer({lnd, public_key: target.id, socket: target.socket});
|
|
32
|
-
|
|
33
|
-
const toCancel = await race([
|
|
34
|
-
delay(timeout),
|
|
35
|
-
openChannels({channels, lnd}),
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
|
-
const [{id}] = toCancel.pending;
|
|
39
|
-
|
|
40
|
-
await cancelPendingChannel({id, lnd});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
await kill({});
|
|
44
|
-
|
|
45
|
-
return;
|
|
46
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const {strictEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
|
|
4
|
-
const {setupChannel} = require('ln-docker-daemons');
|
|
5
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
6
|
-
|
|
7
|
-
const {closeChannel} = require('./../../');
|
|
8
|
-
|
|
9
|
-
const size = 2;
|
|
10
|
-
|
|
11
|
-
// Closing a channel should close the channel
|
|
12
|
-
test(`Close channel`, async () => {
|
|
13
|
-
const {kill, nodes} = await spawnLightningCluster({size});
|
|
14
|
-
|
|
15
|
-
const [control, target] = nodes;
|
|
16
|
-
|
|
17
|
-
// Force close channel using tx id and vout
|
|
18
|
-
try {
|
|
19
|
-
const channelOpen = await setupChannel({
|
|
20
|
-
generate: control.generate,
|
|
21
|
-
lnd: control.lnd,
|
|
22
|
-
to: target,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const channelClose = await closeChannel({
|
|
26
|
-
is_force_close: true,
|
|
27
|
-
lnd: control.lnd,
|
|
28
|
-
transaction_id: channelOpen.transaction_id,
|
|
29
|
-
transaction_vout: channelOpen.transaction_vout,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
strictEqual(channelClose.transaction_id.length, 64, 'Got force close id');
|
|
33
|
-
strictEqual(channelClose.transaction_vout, 0, 'Force close vout returned');
|
|
34
|
-
} catch (err) {
|
|
35
|
-
strictEqual(err, null, 'Expected no error force closing');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Coop close channel using the channel id
|
|
39
|
-
try {
|
|
40
|
-
const channelOpen = await setupChannel({
|
|
41
|
-
generate: control.generate,
|
|
42
|
-
lnd: control.lnd,
|
|
43
|
-
to: target,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const channelClose = await closeChannel({
|
|
47
|
-
id: channelOpen.id,
|
|
48
|
-
lnd: control.lnd,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
strictEqual(channelClose.transaction_id.length, 64, 'Got coop close id');
|
|
52
|
-
strictEqual(channelClose.transaction_vout, 0, 'Got coop close tx vout');
|
|
53
|
-
} catch (err) {
|
|
54
|
-
strictEqual(err, null, 'Expected no error coop closing');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
await kill({});
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
const {equal} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
|
|
4
|
-
const asyncAuto = require('async/auto');
|
|
5
|
-
const asyncRetry = require('async/retry');
|
|
6
|
-
const {cancelHodlInvoice} = require('./../../');
|
|
7
|
-
const {createHodlInvoice} = require('./../../');
|
|
8
|
-
const {getInvoice} = require('./../../');
|
|
9
|
-
const {getChannels} = require('./../../');
|
|
10
|
-
const {getClosedChannels} = require('./../../');
|
|
11
|
-
const {pay} = require('./../../');
|
|
12
|
-
const {setupChannel} = require('ln-docker-daemons');
|
|
13
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
14
|
-
|
|
15
|
-
const {closeChannel} = require('./../../');
|
|
16
|
-
|
|
17
|
-
const interval = 100;
|
|
18
|
-
const size = 2;
|
|
19
|
-
const times = 1000;
|
|
20
|
-
const tokens = 10;
|
|
21
|
-
|
|
22
|
-
// Closing a pending payments channel should close the channel after a wait
|
|
23
|
-
test(`Close channel with wait for pending`, async () => {
|
|
24
|
-
const {kill, nodes} = await spawnLightningCluster({size});
|
|
25
|
-
|
|
26
|
-
const [control, target] = nodes;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
// Open a channel from control to target
|
|
30
|
-
const channelOpen = await setupChannel({
|
|
31
|
-
generate: control.generate,
|
|
32
|
-
lnd: control.lnd,
|
|
33
|
-
to: target,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Create a hold invoice to create the pending state
|
|
37
|
-
const invoice = await createHodlInvoice({tokens, lnd: target.lnd});
|
|
38
|
-
|
|
39
|
-
await asyncAuto({
|
|
40
|
-
makePayment: async () => {
|
|
41
|
-
// Pay to the hold invoice
|
|
42
|
-
try {
|
|
43
|
-
await pay({lnd: control.lnd, request: invoice.request});
|
|
44
|
-
} catch (err) {
|
|
45
|
-
const [, type] = err;
|
|
46
|
-
|
|
47
|
-
// We expect that it would be canceled back
|
|
48
|
-
equal(type, 'PaymentRejectedByDestination');
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
// Wait for the payment to be held
|
|
53
|
-
lookForPayment: async () => {
|
|
54
|
-
await asyncRetry({interval, times}, async () => {
|
|
55
|
-
const received = await getInvoice({id: invoice.id, lnd: target.lnd});
|
|
56
|
-
|
|
57
|
-
if (!received.is_held) {
|
|
58
|
-
throw new Error('ExpectedPaymentHeld');
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
// Start the closing process
|
|
64
|
-
closeChannel: ['lookForPayment', async () => {
|
|
65
|
-
try {
|
|
66
|
-
await closeChannel({
|
|
67
|
-
id: channelOpen.id,
|
|
68
|
-
is_graceful_close: true,
|
|
69
|
-
lnd: control.lnd,
|
|
70
|
-
});
|
|
71
|
-
} catch (err) {
|
|
72
|
-
const [,, error] = err;
|
|
73
|
-
|
|
74
|
-
const {details} = error.err;
|
|
75
|
-
|
|
76
|
-
// LND 0.17.5 and below do not support graceful closes
|
|
77
|
-
if (details === 'cannot co-op close channel with active htlcs') {
|
|
78
|
-
throw new Error('FeatureUnsupported');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
}],
|
|
84
|
-
|
|
85
|
-
// Wait for channel to be in closing mode
|
|
86
|
-
confirmClosing: ['lookForPayment', async () => {
|
|
87
|
-
await asyncRetry({interval, times}, async () => {
|
|
88
|
-
const {channels} = await getChannels({lnd: control.lnd});
|
|
89
|
-
|
|
90
|
-
if (!channels.filter(n => !n.is_active).length) {
|
|
91
|
-
throw new Error('ExpectedInactiveChannels');
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}],
|
|
95
|
-
|
|
96
|
-
// Stop the payment to void the pending state
|
|
97
|
-
cancelPayment: ['confirmClosing', async () => {
|
|
98
|
-
await cancelHodlInvoice({id: invoice.id, lnd: target.lnd});
|
|
99
|
-
}],
|
|
100
|
-
|
|
101
|
-
// Confirm that the channel closed cleanly
|
|
102
|
-
confirmClosed: ['cancelPayment', async () => {
|
|
103
|
-
await asyncRetry({interval, times}, async () => {
|
|
104
|
-
const {channels} = await getClosedChannels({lnd: control.lnd});
|
|
105
|
-
|
|
106
|
-
await control.generate({});
|
|
107
|
-
|
|
108
|
-
if (!channels.filter(n => !!n.is_cooperative_close).length) {
|
|
109
|
-
throw new Error('ExpectedCooperativelyClosedChannels');
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}],
|
|
113
|
-
});
|
|
114
|
-
} catch (err) {
|
|
115
|
-
equal(err.message, 'FeatureUnsupported', 'Expected no error');
|
|
116
|
-
} finally {
|
|
117
|
-
await kill({});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return;
|
|
121
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const {equal} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
|
|
4
|
-
const {decodeBase58Address} = require('@alexbosworth/blockchain');
|
|
5
|
-
const {decodeBech32Address} = require('@alexbosworth/blockchain');
|
|
6
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
7
|
-
|
|
8
|
-
const {createChainAddress} = require('./../../');
|
|
9
|
-
|
|
10
|
-
const formats = ['np2wpkh', 'p2wpkh'];
|
|
11
|
-
const p2shAddressVersion = 196;
|
|
12
|
-
const p2trProgramLength = 32;
|
|
13
|
-
const p2trVersion = 1;
|
|
14
|
-
const pkHashByteLength = 20;
|
|
15
|
-
const prefixForV1 = 'bcrt1p';
|
|
16
|
-
const regtestBech32AddressHrp = 'bcrt';
|
|
17
|
-
|
|
18
|
-
// Creating addresses should result in addresses
|
|
19
|
-
test(`Create address results in address creation`, async () => {
|
|
20
|
-
const [{kill, lnd}] = (await spawnLightningCluster({})).nodes;
|
|
21
|
-
|
|
22
|
-
const createNewChainAddresses = formats
|
|
23
|
-
.map(async format => await createChainAddress({lnd, format}));
|
|
24
|
-
|
|
25
|
-
const [np2wpkh, p2wpkh] = await Promise.all(createNewChainAddresses);
|
|
26
|
-
|
|
27
|
-
const nativeAddress = decodeBech32Address({address: p2wpkh.address});
|
|
28
|
-
const nestedAddress = decodeBase58Address({address: np2wpkh.address});
|
|
29
|
-
|
|
30
|
-
equal(nativeAddress.program.length, pkHashByteLength, 'Native addr pkHash');
|
|
31
|
-
equal(nativeAddress.prefix, regtestBech32AddressHrp, 'Native addr prefix');
|
|
32
|
-
equal(nestedAddress.version, p2shAddressVersion, 'Nested address version');
|
|
33
|
-
|
|
34
|
-
const getUnused = formats.map(async format => {
|
|
35
|
-
return await createChainAddress({lnd, format, is_unused: true});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const [unusedNp2wpkh, unusedP2wpkh] = await Promise.all(getUnused);
|
|
39
|
-
|
|
40
|
-
equal(np2wpkh.address, unusedNp2wpkh.address, 'Nested is reused');
|
|
41
|
-
equal(p2wpkh.address, unusedP2wpkh.address, 'Native is reused');
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const {address} = await createChainAddress({lnd, format: 'p2tr'});
|
|
45
|
-
|
|
46
|
-
equal(address.startsWith(prefixForV1), true, 'A taproot address is made');
|
|
47
|
-
|
|
48
|
-
const p2trAddress = decodeBech32Address({address});
|
|
49
|
-
|
|
50
|
-
equal(p2trAddress.prefix, regtestBech32AddressHrp, 'addr has p2tr prefix');
|
|
51
|
-
equal(p2trAddress.program.length, p2trProgramLength, 'P2TR addr length');
|
|
52
|
-
equal(p2trAddress.version, p2trVersion, 'address has the P2TR version');
|
|
53
|
-
} catch (err) {
|
|
54
|
-
// LND 0.14.5 and below do not support TR addresses
|
|
55
|
-
const [code] = err;
|
|
56
|
-
|
|
57
|
-
equal(code, 501, 'Taproot addresses are unsupported');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
await kill({});
|
|
61
|
-
|
|
62
|
-
return;
|
|
63
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const {strictEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
|
|
4
|
-
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
5
|
-
|
|
6
|
-
const {createInvoice} = require('./../../');
|
|
7
|
-
const {parsePaymentRequest} = require('./../../');
|
|
8
|
-
|
|
9
|
-
const count = 100;
|
|
10
|
-
|
|
11
|
-
// createInvoice should result in a created invoice
|
|
12
|
-
test(`Create an invoice`, async () => {
|
|
13
|
-
const [{generate, kill, lnd}] = (await spawnLightningCluster({})).nodes;
|
|
14
|
-
|
|
15
|
-
await generate({count});
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
const invoice = await createInvoice({lnd});
|
|
19
|
-
|
|
20
|
-
const parsed = parsePaymentRequest({request: invoice.request});
|
|
21
|
-
|
|
22
|
-
strictEqual(invoice.chain_address, undefined, 'Address is undefined');
|
|
23
|
-
strictEqual(invoice.created_at, parsed.created_at, 'Invoice created date');
|
|
24
|
-
strictEqual(invoice.description, undefined, 'Description undefined');
|
|
25
|
-
strictEqual(invoice.id, parsed.id, 'Invoice has id');
|
|
26
|
-
strictEqual(invoice.mtokens, '0', 'Default mtokens are 0');
|
|
27
|
-
strictEqual(!!invoice.request, true, 'Invoice has request');
|
|
28
|
-
strictEqual(!!invoice.secret, true, 'Invoice returns secret');
|
|
29
|
-
strictEqual(invoice.tokens, 0, 'Default tokens are 0');
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const duplicate = await createInvoice({lnd, secret: invoice.secret});
|
|
33
|
-
|
|
34
|
-
equal(duplicate, null, 'Expected no duplicate invoice');
|
|
35
|
-
} catch (err) {
|
|
36
|
-
const [code, message] = err;
|
|
37
|
-
|
|
38
|
-
strictEqual(code, 409, 'Got expected error code');
|
|
39
|
-
strictEqual(message, 'InvoiceWithGivenHashAlreadyExists', 'Got msg');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
} catch (err) {
|
|
43
|
-
strictEqual(err, null, 'Expected no error in create invoice');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
await kill({});
|
|
47
|
-
|
|
48
|
-
return;
|
|
49
|
-
});
|