Skip to content

Commit

Permalink
test(backup): add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed Nov 27, 2024
1 parent 0f96482 commit a32374c
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 184 deletions.
51 changes: 4 additions & 47 deletions e2e/backup.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
bitcoinURL,
electrumHost,
electrumPort,
getSeed,
restoreWallet,
} from './helpers';
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';

Expand Down Expand Up @@ -103,54 +105,9 @@ d('Backup', () => {
await element(by.id('WidgetsEdit')).tap();
await expect(element(by.id('PriceWidget'))).toBeVisible();

// get seed
await element(by.id('Settings')).tap();
await element(by.id('BackupSettings')).tap();
await element(by.id('BackupWallet')).tap();
await sleep(200); // 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(200); // animation
await element(by.id('NavigationClose')).atIndex(0).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(200);
try {
await element(by.id('SuggestionsLabel')).tap();
break;
} catch (e) {}
}
const seed = await getSeed();
await restoreWallet(seed);

// check settings
await expect(
Expand Down
17 changes: 16 additions & 1 deletion e2e/boost.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
bitcoinURL,
electrumHost,
electrumPort,
getSeed,
restoreWallet,
} from './helpers';
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';

Expand Down Expand Up @@ -267,10 +269,23 @@ d('Boost', () => {
assert(Number(oldFee.replace(' ', '')) < Number(newFee.replace(' ', '')));
assert(oldTxid !== newTxid);
await expect(element(by.id('RBFBoosted'))).toBeVisible();
await element(by.id('NavigationClose')).atIndex(0).tap();

// wipe & restore
const seed = await getSeed();
await restoreWallet(seed);

// check activity after restore
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
await expect(element(by.id('BoostingIcon'))).toBeVisible();
await element(by.id('ActivityShort-1')).tap();
await expect(element(by.id('BoostedButton'))).toBeVisible();
await expect(element(by.id('StatusBoosting'))).toBeVisible();

// mine new block
await element(by.id('NavigationBack')).atIndex(0).tap();
await rpc.generateToAddress(1, await rpc.getNewAddress());

// check activity item after mine
await waitFor(element(by.id('StatusConfirmed')))
.toBeVisible()
.withTimeout(30000);
Expand Down
14 changes: 14 additions & 0 deletions e2e/channels.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
sleep,
waitForActiveChannel,
waitForPeerConnection,
getSeed,
restoreWallet,
} from './helpers';

d = checkComplete(['transfer-1', 'transfer-2']) ? describe.skip : describe;
Expand Down Expand Up @@ -186,6 +188,18 @@ d('Transfer', () => {
await expect(
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
).toHaveText('250 000');
await element(by.id('NavigationClose')).tap();

const seed = await getSeed();
await restoreWallet(seed);

// check transfer card
await expect(element(by.id('Suggestion-lightningSettingUp'))).toBeVisible();

// check activity after restore
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
await element(by.id('ActivityShort-1')).tap();
await expect(element(by.id('StatusTransfer'))).toBeVisible();

markComplete('transfer-1');
});
Expand Down
62 changes: 62 additions & 0 deletions e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,65 @@ export const waitForActiveChannel = async (lnd, nodeId, maxRetries = 20) => {
throw new Error('Channel not active');
}
};

export const getSeed = async () => {
await element(by.id('Settings')).tap();
await element(by.id('BackupSettings')).tap();
await element(by.id('BackupWallet')).tap();
// animation
await sleep(200);
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');
// animation
await sleep(200);
await element(by.id('NavigationClose')).atIndex(0).tap();

console.info({ seed });

return seed;
};

export const restoreWallet = async (seed, passphrase) => {
// make sure everything is saved to cloud storage
// TODO: improve this
await sleep(5000);

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');

if (passphrase) {
await element(by.id('AdvancedButton')).tap();
await element(by.id('PassphraseInput')).typeText(passphrase);
await element(by.id('PassphraseInput')).tapReturnKey();
}

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(200);
try {
await element(by.id('SuggestionsLabel')).tap();
break;
} catch (e) {}
}
};
51 changes: 5 additions & 46 deletions e2e/lightning.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
sleep,
waitForActiveChannel,
waitForPeerConnection,
restoreWallet,
getSeed,
} from './helpers';

d = checkComplete('lighting-1') ? describe.skip : describe;
Expand Down Expand Up @@ -311,52 +313,9 @@ d('Lightning', () => {
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')).atIndex(0).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) {}
}
// wipe and restore wallet
const seed = await getSeed();
await restoreWallet(seed);

// check balance
await waitFor(
Expand Down
61 changes: 14 additions & 47 deletions e2e/onboarding.e2e.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import jestExpect from 'expect';

import { sleep, checkComplete, markComplete } from './helpers';
import {
sleep,
checkComplete,
markComplete,
getSeed,
restoreWallet,
} from './helpers';

d = checkComplete('onboarding-1') ? describe.skip : describe;

Expand Down Expand Up @@ -31,8 +37,9 @@ d('Onboarding', () => {
await element(by.id('SkipButton')).tap();

// create new wallet with passphrase
const passphrase = 'supersecret';
await element(by.id('Passphrase')).tap();
await element(by.id('PassphraseInput')).typeText('supersecret');
await element(by.id('PassphraseInput')).typeText(passphrase);
await element(by.id('PassphraseInput')).tapReturnKey();
await element(by.id('CreateNewWallet')).tap();

Expand All @@ -54,20 +61,9 @@ d('Onboarding', () => {
}
}

// get seed
await element(by.id('Settings')).tap();
await element(by.id('BackupSettings')).tap();
await element(by.id('BackupWallet')).tap();
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 element(by.id('NavigationClose')).atIndex(0).tap();
console.info('seed: ', seed);

// get receing address
const seed = await getSeed();

// get receiving address
await element(by.id('Receive')).tap();
await waitFor(element(by.id('QRCode')))
.toBeVisible()
Expand All @@ -76,38 +72,9 @@ d('Onboarding', () => {
console.info('address', address1);

// wipe and 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('AdvancedButton')).tap();
await element(by.id('PassphraseInput')).typeText('supersecret');
await element(by.id('PassphraseInput')).tapReturnKey();
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) {}
}
await restoreWallet(seed, passphrase);

// get receing address
// get receiving address
await element(by.id('Receive')).tap();
await waitFor(element(by.id('QRCode')))
.toBeVisible()
Expand Down
Loading

0 comments on commit a32374c

Please sign in to comment.