Refactoring threebox.spec.js to use fixtures (#10849)
parent
e18deda0da
commit
8df7a712f3
@ -0,0 +1,122 @@ |
||||
{ |
||||
"data": { |
||||
"AppStateController": { |
||||
"swapsWelcomeMessageHasBeenShown": true, |
||||
"connectedStatusPopoverHasBeenShown": false |
||||
}, |
||||
"CachedBalancesController": { |
||||
"cachedBalances": { |
||||
"0x539": { |
||||
"0x5cfe73b6021e818b776b421b1c4db2474086a7e1": "0x15af1d78b58c40000" |
||||
} |
||||
} |
||||
}, |
||||
"CurrencyController": { |
||||
"conversionDate": 1617897791.928, |
||||
"conversionRate": 2072.49, |
||||
"currentCurrency": "usd", |
||||
"nativeCurrency": "ETH", |
||||
"usdConversionRate": 2072.49 |
||||
}, |
||||
"IncomingTransactionsController": { |
||||
"incomingTransactions": {}, |
||||
"incomingTxLastFetchedBlockByChainId": { |
||||
"0x5": null, |
||||
"0x2a": null, |
||||
"0x1": null, |
||||
"0x4": 5570536 |
||||
} |
||||
}, |
||||
"KeyringController": { |
||||
"vault": "{\"data\":\"s6TpYjlUNsn7ifhEFTkuDGBUM1GyOlPrim7JSjtfIxgTt8/6MiXgiR/CtFfR4dWW2xhq85/NGIBYEeWrZThGdKGarBzeIqBfLFhw9n509jprzJ0zc2Rf+9HVFGLw+xxC4xPxgCS0IIWeAJQ+XtGcHmn0UZXriXm8Ja4kdlow6SWinB7sr/WM3R0+frYs4WgllkwggDf2/Tv6VHygvLnhtzp6hIJFyTjh+l/KnyJTyZW1TkZhDaNDzX3SCOHT\",\"iv\":\"FbeHDAW5afeWNORfNJBR0Q==\",\"salt\":\"TxZ+WbCW6891C9LK/hbMAoUsSEW1E8pyGLVBU6x5KR8=\"}" |
||||
}, |
||||
"NetworkController": { |
||||
"provider": { |
||||
"nickname": "Localhost 8545", |
||||
"rpcUrl": "http://localhost:8545", |
||||
"chainId": "0x539", |
||||
"ticker": "ETH", |
||||
"type": "rpc" |
||||
}, |
||||
"previousProviderStore": { |
||||
"nickname": "Localhost 8545", |
||||
"rpcUrl": "http://localhost:8545", |
||||
"chainId": "0x539", |
||||
"ticker": "ETH", |
||||
"type": "rpc" |
||||
}, |
||||
"network": "1337" |
||||
}, |
||||
"OnboardingController": { |
||||
"onboardingTabs": {}, |
||||
"seedPhraseBackedUp": true |
||||
}, |
||||
"PreferencesController": { |
||||
"frequentRpcListDetail": [ |
||||
{ |
||||
"rpcUrl": "http://localhost:8545", |
||||
"chainId": "0x539", |
||||
"ticker": "ETH", |
||||
"nickname": "Localhost 8545", |
||||
"rpcPrefs": {} |
||||
} |
||||
], |
||||
"accountTokens": { |
||||
"0x5cfe73b6021e818b776b421b1c4db2474086a7e1": { |
||||
"0x4": [], |
||||
"0x3": [] |
||||
} |
||||
}, |
||||
"accountHiddenTokens": {}, |
||||
"assetImages": {}, |
||||
"tokens": [], |
||||
"hiddenTokens": [], |
||||
"suggestedTokens": {}, |
||||
"useBlockie": true, |
||||
"useNonceField": false, |
||||
"usePhishDetect": true, |
||||
"featureFlags": { |
||||
"showIncomingTransactions": true, |
||||
"transactionTime": false |
||||
}, |
||||
"knownMethodData": {}, |
||||
"firstTimeFlowType": "create", |
||||
"currentLocale": "en", |
||||
"identities": { |
||||
"0x5cfe73b6021e818b776b421b1c4db2474086a7e1": { |
||||
"address": "0x5cfe73b6021e818b776b421b1c4db2474086a7e1", |
||||
"name": "Account 1" |
||||
} |
||||
}, |
||||
"lostIdentities": {}, |
||||
"forgottenPassword": false, |
||||
"preferences": { |
||||
"useNativeCurrencyAsPrimaryCurrency": true |
||||
}, |
||||
"completedOnboarding": true, |
||||
"ipfsGateway": "dweb.link", |
||||
"selectedAddress": "0x5cfe73b6021e818b776b421b1c4db2474086a7e1" |
||||
}, |
||||
"config": {}, |
||||
"firstTimeInfo": { |
||||
"date": 1575697234195, |
||||
"version": "7.7.0" |
||||
}, |
||||
"MetaMetricsController": { |
||||
"metaMetricsId": null, |
||||
"participateInMetaMetrics": false, |
||||
"metaMetricsSendCount": 0 |
||||
}, |
||||
"ThreeBoxController": { |
||||
"threeBoxSyncingAllowed": true, |
||||
"showRestorePrompt": true, |
||||
"threeBoxLastUpdated": 0, |
||||
"threeBoxAddress": "0x64480aa2768ef12f3f19c5a01206ceb0f82d06b9", |
||||
"threeBoxSynced": true, |
||||
"threeBoxDisabled": false |
||||
} |
||||
}, |
||||
"meta": { |
||||
"version": 57 |
||||
} |
||||
} |
@ -1,38 +0,0 @@ |
||||
const http = require('http'); |
||||
|
||||
const port = 8889; |
||||
|
||||
const database = {}; |
||||
|
||||
const requestHandler = (request, response) => { |
||||
response.setHeader('Content-Type', 'application/json'); |
||||
if (request.method === 'POST') { |
||||
let body = ''; |
||||
request.on('data', (chunk) => { |
||||
body += chunk.toString(); // convert Buffer to string
|
||||
}); |
||||
request.on('end', () => { |
||||
const { key, data } = JSON.parse(body); |
||||
|
||||
database[key] = data; |
||||
response.setHeader('Access-Control-Allow-Headers', '*'); |
||||
response.end('ok'); |
||||
}); |
||||
} else if (request.method === 'GET') { |
||||
const key = new URL(request.url, 'https://example.org/').searchParams.get( |
||||
'key', |
||||
); |
||||
response.setHeader('Access-Control-Allow-Headers', '*'); |
||||
response.end(JSON.stringify(database[key] || '')); |
||||
} else { |
||||
response.end('unknown request'); |
||||
} |
||||
}; |
||||
|
||||
const server = http.createServer(requestHandler); |
||||
|
||||
server.listen(port, (err) => { |
||||
if (err) { |
||||
console.log('mock 3box server error: ', err); |
||||
} |
||||
}); |
@ -0,0 +1,57 @@ |
||||
const http = require('http'); |
||||
|
||||
const PORT = 8889; |
||||
|
||||
class ThreeboxMockServer { |
||||
constructor() { |
||||
this.server = http.createServer(this.requestHandler); |
||||
this.database = {}; |
||||
} |
||||
|
||||
async start() { |
||||
return new Promise((resolve, reject) => { |
||||
this.server = this.server.listen(PORT); |
||||
this.server.once('error', reject); |
||||
this.server.once('listening', resolve); |
||||
}); |
||||
} |
||||
|
||||
async stop() { |
||||
if (!this.server) { |
||||
return; |
||||
} |
||||
|
||||
await new Promise((resolve, reject) => { |
||||
this.server.close(); |
||||
this.server.once('error', reject); |
||||
this.server.once('close', resolve); |
||||
}); |
||||
} |
||||
|
||||
requestHandler = (request, response) => { |
||||
response.setHeader('Content-Type', 'application/json'); |
||||
if (request.method === 'POST') { |
||||
let body = ''; |
||||
request.on('data', (chunk) => { |
||||
body += chunk.toString(); // convert Buffer to string
|
||||
}); |
||||
request.on('end', () => { |
||||
const { key, data } = JSON.parse(body); |
||||
this.database[key] = data; |
||||
response.setHeader('Access-Control-Allow-Headers', '*'); |
||||
response.end('ok'); |
||||
}); |
||||
} else if (request.method === 'GET') { |
||||
const key = new URL(request.url, 'https://example.org/').searchParams.get( |
||||
'key', |
||||
); |
||||
|
||||
response.setHeader('Access-Control-Allow-Headers', '*'); |
||||
response.end(JSON.stringify(this.database[key] || '')); |
||||
} else { |
||||
response.end('unknown request'); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
module.exports = ThreeboxMockServer; |
@ -0,0 +1,100 @@ |
||||
const { strict: assert } = require('assert'); |
||||
const { By, Key } = require('selenium-webdriver'); |
||||
const { withFixtures, largeDelayMs } = require('../helpers'); |
||||
const ThreeboxMockServer = require('../mock-3box/threebox-mock-server'); |
||||
|
||||
describe('Threebox', function () { |
||||
const ganacheOptions = { |
||||
accounts: [ |
||||
{ |
||||
secretKey: |
||||
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', |
||||
balance: 25000000000000000000, |
||||
}, |
||||
], |
||||
}; |
||||
let threeboxServer; |
||||
before(async function () { |
||||
threeboxServer = new ThreeboxMockServer(); |
||||
await threeboxServer.start(); |
||||
}); |
||||
after(async function () { |
||||
await threeboxServer.stop(); |
||||
}); |
||||
it('Set up data to be restored by 3box', async function () { |
||||
await withFixtures( |
||||
{ |
||||
fixtures: 'imported-account', |
||||
ganacheOptions, |
||||
title: this.test.title, |
||||
}, |
||||
async ({ driver }) => { |
||||
await driver.navigate(); |
||||
const passwordField = await driver.findElement(By.css('#password')); |
||||
await passwordField.sendKeys('correct horse battery staple'); |
||||
await passwordField.sendKeys(Key.ENTER); |
||||
|
||||
// turns on threebox syncing
|
||||
await driver.clickElement('.account-menu__icon'); |
||||
await driver.clickElement({ text: 'Settings', tag: 'div' }); |
||||
|
||||
// turns on threebox syncing
|
||||
await driver.clickElement({ text: 'Advanced', tag: 'div' }); |
||||
await driver.clickElement( |
||||
'[data-testid="advanced-setting-3box"] .toggle-button div', |
||||
); |
||||
|
||||
// updates settings and address book
|
||||
// navigates to General settings
|
||||
await driver.clickElement({ text: 'General', tag: 'div' }); |
||||
|
||||
// turns on use of blockies
|
||||
await driver.clickElement('.toggle-button > div'); |
||||
|
||||
// adds an address to the contact list
|
||||
await driver.clickElement({ text: 'Contacts', tag: 'div' }); |
||||
|
||||
await driver.clickElement('.address-book-add-button__button'); |
||||
const addAddressInputs = await driver.findElements('input'); |
||||
await addAddressInputs[0].sendKeys('Test User Name 11'); |
||||
await addAddressInputs[1].sendKeys( |
||||
'0x2f318C334780961FB129D2a6c30D0763d9a5C970', |
||||
); |
||||
await driver.delay(largeDelayMs * 2); |
||||
await driver.clickElement({ text: 'Save', tag: 'button' }); |
||||
await driver.findElement({ text: 'Test User Name 11', tag: 'div' }); |
||||
}, |
||||
); |
||||
}); |
||||
it('Restore from 3box', async function () { |
||||
await withFixtures( |
||||
{ |
||||
fixtures: 'threebox-enabled', |
||||
ganacheOptions, |
||||
title: this.test.title, |
||||
}, |
||||
async ({ driver }) => { |
||||
await driver.navigate(); |
||||
const passwordField = await driver.findElement(By.css('#password')); |
||||
await passwordField.sendKeys('correct horse battery staple'); |
||||
await passwordField.sendKeys(Key.ENTER); |
||||
|
||||
// confirms the 3box restore notification
|
||||
await driver.clickElement('.home-notification__accept-button'); |
||||
|
||||
// goes to the settings screen
|
||||
await driver.clickElement('.account-menu__icon'); |
||||
await driver.clickElement({ text: 'Settings', tag: 'div' }); |
||||
|
||||
// finds the blockies toggle turned on
|
||||
const toggleLabel = await driver.findElement('.toggle-button__status'); |
||||
const toggleLabelText = await toggleLabel.getText(); |
||||
assert.equal(toggleLabelText, 'ON'); |
||||
|
||||
// finds the restored address in the contact list
|
||||
await driver.clickElement({ text: 'Contacts', tag: 'div' }); |
||||
await driver.findElement({ text: 'Test User Name 11', tag: 'div' }); |
||||
}, |
||||
); |
||||
}); |
||||
}); |
@ -1,265 +0,0 @@ |
||||
const assert = require('assert'); |
||||
const { until } = require('selenium-webdriver'); |
||||
const getPort = require('get-port'); |
||||
|
||||
const enLocaleMessages = require('../../app/_locales/en/messages.json'); |
||||
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers'); |
||||
const { buildWebDriver } = require('./webdriver'); |
||||
const Ganache = require('./ganache'); |
||||
|
||||
const ganacheServer = new Ganache(); |
||||
|
||||
describe('MetaMask', function () { |
||||
let driver; |
||||
|
||||
const testSeedPhrase = |
||||
'forum vessel pink push lonely enact gentle tail admit parrot grunt dress'; |
||||
|
||||
this.timeout(0); |
||||
this.bail(true); |
||||
|
||||
before(async function () { |
||||
await ganacheServer.start({ |
||||
accounts: [ |
||||
{ |
||||
secretKey: |
||||
'0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9', |
||||
balance: 25000000000000000000, |
||||
}, |
||||
], |
||||
}); |
||||
const result = await buildWebDriver({ port: await getPort() }); |
||||
driver = result.driver; |
||||
await driver.navigate(); |
||||
}); |
||||
|
||||
afterEach(async function () { |
||||
if (process.env.SELENIUM_BROWSER === 'chrome') { |
||||
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', |
||||
)}`;
|
||||
console.error(new Error(errorMessage)); |
||||
} |
||||
} |
||||
if (this.currentTest.state === 'failed') { |
||||
await driver.verboseReportOnFailure(this.currentTest.title); |
||||
} |
||||
}); |
||||
|
||||
after(async function () { |
||||
await ganacheServer.quit(); |
||||
await driver.quit(); |
||||
}); |
||||
|
||||
describe('set up data to be restored by 3box', function () { |
||||
describe('First time flow starting from an existing seed phrase', function () { |
||||
it('clicks the continue button on the welcome screen', async function () { |
||||
await driver.findElement('.welcome-page__header'); |
||||
await driver.clickElement({ |
||||
text: enLocaleMessages.getStarted.message, |
||||
tag: 'button', |
||||
}); |
||||
await driver.delay(largeDelayMs); |
||||
}); |
||||
|
||||
it('clicks the "Import Wallet" option', async function () { |
||||
await driver.clickElement({ text: 'Import wallet', tag: 'button' }); |
||||
await driver.delay(largeDelayMs); |
||||
}); |
||||
|
||||
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () { |
||||
await driver.clickElement('.btn-default'); |
||||
await driver.delay(largeDelayMs); |
||||
}); |
||||
|
||||
it('imports a seed phrase', async function () { |
||||
const [seedTextArea] = await driver.findElements( |
||||
'input[placeholder="Paste seed phrase from clipboard"]', |
||||
); |
||||
await seedTextArea.sendKeys(testSeedPhrase); |
||||
await driver.delay(regularDelayMs); |
||||
|
||||
const [password] = await driver.findElements('#password'); |
||||
await password.sendKeys('correct horse battery staple'); |
||||
const [confirmPassword] = await driver.findElements( |
||||
'#confirm-password', |
||||
); |
||||
confirmPassword.sendKeys('correct horse battery staple'); |
||||
|
||||
await driver.clickElement('.first-time-flow__terms'); |
||||
|
||||
await driver.clickElement({ text: 'Import', tag: 'button' }); |
||||
await driver.delay(regularDelayMs); |
||||
}); |
||||
|
||||
it('clicks through the success screen', async function () { |
||||
await driver.findElement({ text: 'Congratulations', tag: 'div' }); |
||||
await driver.clickElement({ |
||||
text: enLocaleMessages.endOfFlowMessage10.message, |
||||
tag: 'button', |
||||
}); |
||||
await driver.delay(regularDelayMs); |
||||
}); |
||||
|
||||
it('balance renders', async function () { |
||||
const balance = await driver.findElement( |
||||
'[data-testid="wallet-balance"] .list-item__heading', |
||||
); |
||||
await driver.wait(until.elementTextMatches(balance, /25\s*ETH/u)); |
||||
await driver.delay(regularDelayMs); |
||||
}); |
||||
}); |
||||
|
||||
describe('turns on threebox syncing', function () { |
||||
it('goes to the settings screen', async function () { |
||||
await driver.clickElement('.account-menu__icon'); |
||||
await driver.delay(regularDelayMs); |
||||
|
||||
await driver.clickElement({ text: 'Settings', tag: 'div' }); |
||||
}); |
||||
|
||||
it('turns on threebox syncing', async function () { |
||||
await driver.clickElement({ text: 'Advanced', tag: 'div' }); |
||||
await driver.clickElement( |
||||
'[data-testid="advanced-setting-3box"] .toggle-button div', |
||||
); |
||||
}); |
||||
}); |
||||
|
||||
describe('updates settings and address book', function () { |
||||
it('navigates to General settings', async function () { |
||||
await driver.clickElement({ text: 'General', tag: 'div' }); |
||||
}); |
||||
|
||||
it('turns on use of blockies', async function () { |
||||
await driver.clickElement('.toggle-button > div'); |
||||
}); |
||||
|
||||
it('adds an address to the contact list', async function () { |
||||
await driver.clickElement({ text: 'Contacts', tag: 'div' }); |
||||
|
||||
await driver.clickElement('.address-book-add-button__button'); |
||||
await driver.delay(tinyDelayMs); |
||||
|
||||
const addAddressInputs = await driver.findElements('input'); |
||||
await addAddressInputs[0].sendKeys('Test User Name 11'); |
||||
|
||||
await driver.delay(tinyDelayMs); |
||||
|
||||
await addAddressInputs[1].sendKeys( |
||||
'0x2f318C334780961FB129D2a6c30D0763d9a5C970', |
||||
); |
||||
|
||||
await driver.delay(largeDelayMs * 2); |
||||
|
||||
await driver.clickElement({ text: 'Save', tag: 'button' }); |
||||
|
||||
await driver.findElement({ text: 'Test User Name 11', tag: 'div' }); |
||||
await driver.delay(regularDelayMs); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('restoration from 3box', function () { |
||||
let driver2; |
||||
|
||||
before(async function () { |
||||
const result = await buildWebDriver({ port: await getPort() }); |
||||
driver2 = result.driver; |
||||
await driver2.navigate(); |
||||
}); |
||||
|
||||
after(async function () { |
||||
await driver2.quit(); |
||||
}); |
||||
|
||||
describe('First time flow starting from an existing seed phrase', function () { |
||||
it('clicks the continue button on the welcome screen', async function () { |
||||
await driver2.findElement('.welcome-page__header'); |
||||
await driver2.clickElement({ |
||||
text: enLocaleMessages.getStarted.message, |
||||
tag: 'button', |
||||
}); |
||||
await driver2.delay(largeDelayMs); |
||||
}); |
||||
|
||||
it('clicks the "Import Wallet" option', async function () { |
||||
await driver2.clickElement({ text: 'Import wallet', tag: 'button' }); |
||||
await driver2.delay(largeDelayMs); |
||||
}); |
||||
|
||||
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () { |
||||
await driver2.clickElement('.btn-default'); |
||||
await driver2.delay(largeDelayMs); |
||||
}); |
||||
|
||||
it('imports a seed phrase', async function () { |
||||
const [seedTextArea] = await driver2.findElements( |
||||
'input[placeholder="Paste seed phrase from clipboard"]', |
||||
); |
||||
await seedTextArea.sendKeys(testSeedPhrase); |
||||
await driver2.delay(regularDelayMs); |
||||
|
||||
const [password] = await driver2.findElements('#password'); |
||||
await password.sendKeys('correct horse battery staple'); |
||||
const [confirmPassword] = await driver2.findElements( |
||||
'#confirm-password', |
||||
); |
||||
confirmPassword.sendKeys('correct horse battery staple'); |
||||
|
||||
await driver2.clickElement('.first-time-flow__terms'); |
||||
|
||||
await driver2.clickElement({ text: 'Import', tag: 'button' }); |
||||
await driver2.delay(regularDelayMs); |
||||
}); |
||||
|
||||
it('clicks through the success screen', async function () { |
||||
await driver2.findElement({ text: 'Congratulations', tag: 'div' }); |
||||
await driver2.clickElement({ |
||||
text: enLocaleMessages.endOfFlowMessage10.message, |
||||
tag: 'button', |
||||
}); |
||||
await driver2.delay(regularDelayMs); |
||||
}); |
||||
|
||||
it('balance renders', async function () { |
||||
const balance = await driver2.findElement( |
||||
'[data-testid="wallet-balance"] .list-item__heading', |
||||
); |
||||
await driver2.wait(until.elementTextMatches(balance, /25\s*ETH/u)); |
||||
await driver2.delay(regularDelayMs); |
||||
}); |
||||
}); |
||||
|
||||
describe('restores 3box data', function () { |
||||
it('confirms the 3box restore notification', async function () { |
||||
await driver2.clickElement('.home-notification__accept-button'); |
||||
}); |
||||
|
||||
it('goes to the settings screen', async function () { |
||||
await driver2.clickElement('.account-menu__icon'); |
||||
await driver2.delay(regularDelayMs); |
||||
|
||||
await driver2.clickElement({ text: 'Settings', tag: 'div' }); |
||||
}); |
||||
|
||||
it('finds the blockies toggle turned on', async function () { |
||||
await driver2.delay(regularDelayMs); |
||||
const toggleLabel = await driver2.findElement('.toggle-button__status'); |
||||
const toggleLabelText = await toggleLabel.getText(); |
||||
assert.equal(toggleLabelText, 'ON'); |
||||
}); |
||||
|
||||
it('finds the restored address in the contact list', async function () { |
||||
await driver2.clickElement({ text: 'Contacts', tag: 'div' }); |
||||
await driver2.delay(regularDelayMs); |
||||
|
||||
await driver2.findElement({ text: 'Test User Name 11', tag: 'div' }); |
||||
await driver2.delay(regularDelayMs); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
Loading…
Reference in new issue