forked from synonymdev/bitkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightning.e2e.js
425 lines (380 loc) · 13.7 KB
/
lightning.e2e.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
import BitcoinJsonRpc from 'bitcoin-json-rpc';
import createLndRpc from '@radar/lnrpc';
import {
sleep,
checkComplete,
markComplete,
launchAndWait,
completeOnboarding,
bitcoinURL,
electrumHost,
electrumPort,
} from './helpers';
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';
const __DEV__ = process.env.DEV === 'true';
d = checkComplete('lighting-1') ? describe.skip : describe;
d('Lightning', () => {
let waitForElectrum;
const rpc = new BitcoinJsonRpc(bitcoinURL);
beforeAll(async () => {
let balance = await rpc.getBalance();
const address = await rpc.getNewAddress();
while (balance < 10) {
await rpc.generateToAddress(10, address);
balance = await rpc.getBalance();
}
waitForElectrum = await initWaitForElectrumToSync(
{ host: electrumHost, port: electrumPort },
bitcoinURL,
);
await completeOnboarding();
});
beforeEach(async () => {
await launchAndWait();
await waitForElectrum();
});
afterEach(() => {
waitForElectrum?.close();
});
d('Receive and Send', () => {
// Test plan:
// - connect to LND node
// - receive funds
// - send funds
// - check balances, tx history and notes
// - restore wallet
// - check balances, tx history and notes
// - close channel
it('Can receive and send LN payments', async () => {
if (checkComplete('lighting-1')) {
return;
}
// send funds to LND node and open a channel
const lnd = await createLndRpc({
server: 'localhost:10009',
tls: `${__dirname}/../docker/lnd/tls.cert`,
macaroonPath: `${__dirname}/../docker/lnd/data/chain/bitcoin/regtest/admin.macaroon`,
});
const { address: lndAddress } = await lnd.newAddress();
await rpc.sendToAddress(lndAddress, '1');
await rpc.generateToAddress(1, await rpc.getNewAddress());
await waitForElectrum();
const { identityPubkey: lndNodeID } = await lnd.getInfo();
// get LDK Node id
await element(by.id('Settings')).tap();
if (!__DEV__) {
await element(by.id('DevOptions')).multiTap(5); // enable dev mode
}
await element(by.id('AdvancedSettings')).tap();
// wait for LDK to start
await sleep(5000);
await element(by.id('LightningNodeInfo')).tap();
await waitFor(element(by.id('LDKNodeID')))
.toBeVisible()
.withTimeout(60000);
let { label: ldkNodeID } = await element(
by.id('LDKNodeID'),
).getAttributes();
await element(by.id('NavigationBack')).tap();
// connect to LND
await element(by.id('Channels')).tap();
await element(by.id('AddPeerInput')).replaceText(
`${lndNodeID}@127.0.0.1:9735`,
);
await element(by.id('AddPeerInput')).tapReturnKey();
await element(by.id('AddPeerButton')).tap();
// wait for peer to be connected
let n = 0;
while (n < 20) {
await sleep(1000);
const { peers } = await lnd.listPeers();
if (peers.some((p) => p.pubKey === ldkNodeID)) {
break;
}
n++;
if (n === 0) {
throw new Error('Peer not connected');
}
}
// open a channel
await lnd.openChannelSync({
nodePubkeyString: ldkNodeID,
localFundingAmount: '100000',
private: true,
});
await rpc.generateToAddress(6, await rpc.getNewAddress());
await waitForElectrum();
// wait for channel to be active
let m = 0;
while (m < 20) {
await sleep(1000);
const { channels } = await lnd.listChannels({
peer: Buffer.from(ldkNodeID, 'hex'),
activeOnly: true,
});
if (channels?.length > 0) {
break;
}
m++;
if (m === 0) {
throw new Error('Channel not active');
}
}
// check channel status
await sleep(500);
await element(by.id('NavigationBack')).tap();
await element(by.id('Channels')).tap();
await element(by.id('Channel')).atIndex(0).tap();
await expect(
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
).toHaveText('100 000');
await element(by.id('ChannelScrollView')).scrollTo('bottom');
await expect(element(by.id('IsReadyYes'))).toBeVisible();
await element(by.id('NavigationClose')).tap();
// send funds to LDK, 0 invoice
await element(by.id('Receive')).tap();
let { label: invoice1 } = await element(by.id('QRCode')).getAttributes();
invoice1 = invoice1.replaceAll(/bitcoin.*=/gi, '').toLowerCase();
await lnd.sendPaymentSync({ paymentRequest: invoice1, amt: 50000 });
await waitFor(element(by.id('NewTxPrompt')))
.toBeVisible()
.withTimeout(10000);
await element(by.id('NewTxPrompt')).swipe('down');
await waitFor(
element(by.id('MoneyText').withAncestor(by.id('TotalBalance'))),
)
.toHaveText('49 000')
.withTimeout(10000);
// send funds to LDK, 111 sats invoice
await element(by.id('Receive')).tap();
await element(by.id('SpecifyInvoiceButton')).tap();
await element(by.id('ReceiveNumberPadTextField')).tap();
await element(
by.id('N1').withAncestor(by.id('ReceiveNumberPad')),
).multiTap(3);
await element(by.id('ReceiveNumberPadSubmit')).tap();
const note1 = 'note 111';
await element(by.id('ReceiveNote')).typeText(note1);
await element(by.id('ReceiveNote')).tapReturnKey();
await element(by.id('TagsAdd')).tap();
await element(by.id('TagInputReceive')).typeText('rtag');
await element(by.id('TagInputReceive')).tapReturnKey();
await element(by.id('ShowQrReceive')).tap();
await element(by.id('QRCode')).swipe('left');
const { label: invoice2 } = await element(
by.id('ReceiveLightningInvoice'),
).getAttributes();
await lnd.sendPaymentSync({ paymentRequest: invoice2 });
await waitFor(element(by.id('NewTxPrompt')))
.toBeVisible()
.withTimeout(10000);
await element(by.id('NewTxPrompt')).swipe('down');
await waitFor(
element(by.id('MoneyText').withAncestor(by.id('TotalBalance'))),
)
.toHaveText('49 111')
.withTimeout(10000);
// send funds to LND, 0 invoice
const note2 = 'zero';
const { paymentRequest: invoice3 } = await lnd.addInvoice({
memo: note2,
});
await element(by.id('Send')).tap();
await element(by.id('RecipientManual')).tap();
await element(by.id('RecipientInput')).replaceText(invoice3);
await element(by.id('RecipientInput')).tapReturnKey();
await sleep(1000); // wait for keyboard to hide
await element(by.id('AddressContinue')).tap();
await element(
by.id('N1').withAncestor(by.id('SendAmountNumberPad')),
).multiTap(3);
await element(by.id('ContinueAmount')).tap();
await element(by.id('GRAB')).swipe('right'); // Swipe to confirm
await waitFor(element(by.id('SendSuccess')))
.toBeVisible()
.withTimeout(10000);
await element(by.id('Close')).tap();
await waitFor(
element(by.id('MoneyText').withAncestor(by.id('TotalBalance'))),
)
.toHaveText('49 000')
.withTimeout(10000);
// send funds to LND, 10000 invoice
const { paymentRequest: invoice4 } = await lnd.addInvoice({
value: '1000',
});
await element(by.id('Send')).tap();
await element(by.id('RecipientManual')).tap();
await element(by.id('RecipientInput')).replaceText(invoice4);
await element(by.id('RecipientInput')).tapReturnKey();
await sleep(1000); // wait for keyboard to hide
await element(by.id('AddressContinue')).tap();
// Review & Send
await expect(element(by.id('TagsAddSend'))).toBeVisible();
await element(by.id('TagsAddSend')).tap(); // add tag
await element(by.id('TagInputSend')).typeText('stag');
await element(by.id('TagInputSend')).tapReturnKey();
await element(by.id('GRAB')).swipe('right'); // Swipe to confirm
await waitFor(element(by.id('SendSuccess')))
.toBeVisible()
.withTimeout(10000);
await element(by.id('Close')).tap();
await waitFor(
element(by.id('MoneyText').withAncestor(by.id('TotalBalance'))),
)
.toHaveText('48 000')
.withTimeout(10000);
// check tx history
await element(by.id('TransferButton')).swipe('up');
await expect(
element(by.text('1 000').withAncestor(by.id('ActivityShort-1'))),
).toBeVisible();
await expect(
element(by.text('111').withAncestor(by.id('ActivityShort-2'))),
).toBeVisible();
await expect(
element(by.text('111').withAncestor(by.id('ActivityShort-3'))),
).toBeVisible();
await element(by.id('ActivityShort-2')).tap();
await expect(element(by.id('InvoiceNote'))).toHaveText(note2);
await element(by.id('NavigationClose')).tap();
await element(by.id('ActivityShort-3')).tap();
await expect(element(by.id('InvoiceNote'))).toHaveText(note1);
await element(by.id('NavigationClose')).tap();
// check activity filters & tags
await element(by.id('ActivityShowAll')).tap();
// All, 4 transactions
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-1'))),
).toHaveText('-');
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-2'))),
).toHaveText('-');
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-3'))),
).toHaveText('+');
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-4'))),
).toHaveText('+');
await expect(element(by.id('Activity-5'))).not.toExist();
// Sent, 2 transactions
await element(by.id('Tab-sent')).tap();
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-1'))),
).toHaveText('-');
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-2'))),
).toHaveText('-');
await expect(element(by.id('Activity-3'))).not.toExist();
// Received, 2 transactions
await element(by.id('Tab-received')).tap();
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-1'))),
).toHaveText('+');
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-2'))),
).toHaveText('+');
await expect(element(by.id('Activity-3'))).not.toExist();
// Other, 0 transactions
await element(by.id('Tab-other')).tap();
await expect(element(by.id('Activity-1'))).not.toExist();
// filter by receive tag
await element(by.id('Tab-all')).tap();
await element(by.id('TagsPrompt')).tap();
await element(by.id('Tag-rtag')).tap();
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-1'))),
).toHaveText('+');
await expect(element(by.id('Activity-2'))).not.toExist();
await element(by.id('Tag-rtag-delete')).tap();
// filter by send tag
await element(by.id('TagsPrompt')).tap();
await element(by.id('Tag-stag')).tap();
await expect(
element(by.id('MoneySign').withAncestor(by.id('Activity-1'))),
).toHaveText('-');
await expect(element(by.id('Activity-2'))).not.toExist();
await element(by.id('Tag-stag-delete')).tap();
await element(by.id('NavigationClose')).tap();
// get seed
await element(by.id('Settings')).tap();
await element(by.id('BackupSettings')).tap();
await element(by.id('BackupWallet')).tap();
await sleep(1000); // animation
await element(by.id('TapToReveal')).tap();
// get the seed from SeedContaider
const { label: seed } = await element(
by.id('SeedContaider'),
).getAttributes();
await element(by.id('SeedContaider')).swipe('down');
await sleep(1000); // animation
await element(by.id('NavigationClose')).tap();
await sleep(5000); // make sure everything is saved to cloud storage TODO: improve this
console.info('seed: ', seed);
// restore wallet
await device.launchApp({ delete: true });
await waitFor(element(by.id('Check1'))).toBeVisible();
await element(by.id('Check1')).tap();
await element(by.id('Check2')).tap();
await element(by.id('Continue')).tap();
await waitFor(element(by.id('SkipIntro'))).toBeVisible();
await element(by.id('SkipIntro')).tap();
await element(by.id('RestoreWallet')).tap();
await element(by.id('MultipleDevices-button')).tap();
await element(by.id('Word-0')).replaceText(seed);
await element(by.id('WordIndex-4')).swipe('up');
await element(by.id('RestoreButton')).tap();
await waitFor(element(by.id('GetStartedButton')))
.toBeVisible()
.withTimeout(300000); // 5 min
await element(by.id('GetStartedButton')).tap();
// wait for SuggestionsLabel to appear and be accessible
for (let i = 0; i < 60; i++) {
await sleep(1000);
try {
await element(by.id('SuggestionsLabel')).tap();
break;
} catch (e) {}
}
// check balance
await waitFor(
element(by.id('MoneyText').withAncestor(by.id('TotalBalance'))),
)
.toHaveText('48 000')
.withTimeout(10000);
// check tx history
await element(by.id('TransferButton')).swipe('up');
await expect(
element(by.text('111').withAncestor(by.id('ActivityShort-2'))),
).toBeVisible();
await element(by.id('ActivityShort-2')).tap();
await expect(element(by.id('InvoiceNote'))).toHaveText(note2);
await element(by.id('NavigationClose')).tap();
// check channel status
await element(by.id('Settings')).tap();
await element(by.id('AdvancedSettings')).tap();
await element(by.id('Channels')).tap();
await element(by.id('Channel')).atIndex(0).tap();
await element(by.id('ChannelScrollView')).scrollTo('bottom');
await expect(element(by.id('IsReadyYes'))).toBeVisible();
// close channel
await element(by.id('CloseConnection')).tap();
await element(by.id('CloseConnectionButton')).tap();
await rpc.generateToAddress(6, await rpc.getNewAddress());
await waitForElectrum();
await expect(element(by.id('Channel')).atIndex(0)).not.toExist();
await element(by.id('NavigationBack')).tap();
await element(by.id('NavigationClose')).tap();
// TODO: for some reason this doen't work on github actions
// wait for onchain payment to arrive
// await waitFor(element(by.id('NewTxPrompt')))
// .toBeVisible()
// .withTimeout(60000);
// await element(by.id('NewTxPrompt')).swipe('down');
// await expect(
// element(by.id('MoneySign').withAncestor(by.id('ActivityShort-1'))),
// ).toHaveText('+');
markComplete('lighting-1');
});
});
});