Skip to content

Commit 2485960

Browse files
authored
Merge pull request #97 from synonymdev/fix/fallback-expired-ln-to-onchain
Fix/fallback expired ln to onchain update
2 parents 028fd1c + 1facde9 commit 2485960

5 files changed

Lines changed: 53 additions & 50 deletions

File tree

test/helpers/electrum.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const peer = {
1212
ssl: 60002,
1313
};
1414

15-
const TIMEOUT = 30 * 1000; // 30 seconds
15+
const TIMEOUT = 120 * 1000; // 120 seconds
1616

1717
function sleep(ms: number): Promise<void> {
1818
return new Promise((resolve) => setTimeout(resolve, ms));
@@ -76,8 +76,21 @@ const initElectrum = async (): Promise<ElectrumClient> => {
7676
break;
7777
}
7878

79+
// Actively check if Electrum has the block at nodeHeight
80+
// This handles the case where Electrum is catching up but no new blocks are mined
81+
const { error } = await electrum.getHeader({
82+
height: nodeHeight,
83+
network: 'bitcoinRegtest',
84+
timeout: 5000,
85+
});
86+
if (!error) {
87+
// Electrum has caught up to nodeHeight
88+
electrumHeight = nodeHeight;
89+
break;
90+
}
91+
7992
if (Date.now() - startTime > TIMEOUT) {
80-
throw new Error('Electrum sync timeout');
93+
throw new Error('Electrum sync timeout exceeded 120 seconds');
8194
}
8295

8396
await sleep(1000);

test/specs/numberpad.e2e.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import BitcoinJsonRpc from 'bitcoin-json-rpc';
21
import {
32
completeOnboarding,
43
enterAddress,
@@ -15,26 +14,23 @@ import {
1514
import initElectrum from '../helpers/electrum';
1615
import { launchFreshApp, reinstallApp } from '../helpers/setup';
1716
import { ciIt } from '../helpers/suite';
18-
import { bitcoinURL } from '../helpers/constants';
17+
import { ensureLocalFunds } from '../helpers/regtest';
1918

2019
describe('@numberpad - NumberPad', () => {
2120
let electrum: Awaited<ReturnType<typeof initElectrum>> | undefined;
22-
const rpc = new BitcoinJsonRpc(bitcoinURL);
23-
before(async () => {
24-
let balance = await rpc.getBalance();
25-
const address = await rpc.getNewAddress();
26-
27-
while (balance < 10) {
28-
await rpc.generateToAddress(10, address);
29-
balance = await rpc.getBalance();
30-
}
3121

22+
before(async () => {
23+
await ensureLocalFunds();
3224
electrum = await initElectrum();
3325
await reinstallApp();
3426
await completeOnboarding();
3527
await receiveOnchainFunds({ sats: 10_000 });
3628
});
3729

30+
after(async () => {
31+
await electrum?.stop();
32+
});
33+
3834
beforeEach(async () => {
3935
await launchFreshApp();
4036
await electrum?.waitForSync();

test/specs/security.e2e.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('@security - Security And Privacy', () => {
5151
await tap('DrawerSettings');
5252
await tap('SecuritySettings');
5353
await tap('PINCode');
54+
await sleep(1000);
5455
await tap('SecureWalletContinue');
5556
await multiTap('N1', PIN_LENGTH); // enter PIN
5657
await multiTap('N2', PIN_LENGTH); // retype wrong PIN
@@ -63,7 +64,7 @@ describe('@security - Security And Privacy', () => {
6364
await doNavigationClose();
6465

6566
// - login with PIN
66-
await launchFreshApp({ tryHandleAlert: false });
67+
await launchFreshApp();
6768
await elementById('PinPad').waitForDisplayed();
6869
await sleep(1000);
6970
await multiTap('N1', PIN_LENGTH);
@@ -104,7 +105,7 @@ describe('@security - Security And Privacy', () => {
104105
await multiTap('N2', PIN_LENGTH); // correct new pin in the confirmation
105106
await tap('OK');
106107

107-
await launchFreshApp({ tryHandleAlert: false });
108+
await launchFreshApp();
108109
await elementById('PinPad').waitForDisplayed();
109110
await sleep(1000);
110111
await multiTap('N2', PIN_LENGTH);
@@ -118,14 +119,15 @@ describe('@security - Security And Privacy', () => {
118119
await tap('DisablePin');
119120
await multiTap('N2', PIN_LENGTH);
120121
await sleep(1000);
121-
await launchFreshApp({ tryHandleAlert: false });
122+
await launchFreshApp();
122123
await elementById('TotalBalance').waitForDisplayed();
123124

124125
// enable PIN for last test
125126
await tap('HeaderMenu');
126127
await tap('DrawerSettings');
127128
await tap('SecuritySettings');
128129
await tap('PINCode');
130+
await sleep(1000);
129131
await tap('SecureWalletContinue');
130132
await multiTap('N1', PIN_LENGTH); // enter PIN
131133
await multiTap('N1', PIN_LENGTH); // retype PIN
@@ -135,7 +137,7 @@ describe('@security - Security And Privacy', () => {
135137
await sleep(1000);
136138

137139
// now lets restart the app and fail to enter correct PIN 8 times
138-
await launchFreshApp({ tryHandleAlert: false });
140+
await launchFreshApp();
139141
await elementById('PinPad').waitForDisplayed();
140142
for (let i = 1; i <= MAX_ATTEMPTS_BEFORE_LAST; i++) {
141143
await multiTap('N9', PIN_LENGTH); // wrong PIN

test/specs/send.e2e.ts

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -325,39 +325,31 @@ describe('@send - Send', () => {
325325

326326
// send to unified invoice w/ expired invoice
327327
let amtAfterUnified3: string;
328-
if (driver.isAndroid) {
329-
console.info('Sending to unified invoice w/ expired invoice...');
330-
const unified3 =
331-
'bitcoin:bcrt1qaytrqsrgg75rtxrtr7ur6k75la8p3v95mey48z?lightning=LNBCRT1PN33T20DQQNP4QTNTQ4D2DHDYQ420HAUQF5TS7X32TNW9WGYEPQZQ6R9G69QPHW4RXPP5QU7UYXJYJA9PJV7H6JPEYEFFNZ98N686JDEAAK8AUD5AGC5X70HQSP54V5LEFATCQDEU8TLKAF6MDK3ZLU6MWUA52J4JEMD5XA85KGKMTTQ9QYYSGQCQPCXQRRSSRZJQWU6G4HMGH26EXXQYPQD8XHVWLARA66PL53V7S9CV2EE808UGDRN4APYQQQQQQQGRCQQQQLGQQQQQQGQ2QX7F74RT5SQE0KEYCU47LYMSVY2LM4QA4KLR65PPSY55M0H4VR8AN7WVM9EFVSPYJ5R8EFGVXTGVATAGFTC372VRJ3HEPSEELFZ7FQFCQ9XDU9X';
332-
console.info({ unified3 });
333-
334-
// const ln =
335-
// 'LNBCRT1PN33T20DQQNP4QTNTQ4D2DHDYQ420HAUQF5TS7X32TNW9WGYEPQZQ6R9G69QPHW4RXPP5QU7UYXJYJA9PJV7H6JPEYEFFNZ98N686JDEAAK8AUD5AGC5X70HQSP54V5LEFATCQDEU8TLKAF6MDK3ZLU6MWUA52J4JEMD5XA85KGKMTTQ9QYYSGQCQPCXQRRSSRZJQWU6G4HMGH26EXXQYPQD8XHVWLARA66PL53V7S9CV2EE808UGDRN4APYQQQQQQQGRCQQQQLGQQQQQQGQ2QX7F74RT5SQE0KEYCU47LYMSVY2LM4QA4KLR65PPSY55M0H4VR8AN7WVM9EFVSPYJ5R8EFGVXTGVATAGFTC372VRJ3HEPSEELFZ7FQFCQ9XDU9X';
336-
// const dec = await lnd.decodePayReq({ payReq: ln });
337-
// console.info(JSON.stringify(dec, null, 2));
328+
console.info('Sending to unified invoice w/ expired invoice...');
329+
const unified3 =
330+
'bitcoin:bcrt1qaytrqsrgg75rtxrtr7ur6k75la8p3v95mey48z?lightning=LNBCRT1PN33T20DQQNP4QTNTQ4D2DHDYQ420HAUQF5TS7X32TNW9WGYEPQZQ6R9G69QPHW4RXPP5QU7UYXJYJA9PJV7H6JPEYEFFNZ98N686JDEAAK8AUD5AGC5X70HQSP54V5LEFATCQDEU8TLKAF6MDK3ZLU6MWUA52J4JEMD5XA85KGKMTTQ9QYYSGQCQPCXQRRSSRZJQWU6G4HMGH26EXXQYPQD8XHVWLARA66PL53V7S9CV2EE808UGDRN4APYQQQQQQQGRCQQQQLGQQQQQQGQ2QX7F74RT5SQE0KEYCU47LYMSVY2LM4QA4KLR65PPSY55M0H4VR8AN7WVM9EFVSPYJ5R8EFGVXTGVATAGFTC372VRJ3HEPSEELFZ7FQFCQ9XDU9X';
331+
console.info({ unified3 });
332+
333+
// const ln =
334+
// 'LNBCRT1PN33T20DQQNP4QTNTQ4D2DHDYQ420HAUQF5TS7X32TNW9WGYEPQZQ6R9G69QPHW4RXPP5QU7UYXJYJA9PJV7H6JPEYEFFNZ98N686JDEAAK8AUD5AGC5X70HQSP54V5LEFATCQDEU8TLKAF6MDK3ZLU6MWUA52J4JEMD5XA85KGKMTTQ9QYYSGQCQPCXQRRSSRZJQWU6G4HMGH26EXXQYPQD8XHVWLARA66PL53V7S9CV2EE808UGDRN4APYQQQQQQQGRCQQQQLGQQQQQQGQ2QX7F74RT5SQE0KEYCU47LYMSVY2LM4QA4KLR65PPSY55M0H4VR8AN7WVM9EFVSPYJ5R8EFGVXTGVATAGFTC372VRJ3HEPSEELFZ7FQFCQ9XDU9X';
335+
// const dec = await lnd.decodePayReq({ payReq: ln });
336+
// console.info(JSON.stringify(dec, null, 2));
338337

339-
await sleep(1000);
340-
await enterAddress(unified3, { acceptCameraPermission: false });
341-
await elementById('AssetButton-savings').waitForDisplayed();
342-
await tap('N1');
343-
await multiTap('N0', 4);
344-
await tap('ContinueAmount');
345-
await reviewAmt.waitForDisplayed();
346-
await expect(reviewAmt).toHaveText('10 000');
347-
await dragOnElement('GRAB', 'right', 0.95);
348-
await elementById('SendSuccess').waitForDisplayed();
349-
await tap('Close');
350-
await expect(totalBalance).not.toHaveText(amtAfterUnified2);
351-
amtAfterUnified3 = await totalBalance.getText();
352-
console.info({ amtAfterUnified3 });
353-
await expectTextWithin('ActivitySpending', '7 000');
354-
} else {
355-
// https://github.com/synonymdev/bitkit-ios/issues/300
356-
console.info(
357-
'Skipping sending to unified invoice w/ expired invoice on iOS due to /bitkit-ios/issues/300'
358-
);
359-
amtAfterUnified3 = amtAfterUnified2;
360-
}
338+
await sleep(1000);
339+
await enterAddress(unified3, { acceptCameraPermission: false });
340+
await elementById('AssetButton-savings').waitForDisplayed();
341+
await tap('N1');
342+
await multiTap('N0', 4);
343+
await tap('ContinueAmount');
344+
await reviewAmt.waitForDisplayed();
345+
await expect(reviewAmt).toHaveText('10 000');
346+
await dragOnElement('GRAB', 'right', 0.95);
347+
await elementById('SendSuccess').waitForDisplayed();
348+
await tap('Close');
349+
await expect(totalBalance).not.toHaveText(amtAfterUnified2);
350+
amtAfterUnified3 = await totalBalance.getText();
351+
console.info({ amtAfterUnified3 });
352+
await expectTextWithin('ActivitySpending', '7 000');
361353

362354
// send to unified invoice w/o amount (lightning)
363355
console.info('Sending to unified invoice w/o amount (lightning)...');

wdio.conf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export const config: WebdriverIO.Config = {
123123
// baseUrl: 'http://localhost:8080',
124124
//
125125
// Default timeout for all waitFor* commands.
126-
waitforTimeout: 30000,
126+
waitforTimeout: process.env.CI ? 30000 : 10000,
127127
//
128128
// Default timeout in milliseconds for request
129129
// if browser driver or grid doesn't send response

0 commit comments

Comments
 (0)