diff --git a/test/e2e/address-book.spec.js b/test/e2e/address-book.spec.js index 6a526edd9ca2..02d391cb4537 100644 --- a/test/e2e/address-book.spec.js +++ b/test/e2e/address-book.spec.js @@ -1,7 +1,11 @@ const assert = require('assert') const { By, until } = require('selenium-webdriver') -const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers') +const { + tinyDelayMs, + regularDelayMs, + largeDelayMs, +} = require('./helpers') const { buildWebDriver } = require('./webdriver') const Ganache = require('./ganache') const enLocaleMessages = require('../../app/_locales/en/messages.json') @@ -11,8 +15,7 @@ const ganacheServer = new Ganache() describe('MetaMask', function () { let driver - const testSeedPhrase = - 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress' + const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress' this.timeout(0) this.bail(true) @@ -21,8 +24,7 @@ describe('MetaMask', function () { await ganacheServer.start({ accounts: [ { - secretKey: - '0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9', + secretKey: '0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9', balance: 25000000000000000000, }, ], @@ -36,9 +38,7 @@ describe('MetaMask', function () { const errors = await driver.checkBrowserForConsoleErrors() if (errors.length) { const errorReports = errors.map(err => err.message) - const errorMessage = `Errors found in browser console:\n${errorReports.join( - '\n' - )}` + const errorMessage = `Errors found in browser console:\n${errorReports.join('\n')}` console.error(new Error(errorMessage)) } } @@ -55,18 +55,12 @@ describe('MetaMask', function () { describe('Going through the first time flow', () => { it('clicks the continue button on the welcome screen', async () => { await driver.findElement(By.css('.welcome-page__header')) - await driver.clickElement( - By.xpath( - `//button[contains(text(), '${enLocaleMessages.getStarted.message}')]` - ) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`)) await driver.delay(largeDelayMs) }) it('clicks the "Create New Wallet" option', async () => { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Create a Wallet')]`) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), 'Create a Wallet')]`)) await driver.delay(largeDelayMs) }) @@ -76,12 +70,8 @@ describe('MetaMask', function () { }) it('accepts a secure password', async () => { - const passwordBox = await driver.findElement( - By.css('.first-time-flow__form #create-password') - ) - const passwordBoxConfirm = await driver.findElement( - By.css('.first-time-flow__form #confirm-password') - ) + const passwordBox = await driver.findElement(By.css('.first-time-flow__form #create-password')) + const passwordBoxConfirm = await driver.findElement(By.css('.first-time-flow__form #confirm-password')) await passwordBox.sendKeys('correct horse battery staple') await passwordBoxConfirm.sendKeys('correct horse battery staple') @@ -94,33 +84,21 @@ describe('MetaMask', function () { let seedPhrase it('reveals the seed phrase', async () => { - const byRevealButton = By.css( - '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button' - ) + const byRevealButton = By.css('.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button') await driver.clickElement(byRevealButton) await driver.delay(regularDelayMs) - const revealedSeedPhrase = await driver.findElement( - By.css('.reveal-seed-phrase__secret-words') - ) + const revealedSeedPhrase = await driver.findElement(By.css('.reveal-seed-phrase__secret-words')) seedPhrase = await revealedSeedPhrase.getText() assert.equal(seedPhrase.split(' ').length, 12) await driver.delay(regularDelayMs) - await driver.clickElement( - By.xpath( - `//button[contains(text(), '${enLocaleMessages.next.message}')]` - ) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.next.message}')]`)) await driver.delay(regularDelayMs) }) async function clickWordAndWait (word) { - await driver.clickElement( - By.css( - `[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]` - ) - ) + await driver.clickElement(By.css(`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`)) await driver.delay(tinyDelayMs) } @@ -131,21 +109,13 @@ describe('MetaMask', function () { await clickWordAndWait(word) } - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), 'Confirm')]`)) await driver.delay(regularDelayMs) }) it('clicks through the success screen', async () => { - await driver.findElement( - By.xpath(`//div[contains(text(), 'Congratulations')]`) - ) - await driver.clickElement( - By.xpath( - `//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]` - ) - ) + await driver.findElement(By.xpath(`//div[contains(text(), 'Congratulations')]`)) + await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`)) await driver.delay(regularDelayMs) }) }) @@ -155,22 +125,15 @@ describe('MetaMask', function () { await driver.clickElement(By.css('.account-menu__icon')) await driver.delay(regularDelayMs) - const lockButton = await driver.findClickableElement( - By.css('.account-menu__lock-button') - ) + const lockButton = await driver.findClickableElement(By.css('.account-menu__lock-button')) assert.equal(await lockButton.getText(), 'Lock') await lockButton.click() await driver.delay(regularDelayMs) }) it('imports seed phrase', async () => { - const restoreSeedLink = await driver.findClickableElement( - By.css('.unlock-page__link--import') - ) - assert.equal( - await restoreSeedLink.getText(), - 'Import using account seed phrase' - ) + const restoreSeedLink = await driver.findClickableElement(By.css('.unlock-page__link--import')) + assert.equal(await restoreSeedLink.getText(), 'Import using account seed phrase') await restoreSeedLink.click() await driver.delay(regularDelayMs) @@ -183,18 +146,12 @@ describe('MetaMask', function () { await passwordInputs[0].sendKeys('correct horse battery staple') await passwordInputs[1].sendKeys('correct horse battery staple') - await driver.clickElement( - By.xpath( - `//button[contains(text(), '${enLocaleMessages.restore.message}')]` - ) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.restore.message}')]`)) await driver.delay(regularDelayMs) }) it('balance renders', async () => { - const balance = await driver.findElement( - By.css('.balance-display .token-amount') - ) + const balance = await driver.findElement(By.css('.balance-display .token-amount')) await driver.wait(until.elementTextMatches(balance, /25\s*ETH/)) await driver.delay(regularDelayMs) }) @@ -205,26 +162,18 @@ describe('MetaMask', function () { await driver.clickElement(By.xpath(`//button[contains(text(), 'Send')]`)) await driver.delay(regularDelayMs) - const inputAddress = await driver.findElement( - By.css('input[placeholder="Search, public address (0x), or ENS"]') - ) + const inputAddress = await driver.findElement(By.css('input[placeholder="Search, public address (0x), or ENS"]')) await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970') await driver.delay(regularDelayMs) await driver.clickElement(By.css('.dialog.send__dialog.dialog--message')) - const addressBookAddModal = await driver.findElement( - By.css('span .modal') - ) + const addressBookAddModal = await driver.findElement(By.css('span .modal')) await driver.findElement(By.css('.add-to-address-book-modal')) - const addressBookInput = await driver.findElement( - By.css('.add-to-address-book-modal__input') - ) + const addressBookInput = await driver.findElement(By.css('.add-to-address-book-modal__input')) await addressBookInput.sendKeys('Test Name 1') await driver.delay(tinyDelayMs) - await driver.clickElement( - By.css('.add-to-address-book-modal__footer .btn-primary') - ) + await driver.clickElement(By.css('.add-to-address-book-modal__footer .btn-primary')) await driver.wait(until.stalenessOf(addressBookAddModal)) @@ -241,25 +190,17 @@ describe('MetaMask', function () { }) it('confirms the transaction', async function () { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), 'Confirm')]`)) await driver.delay(largeDelayMs * 2) }) it('finds the transaction in the transactions list', async function () { await driver.wait(async () => { - const confirmedTxes = await driver.findElements( - By.css( - '.transaction-list__completed-transactions .transaction-list-item' - ) - ) + const confirmedTxes = await driver.findElements(By.css('.transaction-list__completed-transactions .transaction-list-item')) return confirmedTxes.length === 1 }, 10000) - const txValues = await driver.findElement( - By.css('.transaction-list-item__amount--primary') - ) + const txValues = await driver.findElement(By.css('.transaction-list-item__amount--primary')) await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/), 10000) }) }) @@ -269,15 +210,11 @@ describe('MetaMask', function () { await driver.clickElement(By.xpath(`//button[contains(text(), 'Send')]`)) await driver.delay(regularDelayMs) - const recipientRowTitle = await driver.findElement( - By.css('.send__select-recipient-wrapper__group-item__title') - ) + const recipientRowTitle = await driver.findElement(By.css('.send__select-recipient-wrapper__group-item__title')) const recipientRowTitleString = await recipientRowTitle.getText() assert.equal(recipientRowTitleString, 'Test Name 1') - await driver.clickElement( - By.css('.send__select-recipient-wrapper__group-item') - ) + await driver.clickElement(By.css('.send__select-recipient-wrapper__group-item')) await driver.delay(regularDelayMs) const inputAmount = await driver.findElement(By.css('.unit-input__input')) @@ -290,25 +227,17 @@ describe('MetaMask', function () { }) it('confirms the transaction', async function () { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), 'Confirm')]`)) await driver.delay(largeDelayMs * 2) }) it('finds the transaction in the transactions list', async function () { await driver.wait(async () => { - const confirmedTxes = await driver.findElements( - By.css( - '.transaction-list__completed-transactions .transaction-list-item' - ) - ) + const confirmedTxes = await driver.findElements(By.css('.transaction-list__completed-transactions .transaction-list-item')) return confirmedTxes.length === 2 }, 10000) - const txValues = await driver.findElement( - By.css('.transaction-list-item__amount--primary') - ) + const txValues = await driver.findElement(By.css('.transaction-list-item__amount--primary')) await driver.wait(until.elementTextMatches(txValues, /-2\s*ETH/), 10000) }) }) diff --git a/test/e2e/incremental-security.spec.js b/test/e2e/incremental-security.spec.js index f10e76cc32ba..734655b811f5 100644 --- a/test/e2e/incremental-security.spec.js +++ b/test/e2e/incremental-security.spec.js @@ -2,7 +2,11 @@ const assert = require('assert') const webdriver = require('selenium-webdriver') const { By, until } = webdriver -const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers') +const { + tinyDelayMs, + regularDelayMs, + largeDelayMs, +} = require('./helpers') const { buildWebDriver } = require('./webdriver') const Ganache = require('./ganache') const enLocaleMessages = require('../../app/_locales/en/messages.json') @@ -20,13 +24,11 @@ describe('MetaMask', function () { await ganacheServer.start({ accounts: [ { - secretKey: - '0x250F458997A364988956409A164BA4E16F0F99F916ACDD73ADCD3A1DE30CF8D1', + secretKey: '0x250F458997A364988956409A164BA4E16F0F99F916ACDD73ADCD3A1DE30CF8D1', balance: 0, }, { - secretKey: - '0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9', + secretKey: '0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9', balance: 25000000000000000000, }, ], @@ -40,9 +42,7 @@ describe('MetaMask', function () { const errors = await driver.checkBrowserForConsoleErrors(driver) if (errors.length) { const errorReports = errors.map(err => err.message) - const errorMessage = `Errors found in browser console:\n${errorReports.join( - '\n' - )}` + const errorMessage = `Errors found in browser console:\n${errorReports.join('\n')}` console.error(new Error(errorMessage)) } } @@ -59,18 +59,12 @@ describe('MetaMask', function () { describe('Going through the first time flow, but skipping the seed phrase challenge', () => { it('clicks the continue button on the welcome screen', async () => { await driver.findElement(By.css('.welcome-page__header')) - await driver.clickElement( - By.xpath( - `//button[contains(text(), '${enLocaleMessages.getStarted.message}')]` - ) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`)) await driver.delay(largeDelayMs) }) it('clicks the "Create New Wallet" option', async () => { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Create a Wallet')]`) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), 'Create a Wallet')]`)) await driver.delay(largeDelayMs) }) @@ -80,12 +74,8 @@ describe('MetaMask', function () { }) it('accepts a secure password', async () => { - const passwordBox = await driver.findElement( - By.css('.first-time-flow__form #create-password') - ) - const passwordBoxConfirm = await driver.findElement( - By.css('.first-time-flow__form #confirm-password') - ) + const passwordBox = await driver.findElement(By.css('.first-time-flow__form #create-password')) + const passwordBoxConfirm = await driver.findElement(By.css('.first-time-flow__form #confirm-password')) await passwordBox.sendKeys('correct horse battery staple') await passwordBoxConfirm.sendKeys('correct horse battery staple') @@ -97,11 +87,7 @@ describe('MetaMask', function () { }) it('skips the seed phrase challenge', async () => { - await driver.clickElement( - By.xpath( - `//button[contains(text(), '${enLocaleMessages.remindMeLater.message}')]` - ) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.remindMeLater.message}')]`)) await driver.delay(regularDelayMs) await driver.clickElement(By.css('.account-details__details-button')) @@ -119,6 +105,7 @@ describe('MetaMask', function () { await driver.wait(until.stalenessOf(accountModal)) await driver.delay(regularDelayMs) }) + }) describe('send to current account from dapp with different provider', () => { @@ -148,9 +135,7 @@ describe('MetaMask', function () { }) it('should have the correct amount of eth', async () => { - const balances = await driver.findElements( - By.css('.currency-display-component__text') - ) + const balances = await driver.findElements(By.css('.currency-display-component__text')) await driver.wait(until.elementTextMatches(balances[0], /1/), 15000) const balance = await balances[0].getText() @@ -160,11 +145,7 @@ describe('MetaMask', function () { describe('backs up the seed phrase', () => { it('should show a backup reminder', async () => { - const backupReminder = await driver.findElements( - By.xpath( - "//div[contains(@class, 'home-notification__text') and contains(text(), 'Backup your Secret Recovery code to keep your wallet and funds secure')]" - ) - ) + const backupReminder = await driver.findElements(By.xpath("//div[contains(@class, 'home-notification__text') and contains(text(), 'Backup your Secret Recovery code to keep your wallet and funds secure')]")) assert.equal(backupReminder.length, 1) }) @@ -176,33 +157,21 @@ describe('MetaMask', function () { let seedPhrase it('reveals the seed phrase', async () => { - const byRevealButton = By.css( - '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button' - ) + const byRevealButton = By.css('.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button') await driver.clickElement(byRevealButton) await driver.delay(regularDelayMs) - const revealedSeedPhrase = await driver.findElement( - By.css('.reveal-seed-phrase__secret-words') - ) + const revealedSeedPhrase = await driver.findElement(By.css('.reveal-seed-phrase__secret-words')) seedPhrase = await revealedSeedPhrase.getText() assert.equal(seedPhrase.split(' ').length, 12) await driver.delay(regularDelayMs) - await driver.clickElement( - By.xpath( - `//button[contains(text(), '${enLocaleMessages.next.message}')]` - ) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.next.message}')]`)) await driver.delay(regularDelayMs) }) async function clickWordAndWait (word) { - await driver.clickElement( - By.css( - `[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]` - ) - ) + await driver.clickElement(By.css(`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`)) await driver.delay(tinyDelayMs) } @@ -213,23 +182,17 @@ describe('MetaMask', function () { await clickWordAndWait(word) } - await driver.clickElement( - By.xpath(`//button[contains(text(), 'Confirm')]`) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), 'Confirm')]`)) await driver.delay(regularDelayMs) }) it('can click through the success screen', async () => { - await driver.clickElement( - By.xpath(`//button[contains(text(), 'All Done')]`) - ) + await driver.clickElement(By.xpath(`//button[contains(text(), 'All Done')]`)) await driver.delay(regularDelayMs) }) it('should have the correct amount of eth', async () => { - const balances = await driver.findElements( - By.css('.currency-display-component__text') - ) + const balances = await driver.findElements(By.css('.currency-display-component__text')) await driver.wait(until.elementTextMatches(balances[0], /1/), 15000) const balance = await balances[0].getText() diff --git a/test/e2e/metamask-responsive-ui.spec.js b/test/e2e/metamask-responsive-ui.spec.js index 8993daae3ee8..b28a54bc934b 100644 --- a/test/e2e/metamask-responsive-ui.spec.js +++ b/test/e2e/metamask-responsive-ui.spec.js @@ -110,11 +110,7 @@ describe('MetaMask', function () { }) async function clickWordAndWait (word) { - await driver.clickElement( - By.css( - `[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]` - ) - ) + await driver.clickElement(By.css(`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`)) await driver.delay(tinyDelayMs) } diff --git a/test/e2e/metamask-ui.spec.js b/test/e2e/metamask-ui.spec.js index 43ed035fb470..06fc90bcc68e 100644 --- a/test/e2e/metamask-ui.spec.js +++ b/test/e2e/metamask-ui.spec.js @@ -120,11 +120,7 @@ describe('MetaMask', function () { }) async function clickWordAndWait (word) { - await driver.clickElement( - By.css( - `[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]` - ) - ) + await driver.clickElement(By.css(`[data-testid="seed-phrase-sorted"] [data-testid="draggable-seed-${word}"]`)) await driver.delay(tinyDelayMs) } diff --git a/ui/app/pages/first-time-flow/seed-phrase/confirm-seed-phrase/confirm-seed-phrase.component.js b/ui/app/pages/first-time-flow/seed-phrase/confirm-seed-phrase/confirm-seed-phrase.component.js index 8977de233282..4296803d0616 100644 --- a/ui/app/pages/first-time-flow/seed-phrase/confirm-seed-phrase/confirm-seed-phrase.component.js +++ b/ui/app/pages/first-time-flow/seed-phrase/confirm-seed-phrase/confirm-seed-phrase.component.js @@ -1,7 +1,6 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' -import { shuffle } from 'lodash' import Button from '../../../../components/ui/button' import { INITIALIZE_END_OF_FLOW_ROUTE, @@ -34,7 +33,7 @@ export default class ConfirmSeedPhrase extends PureComponent { state = { selectedSeedIndices: [], - shuffledSeedWords: [], + sortedSeedWords: [], pendingSeedIndices: [], draggingSeedIndex: -1, hoveringIndex: -1, @@ -42,8 +41,8 @@ export default class ConfirmSeedPhrase extends PureComponent { componentDidMount () { const { seedPhrase = '' } = this.props - const shuffledSeedWords = shuffle(seedPhrase.split(' ')) || [] - this.setState({ shuffledSeedWords }) + const sortedSeedWords = (seedPhrase.split(' ') || []).sort() + this.setState({ sortedSeedWords }) } setDraggingSeedIndex = draggingSeedIndex => @@ -109,28 +108,24 @@ export default class ConfirmSeedPhrase extends PureComponent { } } - handleSelectSeedWord = shuffledIndex => { + handleSelectSeedWord = (index) => { this.setState({ - selectedSeedIndices: [...this.state.selectedSeedIndices, shuffledIndex], - pendingSeedIndices: [...this.state.pendingSeedIndices, shuffledIndex], + selectedSeedIndices: [...this.state.selectedSeedIndices, index], + pendingSeedIndices: [...this.state.pendingSeedIndices, index], }) } - handleDeselectSeedWord = shuffledIndex => { + handleDeselectSeedWord = (index) => { this.setState({ - selectedSeedIndices: this.state.selectedSeedIndices.filter( - i => shuffledIndex !== i - ), - pendingSeedIndices: this.state.pendingSeedIndices.filter( - i => shuffledIndex !== i - ), + selectedSeedIndices: this.state.selectedSeedIndices.filter(i => index !== i), + pendingSeedIndices: this.state.pendingSeedIndices.filter(i => index !== i), }) } isValid () { const { seedPhrase } = this.props - const { selectedSeedIndices, shuffledSeedWords } = this.state - const selectedSeedWords = selectedSeedIndices.map(i => shuffledSeedWords[i]) + const { selectedSeedIndices, sortedSeedWords } = this.state + const selectedSeedWords = selectedSeedIndices.map(i => sortedSeedWords[i]) return seedPhrase === selectedSeedWords.join(' ') } @@ -139,7 +134,7 @@ export default class ConfirmSeedPhrase extends PureComponent { const { history } = this.props const { selectedSeedIndices, - shuffledSeedWords, + sortedSeedWords, draggingSeedIndex, } = this.state @@ -171,33 +166,32 @@ export default class ConfirmSeedPhrase extends PureComponent { {this.renderPendingSeeds()} {this.renderSelectedSeeds()} -
- {shuffledSeedWords.map((word, index) => { - const isSelected = selectedSeedIndices.includes(index) - - return ( - { - if (!isSelected) { - this.handleSelectSeedWord(index) - } else { - this.handleDeselectSeedWord(index) - } - }} - word={word} - /> - ) - })} +
+ { + sortedSeedWords.map((word, index) => { + const isSelected = selectedSeedIndices.includes(index) + + return ( + { + if (!isSelected) { + this.handleSelectSeedWord(index) + } else { + this.handleDeselectSeedWord(index) + } + }} + word={word} + /> + ) + }) + }