2019-04-16 19:59:11 +02:00
|
|
|
const assert = require('assert')
|
|
|
|
const webdriver = require('selenium-webdriver')
|
2020-01-09 04:34:58 +01:00
|
|
|
|
2019-04-16 19:59:11 +02:00
|
|
|
const { By } = webdriver
|
|
|
|
const {
|
2020-01-13 16:07:32 +01:00
|
|
|
regularDelayMs,
|
|
|
|
largeDelayMs,
|
2019-04-16 19:59:11 +02:00
|
|
|
} = require('./helpers')
|
2020-01-14 18:34:38 +01:00
|
|
|
const { buildWebDriver } = require('./webdriver')
|
2019-10-23 19:00:16 +02:00
|
|
|
const enLocaleMessages = require('../../app/_locales/en/messages.json')
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
describe('Using MetaMask with an existing account', function () {
|
|
|
|
let driver
|
|
|
|
|
|
|
|
const testSeedPhrase = 'forum vessel pink push lonely enact gentle tail admit parrot grunt dress'
|
|
|
|
|
|
|
|
const button = async (x) => {
|
|
|
|
const buttoncheck = x
|
|
|
|
await buttoncheck.click()
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(largeDelayMs)
|
|
|
|
const [results] = await driver.findElements(By.css('#results'))
|
2019-07-31 22:17:11 +02:00
|
|
|
const resulttext = await results.getText()
|
2019-12-03 15:52:01 +01:00
|
|
|
const parsedData = JSON.parse(resulttext)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
return (parsedData)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.timeout(0)
|
|
|
|
this.bail(true)
|
|
|
|
|
|
|
|
before(async function () {
|
2020-01-14 18:34:38 +01:00
|
|
|
const result = await buildWebDriver()
|
2019-09-07 09:13:58 +02:00
|
|
|
driver = result.driver
|
2019-04-16 19:59:11 +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-04-16 19:59:11 +02:00
|
|
|
if (errors.length) {
|
2020-02-15 21:34:12 +01:00
|
|
|
const errorReports = errors.map((err) => err.message)
|
2019-04-16 19:59:11 +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-04-16 19:59:11 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await driver.quit()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('First time flow starting from an existing seed phrase', 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-04-16 19:59:11 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('clicks the "Import Wallet" option', async function () {
|
2020-06-11 16:24:13 +02:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Import wallet')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(largeDelayMs)
|
2019-04-16 19:59:11 +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-04-16 19:59:11 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('imports a seed phrase', async function () {
|
2020-06-11 16:24:13 +02:00
|
|
|
const [seedTextArea] = await driver.findElements(By.css('input[placeholder="Paste seed phrase from clipboard"]'))
|
2019-04-16 19:59:11 +02:00
|
|
|
await seedTextArea.sendKeys(testSeedPhrase)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
const [password] = await driver.findElements(By.id('password'))
|
2019-04-16 19:59:11 +02:00
|
|
|
await password.sendKeys('correct horse battery staple')
|
2020-01-13 16:07:32 +01:00
|
|
|
const [confirmPassword] = await driver.findElements(By.id('confirm-password'))
|
2019-04-16 19:59:11 +02:00
|
|
|
confirmPassword.sendKeys('correct horse battery staple')
|
|
|
|
|
2020-06-11 16:24:13 +02:00
|
|
|
await driver.clickElement(By.css('.first-time-flow__terms'))
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Import')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('clicks through the success screen', async function () {
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.findElement(By.xpath(`//div[contains(text(), 'Congratulations')]`))
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('opens dapp', function () {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('switches to mainnet', async function () {
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.css('.network-name'))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//span[contains(text(), 'Main Ethereum Network')]`))
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(largeDelayMs * 2)
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('connects to dapp', async function () {
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.openNewPage('http://127.0.0.1:8080/')
|
|
|
|
await driver.delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Connect')]`))
|
2019-11-22 18:03:51 +01:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-11-22 18:03:51 +01:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.waitUntilXWindowHandles(3)
|
2019-07-31 22:17:11 +02:00
|
|
|
const windowHandles = await driver.getAllWindowHandles()
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
const extension = windowHandles[0]
|
2020-01-13 16:07:32 +01:00
|
|
|
const popup = await driver.switchToWindowWithTitle('MetaMask Notification', windowHandles)
|
2020-02-15 21:34:12 +01:00
|
|
|
const dapp = windowHandles.find((handle) => handle !== extension && handle !== popup)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2020-01-15 20:34:15 +01:00
|
|
|
await driver.clickElement(By.xpath(`//button[contains(text(), 'Connect')]`))
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.switchToWindow(dapp)
|
|
|
|
await driver.delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
})
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('testing web3 methods', function () {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('testing hexa methods', async function () {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
const List = await driver.findClickableElements(By.className('hexaNumberMethods'))
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
for (let i = 0; i < List.length; i++) {
|
|
|
|
try {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
const parsedData = await button(List[i])
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(parsedData)
|
2019-12-03 15:52:01 +01:00
|
|
|
const result = parseInt(parsedData.result, 16)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
assert.equal((typeof result === 'number'), true)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
assert(false)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
}
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('testing booleanMethods', async function () {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
const List = await driver.findClickableElement(By.className('booleanMethods'))
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
for (let i = 0; i < List.length; i++) {
|
|
|
|
try {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
const parsedData = await button(List[i])
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(parsedData)
|
2019-12-03 15:52:01 +01:00
|
|
|
const result = parsedData.result
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
assert.equal(result, false)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
assert(false)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('testing transactionMethods', async function () {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
const List = await driver.findClickableElement(By.className('transactionMethods'))
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
for (let i = 0; i < List.length; i++) {
|
|
|
|
try {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
const parsedData = await button(List[i])
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(parsedData.result.blockHash)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
const result = []
|
2019-07-31 22:17:11 +02:00
|
|
|
result.push(parseInt(parsedData.result.blockHash, 16))
|
|
|
|
result.push(parseInt(parsedData.result.blockNumber, 16))
|
|
|
|
result.push(parseInt(parsedData.result.gas, 16))
|
|
|
|
result.push(parseInt(parsedData.result.gasPrice, 16))
|
|
|
|
result.push(parseInt(parsedData.result.hash, 16))
|
|
|
|
result.push(parseInt(parsedData.result.input, 16))
|
|
|
|
result.push(parseInt(parsedData.result.nonce, 16))
|
|
|
|
result.push(parseInt(parsedData.result.r, 16))
|
|
|
|
result.push(parseInt(parsedData.result.s, 16))
|
|
|
|
result.push(parseInt(parsedData.result.v, 16))
|
|
|
|
result.push(parseInt(parsedData.result.to, 16))
|
|
|
|
result.push(parseInt(parsedData.result.value, 16))
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
result.forEach((value) => {
|
|
|
|
assert.equal((typeof value === 'number'), true)
|
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
} catch (err) {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(err)
|
|
|
|
assert(false)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('testing blockMethods', async function () {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
const List = await driver.findClickableElement(By.className('blockMethods'))
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
for (let i = 0; i < List.length; i++) {
|
|
|
|
try {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
const parsedData = await button(List[i])
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(JSON.stringify(parsedData) + i)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(parsedData.result.parentHash)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-12-03 15:52:01 +01:00
|
|
|
const result = parseInt(parsedData.result.parentHash, 16)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
assert.equal((typeof result === 'number'), true)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
} catch (err) {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(err)
|
|
|
|
assert(false)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('testing methods', async function () {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2020-01-15 20:34:15 +01:00
|
|
|
const List = await driver.findClickableElement(By.className('methods'))
|
2019-12-03 15:52:01 +01:00
|
|
|
let parsedData
|
|
|
|
let result
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
for (let i = 0; i < List.length; i++) {
|
|
|
|
try {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
if (i === 2) {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
parsedData = await button(List[i])
|
|
|
|
console.log(parsedData.result.blockHash)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
result = parseInt(parsedData.result.blockHash, 16)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
assert.equal((typeof result === 'number' || (result === 0)), true)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
} else {
|
|
|
|
parsedData = await button(List[i])
|
|
|
|
console.log(parsedData.result)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
result = parseInt(parsedData.result, 16)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
assert.equal((typeof result === 'number' || (result === 0)), true)
|
2020-01-13 16:07:32 +01:00
|
|
|
await driver.delay(regularDelayMs)
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
} catch (err) {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
console.log(err)
|
|
|
|
assert(false)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
})
|