add e2e test for deterministic account address generation (#13668)

* add e2e test for deterministic account address generation

* extract import srp onboarding flow into helper function
feature/default_network_editable
Alex Donesky 3 years ago committed by GitHub
parent a0602f1c0e
commit 93dd85fb2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 68
      test/e2e/helpers.js
  2. 163
      test/e2e/tests/add-account.spec.js
  3. 72
      test/e2e/tests/from-import-ui.spec.js

@ -7,6 +7,7 @@ const {
createSegmentServer, createSegmentServer,
} = require('../../development/lib/create-segment-server'); } = require('../../development/lib/create-segment-server');
const { setupMocking } = require('../../development/mock-e2e'); const { setupMocking } = require('../../development/mock-e2e');
const enLocaleMessages = require('../../app/_locales/en/messages.json');
const Ganache = require('./ganache'); const Ganache = require('./ganache');
const FixtureServer = require('./fixture-server'); const FixtureServer = require('./fixture-server');
const { buildWebDriver } = require('./webdriver'); const { buildWebDriver } = require('./webdriver');
@ -206,6 +207,72 @@ const connectDappWithExtensionPopup = async (driver) => {
await driver.delay(regularDelayMs); await driver.delay(regularDelayMs);
}; };
const completeImportSRPOnboardingFlow = async (
driver,
seedPhrase,
password,
) => {
if (process.env.ONBOARDING_V2 === '1') {
// welcome
await driver.clickElement('[data-testid="onboarding-import-wallet"]');
// metrics
await driver.clickElement('[data-testid="metametrics-no-thanks"]');
// import with recovery phrase
await driver.fill('[data-testid="import-srp-text"]', seedPhrase);
await driver.clickElement('[data-testid="import-srp-confirm"]');
// 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-import"]');
// complete
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"]');
} else {
// clicks the continue button on the welcome screen
await driver.findElement('.welcome-page__header');
await driver.clickElement({
text: enLocaleMessages.getStarted.message,
tag: 'button',
});
// clicks the "Import Wallet" option
await driver.clickElement({ text: 'Import wallet', tag: 'button' });
// clicks the "No thanks" option on the metametrics opt-in screen
await driver.clickElement('.btn-secondary');
// Import Secret Recovery Phrase
await driver.fill(
'input[placeholder="Enter your Secret Recovery Phrase"]',
seedPhrase,
);
await driver.fill('#password', password);
await driver.fill('#confirm-password', password);
await driver.clickElement(
'[data-testid="create-new-vault__terms-checkbox"]',
);
await driver.clickElement({ text: 'Import', tag: 'button' });
// clicks through the success screen
await driver.findElement({ text: 'Congratulations', tag: 'div' });
await driver.clickElement({
text: enLocaleMessages.endOfFlowMessage10.message,
tag: 'button',
});
}
};
module.exports = { module.exports = {
getWindowHandles, getWindowHandles,
convertToHexValue, convertToHexValue,
@ -214,4 +281,5 @@ module.exports = {
largeDelayMs, largeDelayMs,
withFixtures, withFixtures,
connectDappWithExtensionPopup, connectDappWithExtensionPopup,
completeImportSRPOnboardingFlow,
}; };

@ -1,16 +1,26 @@
const { strict: assert } = require('assert'); const { strict: assert } = require('assert');
const { convertToHexValue, withFixtures } = require('../helpers'); const {
convertToHexValue,
withFixtures,
regularDelayMs,
completeImportSRPOnboardingFlow,
} = require('../helpers');
const enLocaleMessages = require('../../../app/_locales/en/messages.json');
describe('Add account', function () { describe('Add account', function () {
const testSeedPhrase =
'forum vessel pink push lonely enact gentle tail admit parrot grunt dress';
const testPassword = 'correct horse battery staple';
const ganacheOptions = { const ganacheOptions = {
accounts: [ accounts: [
{ {
secretKey: secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', '0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9',
balance: convertToHexValue(25000000000000000000), balance: convertToHexValue(25000000000000000000),
}, },
], ],
}; };
it('should display correct new account name after create', async function () { it('should display correct new account name after create', async function () {
await withFixtures( await withFixtures(
{ {
@ -36,4 +46,153 @@ describe('Add account', function () {
}, },
); );
}); });
it('should add the same account addresses when a secret recovery phrase is imported, the account is locked, and the same secret recovery phrase is imported again', async function () {
await withFixtures(
{
fixtures: 'onboarding',
ganacheOptions,
title: this.test.title,
failOnConsoleError: false,
},
async ({ driver }) => {
await driver.navigate();
await completeImportSRPOnboardingFlow(
driver,
testSeedPhrase,
testPassword,
);
await driver.clickElement('.account-menu__icon');
await driver.clickElement({ text: 'Create Account', tag: 'div' });
await driver.fill('.new-account-create-form input', '2nd account');
await driver.clickElement({ text: 'Create', tag: 'button' });
await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);
await driver.clickElement(
'[data-testid="account-options-menu__account-details"]',
);
const detailsModal = await driver.findVisibleElement('span .modal');
// get the public address for the "second account"
const secondAccountAddress = await driver.findElement(
'.qr-code__address',
);
const secondAccountPublicAddress = await secondAccountAddress.getText();
await driver.clickElement('.account-modal__close');
await detailsModal.waitForElementState('hidden');
// generate a third accound
await driver.clickElement('.account-menu__icon');
await driver.clickElement({ text: 'Create Account', tag: 'div' });
await driver.fill('.new-account-create-form input', '3rd account');
await driver.clickElement({ text: 'Create', tag: 'button' });
await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);
await driver.clickElement(
'[data-testid="account-options-menu__account-details"]',
);
// get the public address for the "third account"
const secondDetailsModal = await driver.findVisibleElement(
'span .modal',
);
const thirdAccountAddress = await driver.findElement(
'.qr-code__address',
);
const thirdAccountPublicAddress = await thirdAccountAddress.getText();
await driver.clickElement('.account-modal__close');
await secondDetailsModal.waitForElementState('hidden');
// lock account
await driver.clickElement('.account-menu__icon');
await driver.delay(regularDelayMs);
const lockButton = await driver.findClickableElement(
'.account-menu__lock-button',
);
await lockButton.click();
await driver.delay(regularDelayMs);
// restore same seed phrase
const restoreSeedLink = await driver.findClickableElement(
'.unlock-page__link--import',
);
await restoreSeedLink.click();
await driver.delay(regularDelayMs);
await driver.fill(
'input[placeholder="Enter your Secret Recovery Phrase"]',
testSeedPhrase,
);
await driver.delay(regularDelayMs);
await driver.fill('#password', 'correct horse battery staple');
await driver.fill('#confirm-password', 'correct horse battery staple');
await driver.clickElement({
text: enLocaleMessages.restore.message,
tag: 'button',
});
await driver.delay(regularDelayMs);
// recreate a "2nd account"
await driver.clickElement('.account-menu__icon');
await driver.clickElement({ text: 'Create Account', tag: 'div' });
await driver.fill('.new-account-create-form input', '2nd account');
await driver.clickElement({ text: 'Create', tag: 'button' });
await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);
await driver.clickElement(
'[data-testid="account-options-menu__account-details"]',
);
const thirdDetailsModal = await driver.findVisibleElement(
'span .modal',
);
// get the public address for the "second account"
const recreatedSecondAccountAddress = await driver.findElement(
'.qr-code__address',
);
assert.equal(
await recreatedSecondAccountAddress.getText(),
secondAccountPublicAddress,
);
await driver.clickElement('.account-modal__close');
await thirdDetailsModal.waitForElementState('hidden');
// re-generate a third accound
await driver.clickElement('.account-menu__icon');
await driver.clickElement({ text: 'Create Account', tag: 'div' });
await driver.fill('.new-account-create-form input', '3rd account');
await driver.clickElement({ text: 'Create', tag: 'button' });
await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);
await driver.clickElement(
'[data-testid="account-options-menu__account-details"]',
);
// get the public address for the "third account"
const recreatedThirdAccountAddress = await driver.findElement(
'.qr-code__address',
);
assert.strictEqual(
await recreatedThirdAccountAddress.getText(),
thirdAccountPublicAddress,
);
},
);
});
}); });

@ -4,8 +4,8 @@ const {
withFixtures, withFixtures,
regularDelayMs, regularDelayMs,
largeDelayMs, largeDelayMs,
completeImportSRPOnboardingFlow,
} = require('../helpers'); } = require('../helpers');
const enLocaleMessages = require('../../../app/_locales/en/messages.json');
describe('Metamask Import UI', function () { describe('Metamask Import UI', function () {
it('Importing wallet using Secret Recovery Phrase', async function () { it('Importing wallet using Secret Recovery Phrase', async function () {
@ -20,6 +20,7 @@ describe('Metamask Import UI', function () {
}; };
const testSeedPhrase = const testSeedPhrase =
'forum vessel pink push lonely enact gentle tail admit parrot grunt dress'; 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress';
const testPassword = 'correct horse battery staple';
const testAddress = '0x0Cc5261AB8cE458dc977078A3623E2BaDD27afD3'; const testAddress = '0x0Cc5261AB8cE458dc977078A3623E2BaDD27afD3';
await withFixtures( await withFixtures(
@ -32,75 +33,12 @@ describe('Metamask Import UI', function () {
async ({ driver }) => { async ({ driver }) => {
await driver.navigate(); await driver.navigate();
if (process.env.ONBOARDING_V2 === '1') { await completeImportSRPOnboardingFlow(
// welcome driver,
await driver.clickElement('[data-testid="onboarding-import-wallet"]');
// metrics
await driver.clickElement('[data-testid="metametrics-no-thanks"]');
// import with recovery phrase
await driver.fill('[data-testid="import-srp-text"]', testSeedPhrase);
await driver.clickElement('[data-testid="import-srp-confirm"]');
// create password
await driver.fill(
'[data-testid="create-password-new"]',
'correct horse battery staple',
);
await driver.fill(
'[data-testid="create-password-confirm"]',
'correct horse battery staple',
);
await driver.clickElement('[data-testid="create-password-terms"]');
await driver.clickElement('[data-testid="create-password-import"]');
// complete
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"]');
} else {
// clicks the continue button on the welcome screen
await driver.findElement('.welcome-page__header');
await driver.clickElement({
text: enLocaleMessages.getStarted.message,
tag: 'button',
});
// clicks the "Import Wallet" option
await driver.clickElement({ text: 'Import wallet', tag: 'button' });
// clicks the "No thanks" option on the metametrics opt-in screen
await driver.clickElement('.btn-secondary');
// Import Secret Recovery Phrase
await driver.fill(
'input[placeholder="Enter your Secret Recovery Phrase"]',
testSeedPhrase, testSeedPhrase,
testPassword,
); );
await driver.fill('#password', 'correct horse battery staple');
await driver.fill(
'#confirm-password',
'correct horse battery staple',
);
await driver.clickElement(
'[data-testid="create-new-vault__terms-checkbox"]',
);
await driver.clickElement({ text: 'Import', tag: 'button' });
// clicks through the success screen
await driver.findElement({ text: 'Congratulations', tag: 'div' });
await driver.clickElement({
text: enLocaleMessages.endOfFlowMessage10.message,
tag: 'button',
});
}
// Show account information // Show account information
await driver.clickElement( await driver.clickElement(
'[data-testid="account-options-menu-button"]', '[data-testid="account-options-menu-button"]',

Loading…
Cancel
Save