Skip to content

Commit

Permalink
feat: add Restore wallet cases (#1765)
Browse files Browse the repository at this point in the history
* fix: ensureWalletIsVisible

* add: restorePrivateKey

* fix: restoreWallet

* add: wallet-create testIDs

* update: signin suite

* add: current-total id

* fix: tests

* fix: tests

* fix: skip staking e2e

* fix: tests

* update: detox

* feat: add resetApp

* fix: tests

* remove: toast from e2e builds
  • Loading branch information
ragozin-nikita authored Mar 11, 2024
1 parent 3b8fa2b commit 810f988
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 127 deletions.
1 change: 1 addition & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
device: {
name: 'HAQQ_e2e',
},
headless: true
},
attached: {
type: 'android.attached',
Expand Down
21 changes: 14 additions & 7 deletions e2e/1_signup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import {by, device, element, waitFor} from 'detox';

import {createWallet} from './helpers/createWallet';
import {ensureWalletIsVisible} from './helpers/ensureWalletIsVisible';
import {launchApp} from './helpers/launchApp';
import {PIN} from './test-variables';

describe('Signup', () => {
beforeAll(async () => {
await device.launchApp({
newInstance: true,
permissions: {notifications: 'NO'},
});
await launchApp();
});

it('should create and backup phrase', async () => {
Expand All @@ -25,7 +23,10 @@ describe('Signup', () => {

await element(by.id('protect_phrase_button')).tap();

await element(by.id('backup_warning')).scrollTo('bottom');
await waitFor(element(by.id('backup_warning_next')))
.toBeVisible()
.whileElement(by.id('backup_warning'))
.scroll(50, 'down');
await element(by.id('backup_warning_next')).tap();

const mnemonic_words = [];
Expand All @@ -39,7 +40,10 @@ describe('Signup', () => {
mnemonic_words.push(text);
}

await element(by.id('backup_create')).scrollTo('bottom');
await waitFor(element(by.id('backup_create_checkbox')))
.toBeVisible()
.whileElement(by.id('backup_create'))
.scroll(50, 'down');
await element(by.id('backup_create_checkbox')).tap();
await element(by.id('backup_create_next')).tap();

Expand All @@ -59,7 +63,10 @@ describe('Signup', () => {
await waitFor(elDisabled).toBeVisible().withTimeout(1000);
}

await element(by.id('backup_verify')).scrollTo('bottom');
await waitFor(element(by.id('backup_verify_check')))
.toBeVisible()
.whileElement(by.id('backup_verify'))
.scroll(50, 'down');
await element(by.id('backup_verify_check')).tap();

await waitFor(element(by.id('backup_finish')))
Expand Down
97 changes: 89 additions & 8 deletions e2e/2_signin.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,105 @@
import {device} from 'detox';
import {utils} from 'ethers';
import {Wallet, utils} from 'ethers';

import {ensureWalletIsVisible} from './helpers/ensureWalletIsVisible';
import {launchApp} from './helpers/launchApp';
import {restorePrivateKey} from './helpers/restorePrivateKey';
import {restoreWallet} from './helpers/restoreWallet';
import {PIN} from './test-variables';

describe('Signin', () => {
let mnemonic = '';
beforeAll(async () => {
await device.launchApp({
newInstance: true,
permissions: {notifications: 'NO'},
});
let privateKey = '';
let privateKeyMnemonic = '';

const resetApp = async () => {
await device.reloadReactNative();
await element(by.id('forgot_the_code')).tap();
await element(by.id('reset_wallet')).tap();
await element(by.label('Reset')).atIndex(0).tap();
};

beforeAll(async () => {
mnemonic = utils.entropyToMnemonic(utils.randomBytes(32));
const randomWallet = Wallet.createRandom();
privateKey = randomWallet.privateKey;
privateKeyMnemonic = randomWallet.mnemonic.phrase;
await launchApp();
});

it('should create and backup phrase', async () => {
await restoreWallet(mnemonic, PIN);
it('should restore privateKey wallet and import mnemonic wallet', async () => {
await restorePrivateKey(privateKey, PIN);
await ensureWalletIsVisible(privateKeyMnemonic);

await element(by.id('wallets')).scrollTo('right');
await waitFor(element(by.id('wallets_create_import')))
.toBeVisible()
.withTimeout(3000);
await element(by.id('wallets_create_import')).tap();

await restoreWallet(mnemonic, PIN, 2);
await ensureWalletIsVisible(mnemonic);
});

it('should restore mnemonic wallet and import privateKey wallet', async () => {
await resetApp();
await restoreWallet(mnemonic, PIN);
await ensureWalletIsVisible(mnemonic);

await element(by.id('wallets')).scrollTo('right');
await waitFor(element(by.id('wallets_create_import')))
.toBeVisible()
.withTimeout(3000);
await element(by.id('wallets_create_import')).tap();

await restorePrivateKey(privateKey, PIN, 2);
await ensureWalletIsVisible(privateKeyMnemonic);
});

it('should restore random wallet and more random wallets', async () => {
await resetApp();
const generateRandomWallet = (): {
wallet: string;
mnemonic: string;
isPrivateKey: boolean;
} => {
const randomWallet = Wallet.createRandom();
const isPrivateKey = Math.random() < 0.5;

return {
wallet: isPrivateKey
? randomWallet.privateKey
: randomWallet.mnemonic.phrase,
mnemonic: randomWallet.mnemonic.phrase,
isPrivateKey,
};
};
const getRandomNumber = (bottom: number, top: number) => {
return Math.floor(Math.random() * (1 + top - bottom)) + bottom;
};

const rootWallet = generateRandomWallet();
const rootRestore = rootWallet.isPrivateKey
? restorePrivateKey
: restoreWallet;
await rootRestore(rootWallet.wallet, PIN);
await ensureWalletIsVisible(rootWallet.mnemonic);

const attempts = getRandomNumber(2, 5);

for (var attempt = 1; attempt < attempts + 1; attempt++) {
await element(by.id('wallets')).scrollTo('right');
await waitFor(element(by.id('wallets_create_import')))
.toBeVisible()
.withTimeout(3000);
await element(by.id('wallets_create_import')).tap();

const randomWallet = generateRandomWallet();
const restore = randomWallet.isPrivateKey
? restorePrivateKey
: restoreWallet;
await restore(randomWallet.wallet, PIN, attempt + 1);
await ensureWalletIsVisible(randomWallet.mnemonic);
}
});
});
33 changes: 13 additions & 20 deletions e2e/3_routine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import {Wallet, utils} from 'ethers';
import {ensureWalletIsVisible} from './helpers/ensureWalletIsVisible';
import {getCoins} from './helpers/getCoins';
import {isVisible} from './helpers/isVisibile';
import {launchApp} from './helpers/launchApp';
import {MilkAddressProxy} from './helpers/milkAddressProxy';
import {restoreWallet} from './helpers/restoreWallet';
import {PIN} from './test-variables';

describe('Routine', () => {
let mnemonic = '';
const isAndroid = device.getPlatform() === 'android';
beforeAll(async () => {
await device.launchApp({
newInstance: true,
permissions: {notifications: 'NO'},
});

mnemonic = utils.entropyToMnemonic(utils.randomBytes(32));
await launchApp();
await restoreWallet(mnemonic, PIN);
});

Expand All @@ -26,8 +22,7 @@ describe('Routine', () => {
});

it('should reopen app', async () => {
await device.terminateApp();
await device.launchApp();
await device.reloadReactNative();

await waitFor(element(by.id('pin')))
.toBeVisible()
Expand All @@ -52,16 +47,13 @@ describe('Routine', () => {
const coinsAmount = '0.003';
await getCoins(mnemonic, coinsAmount);

await waitFor(element(by.text('ISLM: 0.003')))
.toBeVisible()
await waitFor(element(by.id('current-total')))
.toHaveText('0.003 ISLM')
.withTimeout(6 * 60_000);
await element(by.id(`wallets_${wallet.address.toLowerCase()}_send`)).tap();

const input_address = element(by.id('transaction_address_input'));
await input_address.typeText(MilkAddressProxy.address);
if (!isAndroid) {
await input_address.tapReturnKey();
}
await element(by.id('transaction_address_next')).tap();
const nextStillVisible = await isVisible('transaction_address_next');
if (nextStillVisible) {
Expand All @@ -74,11 +66,6 @@ describe('Routine', () => {
await element(by.text(`${coinsAmount} ISLM`))
.atIndex(0)
.tap();
if (isAndroid) {
await element(by.text(`${coinsAmount} ISLM`))
.atIndex(0)
.tap();
}

const input_form = element(by.id('transaction_sum_form_input'));
await input_form.tap();
Expand All @@ -90,14 +77,20 @@ describe('Routine', () => {
.toBeVisible()
.withTimeout(15000);

await element(by.id('transaction_confirmation')).scrollTo('bottom');
await waitFor(element(by.id('transaction_confirmation_submit')))
.toBeVisible()
.whileElement(by.id('transaction_confirmation'))
.scroll(50, 'down');
await element(by.id('transaction_confirmation_submit')).tap();

await waitFor(element(by.id('transaction_finish')))
.toBeVisible()
.withTimeout(15000);

await element(by.id('transaction_finish')).scrollTo('bottom');
await waitFor(element(by.id('transaction_finish_finish')))
.toBeVisible()
.whileElement(by.id('transaction_finish'))
.scroll(50, 'down');
await element(by.id('transaction_finish_finish')).tap();
});
});
21 changes: 14 additions & 7 deletions e2e/4_settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import {by, device, element, expect, waitFor} from 'detox';

import {createWallet} from './helpers/createWallet';
import {ensureWalletIsVisible} from './helpers/ensureWalletIsVisible';
import {launchApp} from './helpers/launchApp';
import {PIN} from './test-variables';

describe('Routine', () => {
const mnemonic_words: string[] = [];

beforeAll(async () => {
await device.launchApp({
newInstance: true,
permissions: {notifications: 'NO'},
});
await launchApp();

await createWallet(PIN);
});
Expand All @@ -27,7 +25,10 @@ describe('Routine', () => {
.scroll(100, 'down');
await element(by.id('recovery_phrase')).tap();

await element(by.id('backup_warning')).scrollTo('bottom');
await waitFor(element(by.id('backup_warning_next')))
.toBeVisible()
.whileElement(by.id('backup_warning'))
.scroll(50, 'down');
await element(by.id('backup_warning_next')).tap();

for (let i = 1; i <= 12; i++) {
Expand All @@ -39,7 +40,10 @@ describe('Routine', () => {
mnemonic_words.push(text);
}

await element(by.id('backup_create')).scrollTo('bottom');
await waitFor(element(by.id('backup_create_checkbox')))
.toBeVisible()
.whileElement(by.id('backup_create'))
.scroll(50, 'down');
await element(by.id('backup_create_checkbox')).tap();
await element(by.id('backup_create_next')).tap();

Expand All @@ -55,7 +59,10 @@ describe('Routine', () => {
await el.tap();
}

await element(by.id('backup_verify')).scrollTo('bottom');
await waitFor(element(by.id('backup_verify_check')))
.toBeVisible()
.whileElement(by.id('backup_verify'))
.scroll(50, 'down');
await element(by.id('backup_verify_check')).tap();

await waitFor(element(by.id('backup_finish')))
Expand Down
14 changes: 6 additions & 8 deletions e2e/5_wallet_reset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {utils} from 'ethers';

import {createWallet} from './helpers/createWallet';
import {ensureWalletIsVisible} from './helpers/ensureWalletIsVisible';
import {launchApp} from './helpers/launchApp';
import {restoreWallet} from './helpers/restoreWallet';
import {PIN} from './test-variables';

Expand All @@ -11,31 +12,28 @@ describe('Reset Wallet', () => {
beforeEach(async () => {
await device.uninstallApp();
await device.installApp();
await device.launchApp({
newInstance: true,
permissions: {notifications: 'NO'},
});
await launchApp();

mnemonic = utils.entropyToMnemonic(utils.randomBytes(32));
});

it('should reset existing wallet', async () => {
await restoreWallet(mnemonic, PIN, 1);
await restoreWallet(mnemonic, PIN);
await ensureWalletIsVisible(mnemonic);
await device.reloadReactNative();
await element(by.id('forgot_the_code')).tap();
await element(by.id('reset_wallet')).tap();
await element(by.label('Reset')).atIndex(0).tap();
await restoreWallet(mnemonic, PIN, 2);
await restoreWallet(mnemonic, PIN);
await ensureWalletIsVisible(mnemonic);
});

it('should reset new wallet', async () => {
await createWallet(PIN, 1);
await createWallet(PIN);
await device.reloadReactNative();
await element(by.id('forgot_the_code')).tap();
await element(by.id('reset_wallet')).tap();
await element(by.label('Reset')).atIndex(0).tap();
await createWallet(PIN, 2);
await createWallet(PIN);
});
});
6 changes: 2 additions & 4 deletions e2e/6_sss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {expect as jestExpect} from '@jest/globals';
import {by, device, element, expect, waitFor} from 'detox';

import {getTimeStamp} from './helpers/getTimeStamp';
import {launchApp} from './helpers/launchApp';
import {PIN} from './test-variables';

describe.skip('SSS Wallet', () => {
Expand All @@ -16,10 +17,7 @@ describe.skip('SSS Wallet', () => {
beforeEach(async () => {
await device.uninstallApp();
await device.installApp();
await device.launchApp({
newInstance: true,
permissions: {notifications: 'NO'},
});
await launchApp();
});

it('should create SSS wallet', async () => {
Expand Down
Loading

0 comments on commit 810f988

Please sign in to comment.