2019-08-02 05:57:26 +02:00
const assert = require ( 'assert' )
const webdriver = require ( 'selenium-webdriver' )
2020-01-09 04:34:58 +01:00
2019-08-02 05:57:26 +02:00
const { By , until } = webdriver
2020-08-18 21:18:25 +02:00
const enLocaleMessages = require ( '../../app/_locales/en/messages.json' )
2019-08-02 05:57:26 +02:00
const {
2020-01-13 16:07:32 +01:00
tinyDelayMs ,
regularDelayMs ,
largeDelayMs ,
2019-08-02 05:57:26 +02:00
} = require ( './helpers' )
2020-01-14 18:34:38 +01:00
const { buildWebDriver } = require ( './webdriver' )
2019-12-09 15:40:43 +01:00
const Ganache = require ( './ganache' )
2019-08-02 05:57:26 +02:00
2019-12-09 15:40:43 +01:00
const ganacheServer = new Ganache ( )
2019-08-02 05:57:26 +02:00
describe ( 'MetaMask' , function ( ) {
let driver
let publicAddress
this . timeout ( 0 )
this . bail ( true )
before ( async function ( ) {
2019-12-09 15:40:43 +01:00
await ganacheServer . start ( {
accounts : [
{
secretKey : '0x250F458997A364988956409A164BA4E16F0F99F916ACDD73ADCD3A1DE30CF8D1' ,
balance : 0 ,
} ,
{
secretKey : '0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9' ,
balance : 25000000000000000000 ,
} ,
] ,
} )
2020-01-14 18:34:38 +01:00
const result = await buildWebDriver ( )
2019-09-07 09:13:58 +02:00
driver = result . driver
2019-08-02 05:57:26 +02:00
} )
afterEach ( async function ( ) {
if ( process . env . SELENIUM _BROWSER === 'chrome' ) {
2020-01-13 16:07:32 +01:00
const errors = await driver . checkBrowserForConsoleErrors ( driver )
2019-08-02 05:57:26 +02:00
if ( errors . length ) {
2020-02-15 21:34:12 +01:00
const errorReports = errors . map ( ( err ) => err . message )
2019-08-02 05:57:26 +02:00
const errorMessage = ` Errors found in browser console: \n ${ errorReports . join ( '\n' ) } `
console . error ( new Error ( errorMessage ) )
}
}
if ( this . currentTest . state === 'failed' ) {
2020-07-09 17:01:14 +02:00
await driver . verboseReportOnFailure ( this . currentTest . title )
2019-08-02 05:57:26 +02:00
}
} )
after ( async function ( ) {
2019-12-09 15:40:43 +01:00
await ganacheServer . quit ( )
2019-08-02 05:57:26 +02:00
await driver . quit ( )
} )
2020-02-11 17:51:13 +01:00
describe ( 'Going through the first time flow, but skipping the seed phrase challenge' , function ( ) {
it ( 'clicks the continue button on the welcome screen' , async function ( ) {
2020-01-13 16:07:32 +01:00
await driver . findElement ( By . css ( '.welcome-page__header' ) )
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . xpath ( ` //button[contains(text(), ' ${ enLocaleMessages . getStarted . message } ')] ` ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( largeDelayMs )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'clicks the "Create New Wallet" option' , async function ( ) {
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . xpath ( ` //button[contains(text(), 'Create a Wallet')] ` ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( largeDelayMs )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'clicks the "No thanks" option on the metametrics opt-in screen' , async function ( ) {
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . css ( '.btn-default' ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( largeDelayMs )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'accepts a secure password' , async function ( ) {
2020-01-13 16:07:32 +01:00
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' ) )
2019-08-02 05:57:26 +02:00
await passwordBox . sendKeys ( 'correct horse battery staple' )
await passwordBoxConfirm . sendKeys ( 'correct horse battery staple' )
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . css ( '.first-time-flow__checkbox' ) )
2019-08-02 05:57:26 +02:00
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . css ( '.first-time-flow__form button' ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'skips the seed phrase challenge' , async function ( ) {
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . xpath ( ` //button[contains(text(), ' ${ enLocaleMessages . remindMeLater . message } ')] ` ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
2020-05-27 22:28:33 +02:00
await driver . clickElement ( By . css ( '[data-testid="account-options-menu-button"]' ) )
await driver . clickElement ( By . css ( '[data-testid="account-options-menu__account-details"]' ) )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'gets the current accounts address' , async function ( ) {
2020-08-07 17:58:48 +02:00
const addressInput = await driver . findElement ( By . css ( '.readonly-input__input' ) )
2019-08-02 05:57:26 +02:00
publicAddress = await addressInput . getAttribute ( 'value' )
const accountModal = await driver . findElement ( By . css ( 'span .modal' ) )
2020-08-11 18:07:47 +02:00
await driver . clickElement ( By . css ( '.account-modal__close' ) )
2019-08-02 05:57:26 +02:00
await driver . wait ( until . stalenessOf ( accountModal ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
} )
} )
2020-02-11 17:51:13 +01:00
describe ( 'send to current account from dapp with different provider' , function ( ) {
2019-08-02 05:57:26 +02:00
let extension
2020-02-11 17:51:13 +01:00
it ( 'switches to dapp screen' , async function ( ) {
2019-08-02 05:57:26 +02:00
const windowHandles = await driver . getAllWindowHandles ( )
extension = windowHandles [ 0 ]
2020-01-13 16:07:32 +01:00
await driver . openNewPage ( 'http://127.0.0.1:8080/' )
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'sends eth to the current account' , async function ( ) {
2020-01-13 16:07:32 +01:00
const addressInput = await driver . findElement ( By . css ( '#address' ) )
2019-08-02 05:57:26 +02:00
await addressInput . sendKeys ( publicAddress )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . css ( '#send' ) )
2019-08-02 05:57:26 +02:00
2020-01-13 16:07:32 +01:00
const txStatus = await driver . findElement ( By . css ( '#success' ) )
2020-08-14 13:48:42 +02:00
await driver . wait ( until . elementTextMatches ( txStatus , /Success/u ) , 15000 )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'switches back to MetaMask' , async function ( ) {
2020-01-13 16:07:32 +01:00
await driver . switchToWindow ( extension )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'should have the correct amount of eth' , async function ( ) {
2020-01-13 16:07:32 +01:00
const balances = await driver . findElements ( By . css ( '.currency-display-component__text' ) )
2020-08-14 13:48:42 +02:00
await driver . wait ( until . elementTextMatches ( balances [ 0 ] , /1/u ) , 15000 )
2019-08-02 05:57:26 +02:00
const balance = await balances [ 0 ] . getText ( )
assert . equal ( balance , '1' )
} )
} )
2020-02-11 17:51:13 +01:00
describe ( 'backs up the seed phrase' , function ( ) {
it ( 'should show a backup reminder' , async function ( ) {
2020-01-13 16:07:32 +01:00
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')]" ) )
2019-08-02 05:57:26 +02:00
assert . equal ( backupReminder . length , 1 )
} )
2020-02-11 17:51:13 +01:00
it ( 'should take the user to the seedphrase backup screen' , async function ( ) {
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . css ( '.home-notification__accept-button' ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
} )
let seedPhrase
2020-02-11 17:51:13 +01:00
it ( 'reveals the seed phrase' , async function ( ) {
2019-08-02 05:57:26 +02:00
const byRevealButton = By . css ( '.reveal-seed-phrase__secret-blocker .reveal-seed-phrase__reveal-button' )
2020-01-15 20:34:15 +01:00
await driver . clickElement ( byRevealButton )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
2020-01-13 16:07:32 +01:00
const revealedSeedPhrase = await driver . findElement ( By . css ( '.reveal-seed-phrase__secret-words' ) )
seedPhrase = await revealedSeedPhrase . getText ( )
2019-08-02 05:57:26 +02:00
assert . equal ( seedPhrase . split ( ' ' ) . length , 12 )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . xpath ( ` //button[contains(text(), ' ${ enLocaleMessages . next . message } ')] ` ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
} )
async function clickWordAndWait ( word ) {
2020-01-29 20:42:46 +01:00
await driver . clickElement ( By . css ( ` [data-testid="seed-phrase-sorted"] [data-testid="draggable-seed- ${ word } "] ` ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( tinyDelayMs )
2019-08-02 05:57:26 +02:00
}
2020-02-11 17:51:13 +01:00
it ( 'can retype the seed phrase' , async function ( ) {
2019-08-02 05:57:26 +02:00
const words = seedPhrase . split ( ' ' )
2019-10-23 19:00:16 +02:00
for ( const word of words ) {
await clickWordAndWait ( word )
}
2019-08-02 05:57:26 +02:00
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . xpath ( ` //button[contains(text(), 'Confirm')] ` ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-02 05:57:26 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'can click through the success screen' , async function ( ) {
2020-01-15 20:34:15 +01:00
await driver . clickElement ( By . xpath ( ` //button[contains(text(), 'All Done')] ` ) )
2020-01-13 16:07:32 +01:00
await driver . delay ( regularDelayMs )
2019-08-06 05:24:19 +02:00
} )
2020-02-11 17:51:13 +01:00
it ( 'should have the correct amount of eth' , async function ( ) {
2020-01-13 16:07:32 +01:00
const balances = await driver . findElements ( By . css ( '.currency-display-component__text' ) )
2020-08-14 13:48:42 +02:00
await driver . wait ( until . elementTextMatches ( balances [ 0 ] , /1/u ) , 15000 )
2019-08-02 05:57:26 +02:00
const balance = await balances [ 0 ] . getText ( )
assert . equal ( balance , '1' )
} )
2020-02-11 17:51:13 +01:00
it ( 'should not show a backup reminder' , async function ( ) {
2020-01-13 16:07:32 +01:00
await driver . assertElementNotPresent ( By . css ( '.backup-notification' ) )
2019-08-02 05:57:26 +02:00
} )
} )
} )