ln-service 53.7.2 → 53.9.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 +9 -1
- package/README.md +129 -0
- package/index.js +4 -0
- package/package.json +7 -5
- package/test/integration/test_add_peer.js +2 -2
- package/test/integration/test_get_closed_channels.js +0 -2
- package/test/integration/test_get_invoice.js +0 -1
- package/test/integration/test_get_node.js +13 -1
- package/test/integration/test_get_peers.js +32 -21
- package/test/integration/test_get_pending_payments.js +87 -0
- package/test/integration/test_get_wallet_info.js +6 -4
- package/test/integration/test_open_channels.js +2 -2
- package/test/integration/test_pay.js +0 -1
- package/test/integration/test_pay_private_invoice.js +0 -1
- package/test/integration/test_remove_peer.js +13 -9
- package/test/integration/test_send_message_to_peer.js +39 -28
- package/test/integration/test_send_to_chain_address.js +4 -0
- package/test/integration/test_subscribe_to_channels.js +0 -1
- package/test/integration/test_subscribe_to_invoices.js +80 -78
- package/test/integration/test_subscribe_to_peer_messages.js +6 -4
- package/test/invoicesrpc-integration/test_get_sweep_transactions.js +0 -2
- package/test/invoicesrpc-integration/test_subscribe_cancel_invoice.js +0 -1
- package/test/macros/wait_for_channel.js +1 -1
- package/test/routerrpc-integration/test_delete_forwarding_reputations.js +61 -27
- package/test/routerrpc-integration/test_get_forwarding_reputations.js +42 -14
- package/test/routerrpc-integration/test_get_route_through_hops.js +24 -15
- package/test/routerrpc-integration/test_multipath_payment.js +0 -1
- package/test/routerrpc-integration/test_pay_via_payment_details.js +0 -1
- package/test/routerrpc-integration/test_pay_via_payment_request.js +92 -80
- package/test/routerrpc-integration/test_probe_for_route.js +5 -5
- package/test/routerrpc-integration/test_subscribe_to_forward_requests.js +0 -1
- package/test/routerrpc-integration/test_subscribe_to_forwards.js +11 -2
- package/test/routerrpc-integration/test_subscribe_to_past_payments.js +0 -3
- package/test/tower_clientrpc-integration/test_get_connected_watchtowers.js +0 -3
- package/test/walletrpc-integration/test_fund_psbt.js +110 -1
- package/test/walletrpc-integration/test_get_master_public_keys.js +79 -0
- package/test/walletrpc-integration/test_partially_sign_psbt.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
-
## 53.
|
|
3
|
+
## 53.8.1
|
|
4
|
+
|
|
5
|
+
- `fundPsbt`: Fix bip32 key derivation error
|
|
6
|
+
|
|
7
|
+
## 53.8.0
|
|
8
|
+
|
|
9
|
+
- `getMasterPublicKeys`: Add method to get bip32 master public keys
|
|
10
|
+
|
|
11
|
+
## 53.7.3
|
|
4
12
|
|
|
5
13
|
- `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
|
|
6
14
|
|
package/README.md
CHANGED
|
@@ -157,6 +157,7 @@ for `unlocker` methods.
|
|
|
157
157
|
- [getInvoice](#getinvoice) - Get a previously created invoice
|
|
158
158
|
- [getInvoices](#getinvoices) - Get all previously created invoices
|
|
159
159
|
- [getLockedUtxos](#getlockedutxos) - Get all previously locked UTXOs
|
|
160
|
+
- [getMasterPublicKeys](#getmasterpublickeys) - Get a list of master pub keys
|
|
160
161
|
- [getMethods](#getmethods) - Get available methods and associated permissions
|
|
161
162
|
- [getNetworkCentrality](#getnetworkcentrality) - Get centrality score for nodes
|
|
162
163
|
- [getNetworkGraph](#getnetworkgraph) - Get the channels and nodes of the graph
|
|
@@ -169,6 +170,7 @@ for `unlocker` methods.
|
|
|
169
170
|
- [getPeers](#getpeers) - Get all connected peers
|
|
170
171
|
- [getPendingChainBalance](#getpendingchainbalance) - Get pending chain balance
|
|
171
172
|
- [getPendingChannels](#getpendingchannels) - Get channels in pending states
|
|
173
|
+
- [getPendingPayments](#getpendingpayments) - Get in-flight outgoing payments
|
|
172
174
|
- [getPublicKey](#getpublickey) - Get a public key out of the seed
|
|
173
175
|
- [getRouteConfidence](#getrouteconfidence) - Get confidence in a route
|
|
174
176
|
- [getRouteThroughHops](#getroutethroughhops) - Get a route through nodes
|
|
@@ -2102,6 +2104,41 @@ const {getLockedUtxos} = require('ln-service');
|
|
|
2102
2104
|
const numLockedUtxos = (await getLockedUtxos({lnd})).utxos.length;
|
|
2103
2105
|
```
|
|
2104
2106
|
|
|
2107
|
+
### getMasterPublicKeys
|
|
2108
|
+
|
|
2109
|
+
Get the currently tracked master public keys
|
|
2110
|
+
|
|
2111
|
+
Requires LND compiled with `walletrpc` build tag
|
|
2112
|
+
|
|
2113
|
+
Requires `onchain:read` permission
|
|
2114
|
+
|
|
2115
|
+
This method is not supported in LND 0.13.3 and below
|
|
2116
|
+
|
|
2117
|
+
{
|
|
2118
|
+
lnd: <Authenticated API LND Object>
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
@returns via cbk or Promise
|
|
2122
|
+
{
|
|
2123
|
+
keys: [{
|
|
2124
|
+
derivation_path: <Key Derivation Path String>
|
|
2125
|
+
extended_public_key: <Base58 Encoded Master Public Key String>
|
|
2126
|
+
external_key_count: <Used External Keys Count Number>
|
|
2127
|
+
internal_key_count: <Used Internal Keys Count Number>
|
|
2128
|
+
is_watch_only: <Node has Master Private Key Bool>
|
|
2129
|
+
named: <Account Name String>
|
|
2130
|
+
}]
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
```node
|
|
2134
|
+
const {getMasterPublicKeys} = require('ln-service');
|
|
2135
|
+
|
|
2136
|
+
const {keys} = await getMasterPublicKeys({lnd});
|
|
2137
|
+
|
|
2138
|
+
// Find the master public key that derives pay to witness public key hash keys
|
|
2139
|
+
const masterAddressesKey = keys.find(n => n.derivation_path === `m/84'/0'/0'`);
|
|
2140
|
+
```
|
|
2141
|
+
|
|
2105
2142
|
### getMethods
|
|
2106
2143
|
|
|
2107
2144
|
Get the list of all methods and their associated requisite permissions
|
|
@@ -2626,6 +2663,98 @@ const {getPendingChannels} = require('ln-service');
|
|
|
2626
2663
|
const pendingChannels = (await getPendingChannels({lnd})).pending_channels;
|
|
2627
2664
|
```
|
|
2628
2665
|
|
|
2666
|
+
### getPendingPayments
|
|
2667
|
+
|
|
2668
|
+
Get pending payments made through channels.
|
|
2669
|
+
|
|
2670
|
+
Requires `offchain:read` permission
|
|
2671
|
+
|
|
2672
|
+
{
|
|
2673
|
+
[limit]: <Page Result Limit Number>
|
|
2674
|
+
lnd: <Authenticated LND API Object>
|
|
2675
|
+
[token]: <Opaque Paging Token String>
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
@returns via cbk or Promise
|
|
2679
|
+
{
|
|
2680
|
+
payments: [{
|
|
2681
|
+
attempts: [{
|
|
2682
|
+
[failure]: {
|
|
2683
|
+
code: <Error Type Code Number>
|
|
2684
|
+
[details]: {
|
|
2685
|
+
[channel]: <Standard Format Channel Id String>
|
|
2686
|
+
[height]: <Error Associated Block Height Number>
|
|
2687
|
+
[index]: <Failed Hop Index Number>
|
|
2688
|
+
[mtokens]: <Error Millitokens String>
|
|
2689
|
+
[policy]: {
|
|
2690
|
+
base_fee_mtokens: <Base Fee Millitokens String>
|
|
2691
|
+
cltv_delta: <Locktime Delta Number>
|
|
2692
|
+
fee_rate: <Fees Charged in Millitokens Per Million Number>
|
|
2693
|
+
[is_disabled]: <Channel is Disabled Bool>
|
|
2694
|
+
max_htlc_mtokens: <Maximum HLTC Millitokens Value String>
|
|
2695
|
+
min_htlc_mtokens: <Minimum HTLC Millitokens Value String>
|
|
2696
|
+
updated_at: <Updated At ISO 8601 Date String>
|
|
2697
|
+
}
|
|
2698
|
+
[timeout_height]: <Error CLTV Timeout Height Number>
|
|
2699
|
+
[update]: {
|
|
2700
|
+
chain: <Chain Id Hex String>
|
|
2701
|
+
channel_flags: <Channel Flags Number>
|
|
2702
|
+
extra_opaque_data: <Extra Opaque Data Hex String>
|
|
2703
|
+
message_flags: <Message Flags Number>
|
|
2704
|
+
signature: <Channel Update Signature Hex String>
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
message: <Error Message String>
|
|
2708
|
+
}
|
|
2709
|
+
[index]: <Payment Add Index Number>
|
|
2710
|
+
[confirmed_at]: <Payment Confirmed At ISO 8601 Date String>
|
|
2711
|
+
is_confirmed: <Payment Attempt Succeeded Bool>
|
|
2712
|
+
is_failed: <Payment Attempt Failed Bool>
|
|
2713
|
+
is_pending: <Payment Attempt is Waiting For Resolution Bool>
|
|
2714
|
+
route: {
|
|
2715
|
+
fee: <Route Fee Tokens Number>
|
|
2716
|
+
fee_mtokens: <Route Fee Millitokens String>
|
|
2717
|
+
hops: [{
|
|
2718
|
+
channel: <Standard Format Channel Id String>
|
|
2719
|
+
channel_capacity: <Channel Capacity Tokens Number>
|
|
2720
|
+
fee: <Fee Number>
|
|
2721
|
+
fee_mtokens: <Fee Millitokens String>
|
|
2722
|
+
forward: <Forward Tokens Number>
|
|
2723
|
+
forward_mtokens: <Forward Millitokens String>
|
|
2724
|
+
[public_key]: <Forward Edge Public Key Hex String>
|
|
2725
|
+
[timeout]: <Timeout Block Height Number>
|
|
2726
|
+
}]
|
|
2727
|
+
mtokens: <Total Fee-Inclusive Millitokens String>
|
|
2728
|
+
[payment]: <Payment Identifier Hex String>
|
|
2729
|
+
timeout: <Timeout Block Height Number>
|
|
2730
|
+
tokens: <Total Fee-Inclusive Tokens Number>
|
|
2731
|
+
[total_mtokens]: <Total Millitokens String>
|
|
2732
|
+
}
|
|
2733
|
+
}]
|
|
2734
|
+
created_at: <Payment at ISO-8601 Date String>
|
|
2735
|
+
[destination]: <Destination Node Public Key Hex String>
|
|
2736
|
+
id: <Payment Preimage Hash String>
|
|
2737
|
+
[index]: <Payment Add Index Number>
|
|
2738
|
+
is_confirmed: <Payment is Confirmed Bool>
|
|
2739
|
+
is_outgoing: <Transaction Is Outgoing Bool>
|
|
2740
|
+
mtokens: <Millitokens Attempted to Pay to Destination String>
|
|
2741
|
+
[request]: <BOLT 11 Payment Request String>
|
|
2742
|
+
safe_tokens: <Payment Tokens Attempted to Pay Rounded Up Number>
|
|
2743
|
+
tokens: <Rounded Down Tokens Attempted to Pay to Destination Number>
|
|
2744
|
+
}]
|
|
2745
|
+
[next]: <Next Opaque Paging Token String>
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
```node
|
|
2749
|
+
const {getPendingPayments} = require('ln-service')
|
|
2750
|
+
|
|
2751
|
+
const {next, payments} = await getPendingPayments({lnd});
|
|
2752
|
+
|
|
2753
|
+
if (!next) {
|
|
2754
|
+
const inFlightPaymentsCount = payments.length;
|
|
2755
|
+
}
|
|
2756
|
+
```
|
|
2757
|
+
|
|
2629
2758
|
### getPublicKey
|
|
2630
2759
|
|
|
2631
2760
|
Get a public key in the seed
|
package/index.js
CHANGED
|
@@ -49,6 +49,7 @@ const {getIdentity} = require('lightning');
|
|
|
49
49
|
const {getInvoice} = require('lightning');
|
|
50
50
|
const {getInvoices} = require('lightning');
|
|
51
51
|
const {getLockedUtxos} = require('lightning');
|
|
52
|
+
const {getMasterPublicKeys} = require('lightning');
|
|
52
53
|
const {getMethods} = require('lightning');
|
|
53
54
|
const {getNetworkCentrality} = require('lightning');
|
|
54
55
|
const {getNetworkGraph} = require('lightning');
|
|
@@ -60,6 +61,7 @@ const {getPayments} = require('lightning');
|
|
|
60
61
|
const {getPeers} = require('lightning');
|
|
61
62
|
const {getPendingChainBalance} = require('lightning');
|
|
62
63
|
const {getPendingChannels} = require('lightning');
|
|
64
|
+
const {getPendingPayments} = require('lightning');
|
|
63
65
|
const {getPublicKey} = require('lightning');
|
|
64
66
|
const {getRouteConfidence} = require('lightning');
|
|
65
67
|
const {getRouteThroughHops} = require('lightning');
|
|
@@ -189,6 +191,7 @@ module.exports = {
|
|
|
189
191
|
getInvoice,
|
|
190
192
|
getInvoices,
|
|
191
193
|
getLockedUtxos,
|
|
194
|
+
getMasterPublicKeys,
|
|
192
195
|
getMethods,
|
|
193
196
|
getNetworkCentrality,
|
|
194
197
|
getNetworkGraph,
|
|
@@ -200,6 +203,7 @@ module.exports = {
|
|
|
200
203
|
getPeers,
|
|
201
204
|
getPendingChainBalance,
|
|
202
205
|
getPendingChannels,
|
|
206
|
+
getPendingPayments,
|
|
203
207
|
getPublicKey,
|
|
204
208
|
getRouteConfidence,
|
|
205
209
|
getRouteThroughHops,
|
package/package.json
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"bolt07": "1.8.0",
|
|
11
11
|
"cors": "2.8.5",
|
|
12
12
|
"express": "4.17.2",
|
|
13
|
-
"invoices": "2.0.
|
|
14
|
-
"lightning": "5.
|
|
13
|
+
"invoices": "2.0.4",
|
|
14
|
+
"lightning": "5.8.0",
|
|
15
15
|
"macaroon": "3.0.4",
|
|
16
16
|
"morgan": "1.10.0",
|
|
17
|
-
"ws": "8.
|
|
17
|
+
"ws": "8.5.0"
|
|
18
18
|
},
|
|
19
19
|
"description": "Interaction helper for your Lightning Network daemon",
|
|
20
20
|
"devDependencies": {
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"@alexbosworth/node-fetch": "2.6.2",
|
|
23
23
|
"async": "3.2.3",
|
|
24
24
|
"asyncjs-util": "1.2.8",
|
|
25
|
+
"bip32": "3.0.1",
|
|
25
26
|
"bip66": "1.1.5",
|
|
26
27
|
"bitcoinjs-lib": "6.0.1",
|
|
27
28
|
"bn.js": "5.2.0",
|
|
29
|
+
"bs58check": "2.1.2",
|
|
28
30
|
"ecpair": "2.0.1",
|
|
29
31
|
"ln-docker-daemons": "2.2.4",
|
|
30
32
|
"portfinder": "1.0.28",
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
"integration-test-0.13.0": "DOCKER_LND_VERSION=v0.13.0-beta npm run test",
|
|
65
67
|
"integration-test-0.12.1": "DOCKER_LND_VERSION=v0.12.1-beta npm run test",
|
|
66
68
|
"integration-test-0.12.0": "DOCKER_LND_VERSION=v0.12.0-beta npm run test",
|
|
67
|
-
"test": "echo $DOCKER_LND_VERSION && tap -j
|
|
69
|
+
"test": "echo $DOCKER_LND_VERSION && tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 200 test/autopilotrpc-integration/*.js test/chainrpc-integration/*.js test/integration/*.js test/invoicesrpc-integration/*.js test/routerrpc-integration/*.js test/signerrpc-integration/*.js test/tower_clientrpc-integration/*.js test/tower_serverrpc-integration/*.js test/walletrpc-integration/*.js"
|
|
68
70
|
},
|
|
69
|
-
"version": "53.
|
|
71
|
+
"version": "53.9.0"
|
|
70
72
|
}
|
|
@@ -8,8 +8,8 @@ const {getPeers} = require('./../../');
|
|
|
8
8
|
|
|
9
9
|
const interval = 100;
|
|
10
10
|
const size = 2;
|
|
11
|
-
const times =
|
|
12
|
-
const timeout =
|
|
11
|
+
const times = 2000;
|
|
12
|
+
const timeout = 100;
|
|
13
13
|
|
|
14
14
|
// Adding peers should result in a connected peer
|
|
15
15
|
test(`Add a peer`, async ({end, equal}) => {
|
|
@@ -9,9 +9,7 @@ const {createHodlInvoice} = require('./../../');
|
|
|
9
9
|
const {delay} = require('./../macros');
|
|
10
10
|
const {payViaPaymentRequest} = require('./../../');
|
|
11
11
|
const {getChainTransactions} = require('./../../');
|
|
12
|
-
const {getChannels} = require('./../../');
|
|
13
12
|
const {getClosedChannels} = require('./../../');
|
|
14
|
-
const {getHeight} = require('./../../');
|
|
15
13
|
const {getPendingChannels} = require('./../../');
|
|
16
14
|
const {getSweepTransactions} = require('./../../');
|
|
17
15
|
const {getUtxos} = require('./../../');
|
|
@@ -2,7 +2,6 @@ const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
|
2
2
|
const {test} = require('@alexbosworth/tap');
|
|
3
3
|
|
|
4
4
|
const {createInvoice} = require('./../../');
|
|
5
|
-
const {getHeight} = require('./../../');
|
|
6
5
|
const {getInvoice} = require('./../../');
|
|
7
6
|
const {pay} = require('./../../');
|
|
8
7
|
const {setupChannel} = require('./../macros');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const asyncRetry = require('async/retry');
|
|
1
2
|
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
2
3
|
const {test} = require('@alexbosworth/tap');
|
|
3
4
|
|
|
@@ -15,8 +16,10 @@ const confirmationCount = 20;
|
|
|
15
16
|
const defaultFee = 1e3;
|
|
16
17
|
const defaultAliasLength = '00000000000000000000'.length;
|
|
17
18
|
const feeRate = 21;
|
|
19
|
+
const interval = 10;
|
|
18
20
|
const mtokPerTok = BigInt(1e3);
|
|
19
21
|
const size = 3;
|
|
22
|
+
const times = 1000;
|
|
20
23
|
|
|
21
24
|
// Getting a node should return the public graph node info
|
|
22
25
|
test(`Get node`, async ({end, equal, strictSame}) => {
|
|
@@ -42,7 +45,16 @@ test(`Get node`, async ({end, equal, strictSame}) => {
|
|
|
42
45
|
transaction_vout: controlToTarget.transaction_vout,
|
|
43
46
|
});
|
|
44
47
|
|
|
45
|
-
await
|
|
48
|
+
await asyncRetry({interval, times}, async () => {
|
|
49
|
+
await addPeer({
|
|
50
|
+
lnd,
|
|
51
|
+
public_key: remote.id,
|
|
52
|
+
retry_count: 1,
|
|
53
|
+
retry_delay: 1,
|
|
54
|
+
socket: remote.socket,
|
|
55
|
+
timeout: 1000,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
46
58
|
|
|
47
59
|
await delay(3000);
|
|
48
60
|
|
|
@@ -15,27 +15,38 @@ test('Get peers', async ({end, equal}) => {
|
|
|
15
15
|
|
|
16
16
|
const [{lnd}, target] = nodes;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
await
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
try {
|
|
19
|
+
await asyncRetry({interval, times}, async () => {
|
|
20
|
+
await addPeer({
|
|
21
|
+
lnd,
|
|
22
|
+
public_key: target.id,
|
|
23
|
+
retry_count: 1,
|
|
24
|
+
retry_delay: 1,
|
|
25
|
+
socket: target.socket,
|
|
26
|
+
timeout: 100,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const [peer] = (await getPeers({lnd})).peers;
|
|
30
|
+
|
|
31
|
+
if (!peer || !peer.is_sync_peer) {
|
|
32
|
+
throw new Error('ExpectedSyncPeer');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
equal(peer.bytes_received !== undefined, true, 'Bytes received');
|
|
36
|
+
equal(peer.bytes_sent !== undefined, true, 'Bytes sent');
|
|
37
|
+
equal(peer.is_inbound, false, 'Is inbound peer');
|
|
38
|
+
equal(peer.is_sync_peer, true, 'Is sync peer');
|
|
39
|
+
equal(peer.ping_time, 0, 'Ping time');
|
|
40
|
+
equal(peer.public_key, target.id, 'Public key');
|
|
41
|
+
equal(!!peer.socket, true, 'Socket');
|
|
42
|
+
equal(peer.tokens_received, 0, 'Tokens received');
|
|
43
|
+
equal(peer.tokens_sent, 0, 'Tokens sent');
|
|
44
|
+
|
|
45
|
+
return;
|
|
46
|
+
});
|
|
47
|
+
} catch (err) {
|
|
48
|
+
equal(err, null, 'Expected no error');
|
|
49
|
+
}
|
|
39
50
|
|
|
40
51
|
await kill({});
|
|
41
52
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const {once} = require('events');
|
|
2
|
+
|
|
3
|
+
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
4
|
+
const {test} = require('@alexbosworth/tap');
|
|
5
|
+
|
|
6
|
+
const {addPeer} = require('./../../');
|
|
7
|
+
const {createCluster} = require('./../macros');
|
|
8
|
+
const {createInvoice} = require('./../../');
|
|
9
|
+
const {deleteForwardingReputations} = require('./../../');
|
|
10
|
+
const {getHeight} = require('./../../');
|
|
11
|
+
const {getInvoice} = require('./../../');
|
|
12
|
+
const {getPayment} = require('./../../');
|
|
13
|
+
const {getPendingPayments} = require('./../../');
|
|
14
|
+
const {payViaPaymentRequest} = require('./../../');
|
|
15
|
+
const {subscribeToForwardRequests} = require('./../../');
|
|
16
|
+
const {subscribeToPayViaRequest} = require('./../../');
|
|
17
|
+
const {setupChannel} = require('./../macros');
|
|
18
|
+
const {waitForRoute} = require('./../macros');
|
|
19
|
+
|
|
20
|
+
const size = 3;
|
|
21
|
+
const tokens = 100;
|
|
22
|
+
|
|
23
|
+
// Getting pending payments should list out payments in flight
|
|
24
|
+
test(`Get pending payments`, async ({end, equal, rejects, strictSame}) => {
|
|
25
|
+
const {kill, nodes} = await spawnLightningCluster({size});
|
|
26
|
+
|
|
27
|
+
const [{generate, lnd}, target, remote] = nodes;
|
|
28
|
+
|
|
29
|
+
const channel = await setupChannel({generate, lnd, to: target});
|
|
30
|
+
|
|
31
|
+
await remote.generate({count: 100});
|
|
32
|
+
|
|
33
|
+
const remoteChan = await setupChannel({
|
|
34
|
+
lnd: target.lnd,
|
|
35
|
+
generate: target.generate,
|
|
36
|
+
to: remote,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await addPeer({lnd, public_key: remote.id, socket: remote.socket});
|
|
40
|
+
|
|
41
|
+
const {routes} = await waitForRoute({lnd, tokens, destination: remote.id});
|
|
42
|
+
|
|
43
|
+
let height;
|
|
44
|
+
const [route] = routes;
|
|
45
|
+
|
|
46
|
+
{
|
|
47
|
+
const invoice = await createInvoice({tokens, lnd: remote.lnd});
|
|
48
|
+
|
|
49
|
+
const sub = subscribeToForwardRequests({lnd: target.lnd});
|
|
50
|
+
|
|
51
|
+
sub.once('forward_request', async forward => {
|
|
52
|
+
const {pending} = await getPayment({lnd, id: invoice.id});
|
|
53
|
+
|
|
54
|
+
const {next, payments} = await getPendingPayments({lnd});
|
|
55
|
+
|
|
56
|
+
strictSame(next, undefined, 'No more pages');
|
|
57
|
+
strictSame(payments.length, 1, 'A single pending payment');
|
|
58
|
+
|
|
59
|
+
const [payment] = payments;
|
|
60
|
+
|
|
61
|
+
strictSame(payment.destination, remote.id, 'Paying to remote');
|
|
62
|
+
strictSame(payment.index, 1, 'First payment');
|
|
63
|
+
strictSame(payment.request, invoice.request, 'Paying invoice request');
|
|
64
|
+
strictSame(payment.confirmed_at, undefined, 'Not a confirmed payment');
|
|
65
|
+
strictSame(!!payment.created_at, true, 'Has created date');
|
|
66
|
+
strictSame(payment.fee, undefined, 'No fee yet');
|
|
67
|
+
strictSame(payment.fee_mtokens, undefined, 'No fee mtokens');
|
|
68
|
+
strictSame(payment.hops.length, 1, 'Going through hops');
|
|
69
|
+
strictSame(payment.id, invoice.id, 'Paying to the same hash');
|
|
70
|
+
strictSame(payment.is_confirmed, false, 'Payment is pending');
|
|
71
|
+
strictSame(payment.is_outgoing, true, 'Outgoing payment type');
|
|
72
|
+
strictSame(payment.mtokens, invoice.mtokens, 'Paying invoiced mtokens');
|
|
73
|
+
strictSame(payment.safe_fee, undefined, 'No fee paid yet');
|
|
74
|
+
strictSame(payment.safe_tokens, invoice.tokens, 'Paying safe tokens');
|
|
75
|
+
strictSame(payment.secret, undefined, 'Preimage not yet known');
|
|
76
|
+
strictSame(payment.tokens, invoice.tokens, 'Paying invoiced tokens');
|
|
77
|
+
|
|
78
|
+
return forward.accept();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await payViaPaymentRequest({lnd, request: invoice.request});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await kill({});
|
|
85
|
+
|
|
86
|
+
return end();
|
|
87
|
+
});
|
|
@@ -12,16 +12,18 @@ const times = 1000;
|
|
|
12
12
|
const walletInfoType = 'wallet';
|
|
13
13
|
|
|
14
14
|
// Getting the wallet info should return info about the wallet
|
|
15
|
-
test(`Get wallet info`, async ({end, equal, strictSame}) => {
|
|
15
|
+
test(`Get wallet info`, async ({end, equal, ok, strictSame}) => {
|
|
16
16
|
const {kill, nodes} = await spawnLightningCluster({});
|
|
17
17
|
|
|
18
|
-
const [{lnd}] = nodes;
|
|
18
|
+
const [{generate, lnd}] = nodes;
|
|
19
19
|
|
|
20
20
|
try {
|
|
21
21
|
const result = await asyncRetry({interval, times}, async () => {
|
|
22
|
+
await generate({});
|
|
23
|
+
|
|
22
24
|
const result = await getWalletInfo({lnd});
|
|
23
25
|
|
|
24
|
-
if (result.current_block_height
|
|
26
|
+
if (result.current_block_height >= initHeight) {
|
|
25
27
|
return result;
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -32,7 +34,7 @@ test(`Get wallet info`, async ({end, equal, strictSame}) => {
|
|
|
32
34
|
equal(!!result.alias, true, 'Expected alias');
|
|
33
35
|
strictSame(result.chains, [regtestChainId], 'Got chains');
|
|
34
36
|
equal(!!result.current_block_hash, true, 'Expected best block hash');
|
|
35
|
-
|
|
37
|
+
ok(result.current_block_height >= initHeight, 'Expected block height');
|
|
36
38
|
equal(!!result.latest_block_at, true, 'Last block time');
|
|
37
39
|
equal(result.peers_count, 0, 'Expected wallet peers count');
|
|
38
40
|
equal(result.pending_channels_count, 0, 'Expected pending channels count');
|
|
@@ -36,9 +36,9 @@ test(`Open channels`, async ({end, equal}) => {
|
|
|
36
36
|
|
|
37
37
|
const [{generate, lnd}, target, remote] = nodes;
|
|
38
38
|
|
|
39
|
-
await generate({count: maturity});
|
|
40
|
-
|
|
41
39
|
try {
|
|
40
|
+
await generate({count: maturity});
|
|
41
|
+
|
|
42
42
|
await asyncRetry({interval, times}, async () => {
|
|
43
43
|
const lnds = [lnd, target.lnd, remote.lnd];
|
|
44
44
|
|
|
@@ -10,7 +10,6 @@ const {createInvoice} = require('./../../');
|
|
|
10
10
|
const {decodePaymentRequest} = require('./../../');
|
|
11
11
|
const {delay} = require('./../macros');
|
|
12
12
|
const {getChannel} = require('./../../');
|
|
13
|
-
const {getChannels} = require('./../../');
|
|
14
13
|
const {getHeight} = require('./../../');
|
|
15
14
|
const {getNetworkGraph} = require('./../../');
|
|
16
15
|
const {getRouteToDestination} = require('./../../');
|
|
@@ -8,7 +8,6 @@ const {cancelHodlInvoice} = require('./../../');
|
|
|
8
8
|
const {createInvoice} = require('./../../');
|
|
9
9
|
const {decodePaymentRequest} = require('./../../');
|
|
10
10
|
const {getChannel} = require('./../../');
|
|
11
|
-
const {getChannels} = require('./../../');
|
|
12
11
|
const {getInvoice} = require('./../../');
|
|
13
12
|
const {getRouteToDestination} = require('./../../');
|
|
14
13
|
const {openChannel} = require('./../../');
|
|
@@ -14,21 +14,25 @@ test(`Remove a peer`, async ({end, equal}) => {
|
|
|
14
14
|
|
|
15
15
|
const [{id, lnd}, target] = nodes;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
await
|
|
19
|
-
|
|
17
|
+
try {
|
|
18
|
+
await asyncRetry({interval: 10, times: 2000}, async () => {
|
|
19
|
+
await addPeer({lnd, public_key: target.id, socket: target.socket});
|
|
20
|
+
});
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
const {peers} = await getPeers({lnd});
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
const [targetPeer] = peers;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
equal(targetPeer.public_key, target.id, 'Peer is added');
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
await removePeer({lnd, public_key: targetPeer.public_key});
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
const postRemovalPeers = await getPeers({lnd});
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
equal(postRemovalPeers.peers.length, [].length, 'Peer is removed');
|
|
33
|
+
} catch (err) {
|
|
34
|
+
equal(err, null, 'Expected no error');
|
|
35
|
+
}
|
|
32
36
|
|
|
33
37
|
await kill({});
|
|
34
38
|
|
|
@@ -8,7 +8,7 @@ const {subscribeToPeerMessages} = require('./../../');
|
|
|
8
8
|
|
|
9
9
|
const interval = 10;
|
|
10
10
|
const size = 2;
|
|
11
|
-
const times =
|
|
11
|
+
const times = 2000;
|
|
12
12
|
|
|
13
13
|
// Sending a message to a peer should result in the message received
|
|
14
14
|
test(`Send peer message`, async ({end, equal, strictSame}) => {
|
|
@@ -33,39 +33,50 @@ test(`Send peer message`, async ({end, equal, strictSame}) => {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
await
|
|
38
|
-
|
|
36
|
+
try {
|
|
37
|
+
await asyncRetry({interval, times}, async () => {
|
|
38
|
+
await addPeer({
|
|
39
|
+
lnd,
|
|
40
|
+
public_key: target.id,
|
|
41
|
+
retry_count: 1,
|
|
42
|
+
retry_delay: 1,
|
|
43
|
+
socket: target.socket,
|
|
44
|
+
timeout: 1000,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
const sub = subscribeToPeerMessages({lnd: target.lnd});
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
const messages = [];
|
|
43
51
|
|
|
44
|
-
|
|
52
|
+
sub.on('message_received', message => messages.push(message));
|
|
45
53
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
await asyncRetry({interval, times}, async () => {
|
|
55
|
+
await sendMessageToPeer({
|
|
56
|
+
lnd,
|
|
57
|
+
message: Buffer.from('message').toString('hex'),
|
|
58
|
+
public_key: target.id,
|
|
59
|
+
});
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const [message] = messages;
|
|
61
|
+
if (!messages.length) {
|
|
62
|
+
throw new Error('ExpectedMessage');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
message
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const [message] = messages;
|
|
67
|
+
|
|
68
|
+
strictSame(
|
|
69
|
+
message,
|
|
70
|
+
{
|
|
71
|
+
message: Buffer.from('message').toString('hex'),
|
|
72
|
+
public_key: id,
|
|
73
|
+
type: 32768,
|
|
74
|
+
},
|
|
75
|
+
'Message successfully sent to peer'
|
|
76
|
+
);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
equal(err, null, 'Expected no error');
|
|
79
|
+
}
|
|
69
80
|
|
|
70
81
|
await kill({});
|
|
71
82
|
|
|
@@ -5,7 +5,6 @@ const {test} = require('@alexbosworth/tap');
|
|
|
5
5
|
const {addPeer} = require('./../../');
|
|
6
6
|
const {closeChannel} = require('./../../');
|
|
7
7
|
const {getChainBalance} = require('./../../');
|
|
8
|
-
const {getHeight} = require('./../../');
|
|
9
8
|
const {getWalletInfo} = require('./../../');
|
|
10
9
|
const {openChannel} = require('./../../');
|
|
11
10
|
const {removePeer} = require('./../../');
|