Skip to content

Commit

Permalink
Merge branch 'develop' into 17191/onboarding-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmashuang authored Mar 17, 2023
2 parents 5789476 + d45c4ed commit 9e48191
Show file tree
Hide file tree
Showing 21 changed files with 869 additions and 357 deletions.
3 changes: 3 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ addParameters({
],
},
},
controls: {
expanded: true,
},
});

export const globalTypes = {
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/controllers/network/network-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export default class NetworkController extends EventEmitter {

rollbackToPreviousProvider() {
const config = this.previousProviderStore.getState();
this.providerStore.updateState(config);
this.providerStore.putState(config);
this._switchNetwork(config);
}

Expand Down Expand Up @@ -347,7 +347,7 @@ export default class NetworkController extends EventEmitter {
* @param {boolean} isSupported - True if the EIP is supported
*/
_setNetworkEIPSupport(EIPNumber, isSupported) {
this.networkDetails.updateState({
this.networkDetails.putState({
EIPS: {
[EIPNumber]: isSupported,
},
Expand All @@ -367,8 +367,8 @@ export default class NetworkController extends EventEmitter {
* @param config
*/
_setProviderConfig(config) {
this.previousProviderStore.updateState(this.providerStore.getState());
this.providerStore.updateState(config);
this.previousProviderStore.putState(this.providerStore.getState());
this.providerStore.putState(config);
this._switchNetwork(config);
}

Expand Down Expand Up @@ -550,7 +550,7 @@ export default class NetworkController extends EventEmitter {
)?.id;

const newNetworkConfigurationId = oldNetworkConfigurationId || random();
this.networkConfigurationsStore.updateState({
this.networkConfigurationsStore.putState({
...networkConfigurations,
[newNetworkConfigurationId]: {
...newNetworkConfiguration,
Expand Down
9 changes: 3 additions & 6 deletions app/scripts/controllers/network/network-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3218,7 +3218,6 @@ describe('NetworkController', () => {
blockExplorerUrl:
BUILT_IN_NETWORKS[networkType].blockExplorerUrl,
},
id: 'testNetworkConfigurationId2',
});
},
);
Expand Down Expand Up @@ -4213,7 +4212,7 @@ describe('NetworkController', () => {
networkVersion,
} of INFURA_NETWORKS) {
describe(`if the previous provider configuration had a type of "${networkType}"`, () => {
it('merges the previous configuration into the current provider configuration', async () => {
it('overwrites the the current provider configuration with the previous provider configuration', async () => {
await withController(
{
state: {
Expand Down Expand Up @@ -4295,7 +4294,6 @@ describe('NetworkController', () => {
chainId: BUILT_IN_NETWORKS[networkType].chainId,
ticker: BUILT_IN_NETWORKS[networkType].ticker,
nickname: '',
id: 'testNetworkConfigurationId1',
rpcPrefs: {
blockExplorerUrl:
BUILT_IN_NETWORKS[networkType].blockExplorerUrl,
Expand Down Expand Up @@ -4871,7 +4869,7 @@ describe('NetworkController', () => {
}

describe(`if the previous provider configuration had a type of "rpc"`, () => {
it('merges the previous configuration into the current provider configuration', async () => {
it('overwrites the the current provider configuration with the previous provider configuration', async () => {
await withController(
{
state: {
Expand Down Expand Up @@ -4940,7 +4938,6 @@ describe('NetworkController', () => {
rpcPrefs: {
blockExplorerUrl: 'https://goerli.etherscan.io',
},
id: 'testNetworkConfigurationId2',
});

await waitForLookupNetworkToComplete({
Expand All @@ -4953,8 +4950,8 @@ describe('NetworkController', () => {
type: 'rpc',
rpcUrl: 'https://mock-rpc-url-2',
chainId: '0x1337',
ticker: 'TEST2',
nickname: 'test-chain-2',
ticker: 'TEST2',
rpcPrefs: {
blockExplorerUrl: 'test-block-explorer-2.com',
},
Expand Down
92 changes: 91 additions & 1 deletion shared/constants/snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,103 @@ type SnapsDerivationPath = {
export const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [
{
path: ['m', `44'`, `0'`],
curve: 'ed25519',
name: 'Test BIP-32 Path (ed25519)',
},
{
path: ['m', `44'`, `1'`],
curve: 'secp256k1',
name: 'Test BIP-32 Path (secp256k1)',
},
{
path: ['m', `44'`, `0'`],
curve: 'secp256k1',
name: 'Bitcoin Legacy',
},
{
path: ['m', `49'`, `0'`],
curve: 'secp256k1',
name: 'Bitcoin Nested SegWit',
},
{
path: ['m', `49'`, `1'`],
curve: 'secp256k1',
name: 'Bitcoin Testnet Nested SegWit',
},
{
path: ['m', `84'`, `0'`],
curve: 'secp256k1',
name: 'Bitcoin Native SegWit',
},
{
path: ['m', `84'`, `1'`],
curve: 'secp256k1',
name: 'Bitcoin Testnet Native SegWit',
},
{
path: ['m', `44'`, `501'`],
curve: 'secp256k1',
name: 'Solana',
},
{
path: ['m', `44'`, `2'`],
curve: 'secp256k1',
name: 'Litecoin',
},
{
path: ['m', `44'`, `3'`],
curve: 'secp256k1',
name: 'Dogecoin',
},
{
path: ['m', `44'`, `60'`],
curve: 'secp256k1',
name: 'Ethereum',
},
{
path: ['m', `44'`, `118'`],
curve: 'secp256k1',
name: 'Atom',
},
{
path: ['m', `44'`, `145'`],
curve: 'secp256k1',
name: 'Bitcoin Cash',
},
{
path: ['m', `44'`, `714'`],
curve: 'secp256k1',
name: 'Binance (BNB)',
},
{
path: ['m', `44'`, `931'`],
curve: 'secp256k1',
name: 'THORChain (RUNE)',
},
{
path: ['m', `44'`, `330'`],
curve: 'secp256k1',
name: 'Terra (LUNA)',
},
{
path: ['m', `44'`, `459'`],
curve: 'secp256k1',
name: 'Kava',
},
{
path: ['m', `44'`, `529'`],
curve: 'secp256k1',
name: 'Secret Network',
},
{
path: ['m', `44'`, `397'`],
curve: 'ed25519',
name: 'Test BIP-32 Path (ed25519)',
name: 'NEAR Protocol',
},
{
path: ['m', `44'`, `1'`, `0'`],
curve: 'ed25519',
name: 'NEAR Protocol Testnet',
},
];
///: END:ONLY_INCLUDE_IN
89 changes: 89 additions & 0 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { strict: assert } = require('assert');
const path = require('path');
const { promises: fs } = require('fs');
const BigNumber = require('bignumber.js');
Expand Down Expand Up @@ -289,6 +290,91 @@ const completeImportSRPOnboardingFlowWordByWord = async (
await driver.clickElement('[data-testid="pin-extension-done"]');
};

const completeCreateNewWalletOnboardingFlow = async (driver, password) => {
// welcome
await driver.clickElement('[data-testid="onboarding-create-wallet"]');

// metrics
await driver.clickElement('[data-testid="metametrics-no-thanks"]');

// create password
await driver.fill('[data-testid="create-password-new"]', password);
await driver.fill('[data-testid="create-password-confirm"]', password);
await driver.clickElement('[data-testid="create-password-terms"]');
await driver.clickElement('[data-testid="create-password-wallet"]');

// secure my wallet
await driver.clickElement('[data-testid="secure-wallet-recommended"]');

// reveal SRP
await driver.clickElement('[data-testid="recovery-phrase-reveal"]');

const revealedSeedPhrase = await driver.findElement(
'[data-testid="recovery-phrase-chips"]',
);

const recoveryPhrase = await revealedSeedPhrase.getText();

await driver.clickElement('[data-testid="recovery-phrase-next"]');

// confirm SRP
const words = recoveryPhrase.split(/\s*(?:[0-9)]+|\n|\.|^$|$)\s*/u);
const finalWords = words.filter((str) => str !== '');
assert.equal(finalWords.length, 12);

await driver.fill('[data-testid="recovery-phrase-input-2"]', finalWords[2]);
await driver.fill('[data-testid="recovery-phrase-input-3"]', finalWords[3]);
await driver.fill('[data-testid="recovery-phrase-input-7"]', finalWords[7]);

await driver.clickElement('[data-testid="confirm-recovery-phrase"]');

await driver.clickElement({ text: 'Confirm', tag: 'button' });

// complete
await driver.findElement({ text: 'Wallet creation successful', tag: 'h2' });
await driver.clickElement('[data-testid="onboarding-complete-done"]');

// pin extension
await driver.clickElement('[data-testid="pin-extension-next"]');
await driver.clickElement('[data-testid="pin-extension-done"]');
};

const importWrongSRPOnboardingFlow = async (driver, seedPhrase) => {
// welcome
await driver.clickElement('[data-testid="onboarding-import-wallet"]');

// metrics
await driver.clickElement('[data-testid="metametrics-no-thanks"]');

// import with recovery phrase
await driver.pasteIntoField(
'[data-testid="import-srp__srp-word-0"]',
seedPhrase,
);

const warningText = 'Invalid Secret Recovery Phrase';
const warnings = await driver.findElements('.actionable-message__message');
const warning = warnings[1];

assert.equal(await warning.getText(), warningText);
};

const selectDropdownByNum = async (elements, index) => {
await elements[index].click();
};

const testSRPDropdownIterations = async (options, driver, iterations) => {
for (let i = 0; i < iterations; i++) {
await selectDropdownByNum(options, i);
await new Promise((resolve) => setTimeout(resolve, 1000));

const formFields = await driver.findElements('.import-srp__srp-word-label');
const expectedNumFields = 12 + i * 3;
const actualNumFields = formFields.length;
assert.equal(actualNumFields, expectedNumFields);
}
};

module.exports = {
getWindowHandles,
convertToHexValue,
Expand All @@ -300,5 +386,8 @@ module.exports = {
importSRPOnboardingFlow,
completeImportSRPOnboardingFlow,
completeImportSRPOnboardingFlowWordByWord,
completeCreateNewWalletOnboardingFlow,
createDownloadFolder,
importWrongSRPOnboardingFlow,
testSRPDropdownIterations,
};
Loading

0 comments on commit 9e48191

Please sign in to comment.