-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Restore wallet cases (#1765)
* 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
1 parent
3b8fa2b
commit 810f988
Showing
20 changed files
with
321 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.