2019-04-16 19:59:11 +02:00
|
|
|
const assert = require('assert')
|
|
|
|
const webdriver = require('selenium-webdriver')
|
|
|
|
const { By } = webdriver
|
|
|
|
const {
|
|
|
|
delay,
|
2019-07-03 03:49:59 +02:00
|
|
|
} = require('./func')
|
2019-04-16 19:59:11 +02:00
|
|
|
const {
|
|
|
|
checkBrowserForConsoleErrors,
|
|
|
|
findElement,
|
|
|
|
findElements,
|
|
|
|
openNewPage,
|
|
|
|
switchToWindowWithTitle,
|
|
|
|
verboseReportOnFailure,
|
|
|
|
waitUntilXWindowHandles,
|
2019-09-07 08:44:22 +02:00
|
|
|
setupFetchMocking,
|
2019-09-07 09:13:58 +02:00
|
|
|
prepareExtensionForTesting,
|
2019-04-16 19:59:11 +02:00
|
|
|
} = require('./helpers')
|
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 regularDelayMs = 1000
|
|
|
|
const largeDelayMs = regularDelayMs * 2
|
|
|
|
|
|
|
|
const button = async (x) => {
|
|
|
|
const buttoncheck = x
|
|
|
|
await buttoncheck.click()
|
2019-07-31 22:17:11 +02:00
|
|
|
await delay(largeDelayMs)
|
|
|
|
const [results] = await findElements(driver, By.css('#results'))
|
|
|
|
const resulttext = await results.getText()
|
2019-04-16 19:59:11 +02:00
|
|
|
var parsedData = JSON.parse(resulttext)
|
|
|
|
|
|
|
|
return (parsedData)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.timeout(0)
|
|
|
|
this.bail(true)
|
|
|
|
|
|
|
|
before(async function () {
|
2019-09-07 09:13:58 +02:00
|
|
|
const result = await prepareExtensionForTesting()
|
|
|
|
driver = result.driver
|
2019-09-07 08:44:22 +02:00
|
|
|
await setupFetchMocking(driver)
|
2019-04-16 19:59:11 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(async function () {
|
|
|
|
if (process.env.SELENIUM_BROWSER === 'chrome') {
|
|
|
|
const errors = await 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 verboseReportOnFailure(driver, this.currentTest)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await driver.quit()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('First time flow starting from an existing seed phrase', () => {
|
|
|
|
it('clicks the continue button on the welcome screen', async () => {
|
|
|
|
await findElement(driver, By.css('.welcome-page__header'))
|
2019-10-23 19:00:16 +02:00
|
|
|
const welcomeScreenBtn = await findElement(driver, By.xpath(`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`))
|
2019-04-16 19:59:11 +02:00
|
|
|
welcomeScreenBtn.click()
|
|
|
|
await delay(largeDelayMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('clicks the "Import Wallet" option', async () => {
|
|
|
|
const customRpcButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Import Wallet')]`))
|
|
|
|
customRpcButton.click()
|
|
|
|
await delay(largeDelayMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('clicks the "No thanks" option on the metametrics opt-in screen', async () => {
|
|
|
|
const optOutButton = await findElement(driver, By.css('.btn-default'))
|
|
|
|
optOutButton.click()
|
|
|
|
await delay(largeDelayMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('imports a seed phrase', async () => {
|
|
|
|
const [seedTextArea] = await findElements(driver, By.css('textarea.first-time-flow__textarea'))
|
|
|
|
await seedTextArea.sendKeys(testSeedPhrase)
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
|
|
|
|
const [password] = await findElements(driver, By.id('password'))
|
|
|
|
await password.sendKeys('correct horse battery staple')
|
|
|
|
const [confirmPassword] = await findElements(driver, By.id('confirm-password'))
|
|
|
|
confirmPassword.sendKeys('correct horse battery staple')
|
|
|
|
|
|
|
|
const tosCheckBox = await findElement(driver, By.css('.first-time-flow__checkbox'))
|
|
|
|
await tosCheckBox.click()
|
|
|
|
|
|
|
|
const [importButton] = await findElements(driver, By.xpath(`//button[contains(text(), 'Import')]`))
|
|
|
|
await importButton.click()
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('clicks through the success screen', async () => {
|
|
|
|
await findElement(driver, By.xpath(`//div[contains(text(), 'Congratulations')]`))
|
2019-10-23 19:00:16 +02:00
|
|
|
const doneButton = await findElement(driver, By.xpath(`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`))
|
2019-04-16 19:59:11 +02:00
|
|
|
await doneButton.click()
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
describe('opens dapp', () => {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
it('switches to mainnet', async () => {
|
|
|
|
const networkDropdown = await findElement(driver, By.css('.network-name'))
|
|
|
|
await networkDropdown.click()
|
|
|
|
await delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
const [mainnet] = await findElements(driver, By.xpath(`//span[contains(text(), 'Main Ethereum Network')]`))
|
|
|
|
await mainnet.click()
|
|
|
|
await delay(largeDelayMs * 2)
|
|
|
|
})
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-08-31 18:34:27 +02:00
|
|
|
it('connects to dapp', async () => {
|
2019-07-31 22:17:11 +02:00
|
|
|
await openNewPage(driver, 'http://127.0.0.1:8080/')
|
|
|
|
await delay(regularDelayMs)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-11-22 18:03:51 +01:00
|
|
|
const connectButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Connect')]`))
|
|
|
|
await connectButton.click()
|
|
|
|
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
await waitUntilXWindowHandles(driver, 3)
|
|
|
|
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]
|
|
|
|
const popup = await switchToWindowWithTitle(driver, 'MetaMask Notification', windowHandles)
|
|
|
|
const dapp = windowHandles.find(handle => handle !== extension && handle !== popup)
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
await delay(regularDelayMs)
|
|
|
|
const approveButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Connect')]`))
|
|
|
|
await approveButton.click()
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
await driver.switchTo().window(dapp)
|
|
|
|
await 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
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
describe('testing web3 methods', async () => {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
it('testing hexa methods', async () => {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
var List = await driver.findElements(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-07-31 22:17:11 +02:00
|
|
|
var parsedData = await button(List[i])
|
|
|
|
console.log(parsedData)
|
|
|
|
var 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)
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
} 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
|
|
|
it('testing booleanMethods', async () => {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
var List = await driver.findElements(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-07-31 22:17:11 +02:00
|
|
|
var parsedData = await button(List[i])
|
|
|
|
console.log(parsedData)
|
|
|
|
var result = parsedData.result
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
assert.equal(result, false)
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
} 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
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
it('testing transactionMethods', async () => {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
var List = await driver.findElements(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-07-31 22:17:11 +02:00
|
|
|
var 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-07-31 22:17:11 +02:00
|
|
|
var result = []
|
|
|
|
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
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
it('testing blockMethods', async () => {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
var List = await driver.findElements(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-07-31 22:17:11 +02:00
|
|
|
var parsedData = await button(List[i])
|
|
|
|
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-07-31 22:17:11 +02:00
|
|
|
var 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)
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
} 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
|
|
|
it('testing methods', async () => {
|
2019-04-16 19:59:11 +02:00
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
var List = await driver.findElements(By.className('methods'))
|
|
|
|
var parsedData
|
|
|
|
var 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)
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
} 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)
|
|
|
|
await delay(regularDelayMs)
|
|
|
|
}
|
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
|
|
|
})
|