aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/base.conf.js4
-rw-r--r--test/integration/index.js2
-rw-r--r--test/integration/lib/add-token.js73
-rw-r--r--test/integration/lib/confirm-sig-requests.js44
-rw-r--r--test/integration/lib/first-time.js80
-rw-r--r--test/integration/lib/mascara-first-time.js94
-rw-r--r--test/integration/lib/send-new-ui.js137
-rw-r--r--test/lib/react-trigger-change.js161
-rw-r--r--test/lib/util.js53
-rw-r--r--test/unit/components/binary-renderer-test.js2
-rw-r--r--test/unit/components/bn-as-decimal-input-test.js2
-rw-r--r--test/unit/development/version–bump-test.js4
-rw-r--r--test/unit/nameForAccount_test.js2
-rw-r--r--test/unit/tx-controller-test.js45
14 files changed, 410 insertions, 293 deletions
diff --git a/test/base.conf.js b/test/base.conf.js
index 82b9d8eec..adb5357e8 100644
--- a/test/base.conf.js
+++ b/test/base.conf.js
@@ -46,7 +46,9 @@ module.exports = function(config) {
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
- browsers: ['Chrome', 'Firefox'],
+ browsers: process.env.browsers ?
+ JSON.parse(process.env.browsers)
+ : ['Chrome', 'Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
diff --git a/test/integration/index.js b/test/integration/index.js
index 144303dbb..b266ddf37 100644
--- a/test/integration/index.js
+++ b/test/integration/index.js
@@ -23,4 +23,4 @@ pump(
console.log(`Integration test build completed: "${bundlePath}"`)
process.exit(0)
}
-) \ No newline at end of file
+)
diff --git a/test/integration/lib/add-token.js b/test/integration/lib/add-token.js
index dd4251cc4..42ed28dca 100644
--- a/test/integration/lib/add-token.js
+++ b/test/integration/lib/add-token.js
@@ -1,4 +1,9 @@
const reactTriggerChange = require('react-trigger-change')
+const {
+ timeout,
+ queryAsync,
+ findAsync,
+} = require('../../lib/util')
QUnit.module('Add token flow')
@@ -13,74 +18,60 @@ QUnit.test('successful add token flow', (assert) => {
})
async function runAddTokenFlowTest (assert, done) {
- const selectState = $('select')
+ const selectState = await queryAsync($, 'select')
selectState.val('add token')
reactTriggerChange(selectState[0])
- await timeout(2000)
-
// Check that no tokens have been added
assert.ok($('.token-list-item').length === 0, 'no tokens added')
// Go to Add Token screen
- let addTokenButton = $('button.btn-clear.wallet-view__add-token-button')
+ let addTokenButton = await queryAsync($, 'button.btn-clear.wallet-view__add-token-button')
assert.ok(addTokenButton[0], 'add token button present')
addTokenButton[0].click()
- await timeout(1000)
-
// Verify Add Token screen
- let addTokenWrapper = $('.add-token__wrapper')
+ let addTokenWrapper = await queryAsync($, '.add-token__wrapper')
assert.ok(addTokenWrapper[0], 'add token wrapper renders')
- let addTokenTitle = $('.add-token__title')
+ let addTokenTitle = await queryAsync($, '.add-token__title')
assert.equal(addTokenTitle[0].textContent, 'Add Token', 'add token title is correct')
// Cancel Add Token
- const cancelAddTokenButton = $('button.btn-cancel.add-token__button')
+ const cancelAddTokenButton = await queryAsync($, 'button.btn-cancel.add-token__button')
assert.ok(cancelAddTokenButton[0], 'cancel add token button present')
cancelAddTokenButton.click()
- await timeout(1000)
-
assert.ok($('.wallet-view')[0], 'cancelled and returned to account detail wallet view')
// Return to Add Token Screen
- addTokenButton = $('button.btn-clear.wallet-view__add-token-button')
+ addTokenButton = await queryAsync($, 'button.btn-clear.wallet-view__add-token-button')
assert.ok(addTokenButton[0], 'add token button present')
addTokenButton[0].click()
- await timeout(1000)
-
// Verify Add Token Screen
- addTokenWrapper = $('.add-token__wrapper')
- addTokenTitle = $('.add-token__title')
+ addTokenWrapper = await queryAsync($, '.add-token__wrapper')
+ addTokenTitle = await queryAsync($, '.add-token__title')
assert.ok(addTokenWrapper[0], 'add token wrapper renders')
assert.equal(addTokenTitle[0].textContent, 'Add Token', 'add token title is correct')
// Search for token
- const searchInput = $('input.add-token__input')
+ const searchInput = await queryAsync($, 'input.add-token__input')
searchInput.val('a')
reactTriggerChange(searchInput[0])
- await timeout()
-
// Click token to add
- const tokenWrapper = $('div.add-token__token-wrapper')
+ const tokenWrapper = await queryAsync($, 'div.add-token__token-wrapper')
assert.ok(tokenWrapper[0], 'token found')
const tokenImageProp = tokenWrapper.find('.add-token__token-icon').css('background-image')
const tokenImageUrl = tokenImageProp.slice(5, -2)
tokenWrapper[0].click()
- await timeout()
-
// Click Next button
- let nextButton = $('button.btn-clear.add-token__button')
+ let nextButton = await queryAsync($, 'button.btn-clear.add-token__button')
assert.equal(nextButton[0].textContent, 'Next', 'next button rendered')
nextButton[0].click()
- await timeout()
-
// Confirm Add token
assert.equal(
$('.add-token__description')[0].textContent,
@@ -90,47 +81,35 @@ async function runAddTokenFlowTest (assert, done) {
assert.ok($('button.btn-clear.add-token__button')[0], 'confirm add token button found')
$('button.btn-clear.add-token__button')[0].click()
- await timeout(2000)
-
// Verify added token image
- let heroBalance = $('.hero-balance')
+ let heroBalance = await queryAsync($, '.hero-balance')
assert.ok(heroBalance, 'rendered hero balance')
assert.ok(tokenImageUrl.indexOf(heroBalance.find('img').attr('src')) > -1, 'token added')
// Return to Add Token Screen
- addTokenButton = $('button.btn-clear.wallet-view__add-token-button')
+ addTokenButton = await queryAsync($, 'button.btn-clear.wallet-view__add-token-button')
assert.ok(addTokenButton[0], 'add token button present')
addTokenButton[0].click()
- await timeout(1000)
-
- const addCustom = $('.add-token__add-custom')
+ const addCustom = await queryAsync($, '.add-token__add-custom')
assert.ok(addCustom[0], 'add custom token button present')
addCustom[0].click()
- await timeout()
-
// Input token contract address
- const customInput = $('input.add-token__add-custom-input')
+ const customInput = await queryAsync($, 'input.add-token__add-custom-input')
customInput.val('0x177af043D3A1Aed7cc5f2397C70248Fc6cDC056c')
reactTriggerChange(customInput[0])
- await timeout(1000)
-
// Click Next button
- nextButton = $('button.btn-clear.add-token__button')
+ nextButton = await queryAsync($, 'button.btn-clear.add-token__button')
assert.equal(nextButton[0].textContent, 'Next', 'next button rendered')
nextButton[0].click()
- await timeout(1000)
-
// Verify symbol length error since contract address won't return symbol
- const errorMessage = $('.add-token__add-custom-error-message')
+ const errorMessage = await queryAsync($, '.add-token__add-custom-error-message')
assert.ok(errorMessage[0], 'error rendered')
$('button.btn-cancel.add-token__button')[0].click()
- await timeout(2000)
-
// // Confirm Add token
// assert.equal(
// $('.add-token__description')[0].textContent,
@@ -141,13 +120,7 @@ async function runAddTokenFlowTest (assert, done) {
// $('button.btn-clear.add-token__button')[0].click()
// // Verify added token image
- // heroBalance = $('.hero-balance')
+ // heroBalance = await queryAsync($, '.hero-balance')
// assert.ok(heroBalance, 'rendered hero balance')
// assert.ok(heroBalance.find('.identicon')[0], 'token added')
}
-
-function timeout (time) {
- return new Promise((resolve, reject) => {
- setTimeout(resolve, time || 1500)
- })
-}
diff --git a/test/integration/lib/confirm-sig-requests.js b/test/integration/lib/confirm-sig-requests.js
index e49424c37..9737a2283 100644
--- a/test/integration/lib/confirm-sig-requests.js
+++ b/test/integration/lib/confirm-sig-requests.js
@@ -1,5 +1,9 @@
const reactTriggerChange = require('react-trigger-change')
-
+const {
+ timeout,
+ queryAsync,
+ findAsync,
+} = require('../../lib/util')
const PASSWORD = 'password123'
QUnit.module('confirm sig requests')
@@ -13,55 +17,41 @@ QUnit.test('successful confirmation of sig requests', (assert) => {
})
async function runConfirmSigRequestsTest(assert, done) {
- let selectState = $('select')
+ let selectState = await queryAsync($, 'select')
selectState.val('confirm sig requests')
reactTriggerChange(selectState[0])
- await timeout(2000)
-
- let confirmSigHeadline = $('.request-signature__headline')
+ let confirmSigHeadline = await queryAsync($, '.request-signature__headline')
assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested')
- let confirmSigRowValue = $('.request-signature__row-value')
+ let confirmSigRowValue = await queryAsync($, '.request-signature__row-value')
assert.ok(confirmSigRowValue[0].textContent.match(/^\#\sTerms\sof\sUse/))
- let confirmSigSignButton = $('.request-signature__footer__sign-button')
+ let confirmSigSignButton = await queryAsync($, '.request-signature__footer__sign-button')
confirmSigSignButton[0].click()
- await timeout(2000)
-
- confirmSigHeadline = $('.request-signature__headline')
+ confirmSigHeadline = await queryAsync($, '.request-signature__headline')
assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested')
- let confirmSigMessage = $('.request-signature__notice')
+ let confirmSigMessage = await queryAsync($, '.request-signature__notice')
assert.ok(confirmSigMessage[0].textContent.match(/^Signing\sthis\smessage/))
- confirmSigRowValue = $('.request-signature__row-value')
+ confirmSigRowValue = await queryAsync($, '.request-signature__row-value')
assert.equal(confirmSigRowValue[0].textContent, '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0')
- confirmSigSignButton = $('.request-signature__footer__sign-button')
+ confirmSigSignButton = await queryAsync($, '.request-signature__footer__sign-button')
confirmSigSignButton[0].click()
- await timeout(2000)
-
- confirmSigHeadline = $('.request-signature__headline')
+ confirmSigHeadline = await queryAsync($, '.request-signature__headline')
assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested')
- confirmSigRowValue = $('.request-signature__row-value')
+ confirmSigRowValue = await queryAsync($, '.request-signature__row-value')
assert.equal(confirmSigRowValue[0].textContent, 'Hi, Alice!')
assert.equal(confirmSigRowValue[1].textContent, '1337')
- confirmSigSignButton = $('.request-signature__footer__sign-button')
+ confirmSigSignButton = await queryAsync($, '.request-signature__footer__sign-button')
confirmSigSignButton[0].click()
- await timeout(2000)
-
- const txView = $('.tx-view')
+ const txView = await queryAsync($, '.tx-view')
assert.ok(txView[0], 'Should return to the account details screen after confirming')
}
-
-function timeout (time) {
- return new Promise((resolve, reject) => {
- setTimeout(resolve, time || 1500)
- })
-} \ No newline at end of file
diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js
index 764eae47c..052d89518 100644
--- a/test/integration/lib/first-time.js
+++ b/test/integration/lib/first-time.js
@@ -1,6 +1,10 @@
const reactTriggerChange = require('react-trigger-change')
const PASSWORD = 'password123'
const runMascaraFirstTimeTest = require('./mascara-first-time')
+const {
+ timeout,
+ findAsync,
+} = require('../../lib/util')
QUnit.module('first time usage')
@@ -21,20 +25,19 @@ async function runFirstTimeUsageTest(assert, done) {
selectState.val('first time')
reactTriggerChange(selectState[0])
- await timeout(2000)
const app = $('#app-content')
// recurse notices
while (true) {
- const button = app.find('button')
+ const button = await findAsync(app, 'button')
if (button.html() === 'Accept') {
// still notices to accept
- const termsPage = app.find('.markdown')[0]
+ const termsPageRaw = await findAsync(app, '.markdown')
+ const termsPage = (await findAsync(app, '.markdown'))[0]
+ console.log('termsPageRaw', termsPageRaw)
termsPage.scrollTop = termsPage.scrollHeight
- await timeout()
console.log('Clearing notice')
button.click()
- await timeout()
} else {
// exit loop
console.log('No more notices...')
@@ -42,97 +45,68 @@ async function runFirstTimeUsageTest(assert, done) {
}
}
- await timeout()
-
// Scroll through terms
- const title = app.find('h1')[0]
+ const title = (await findAsync(app, 'h1'))[0]
assert.equal(title.textContent, 'MetaMask', 'title screen')
// enter password
- const pwBox = app.find('#password-box')[0]
- const confBox = app.find('#password-box-confirm')[0]
+ const pwBox = (await findAsync(app, '#password-box'))[0]
+ const confBox = (await findAsync(app, '#password-box-confirm'))[0]
pwBox.value = PASSWORD
confBox.value = PASSWORD
- await timeout()
-
// create vault
- const createButton = app.find('button.primary')[0]
+ const createButton = (await findAsync(app, 'button.primary'))[0]
createButton.click()
- await timeout(3000)
-
- const created = app.find('h3')[0]
+ await timeout()
+ const created = (await findAsync(app, 'h3'))[0]
assert.equal(created.textContent, 'Vault Created', 'Vault created screen')
// Agree button
- const button = app.find('button')[0]
+ const button = (await findAsync(app, 'button'))[0]
assert.ok(button, 'button present')
button.click()
- await timeout(1000)
-
- const detail = app.find('.account-detail-section')[0]
+ const detail = (await findAsync(app, '.account-detail-section'))[0]
assert.ok(detail, 'Account detail section loaded.')
- const sandwich = app.find('.sandwich-expando')[0]
+ const sandwich = (await findAsync(app, '.sandwich-expando'))[0]
sandwich.click()
- await timeout()
-
- const menu = app.find('.menu-droppo')[0]
+ const menu = (await findAsync(app, '.menu-droppo'))[0]
const children = menu.children
const logout = children[2]
assert.ok(logout, 'Lock menu item found')
logout.click()
- await timeout(1000)
-
- const pwBox2 = app.find('#password-box')[0]
+ const pwBox2 = (await findAsync(app, '#password-box'))[0]
pwBox2.value = PASSWORD
- const createButton2 = app.find('button.primary')[0]
+ const createButton2 = (await findAsync(app, 'button.primary'))[0]
createButton2.click()
- await timeout(1000)
-
- const detail2 = app.find('.account-detail-section')[0]
+ const detail2 = (await findAsync(app, '.account-detail-section'))[0]
assert.ok(detail2, 'Account detail section loaded again.')
- await timeout()
-
// open account settings dropdown
- const qrButton = app.find('.fa.fa-ellipsis-h')[0]
+ const qrButton = (await findAsync(app, '.fa.fa-ellipsis-h'))[0]
qrButton.click()
- await timeout(1000)
-
// qr code item
- const qrButton2 = app.find('.dropdown-menu-item')[1]
+ const qrButton2 = (await findAsync(app, '.dropdown-menu-item'))[1]
qrButton2.click()
- await timeout(1000)
-
- const qrHeader = app.find('.qr-header')[0]
- const qrContainer = app.find('#qr-container')[0]
+ const qrHeader = (await findAsync(app, '.qr-header'))[0]
+ const qrContainer = (await findAsync(app, '#qr-container'))[0]
assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.')
assert.ok(qrContainer, 'QR Container found')
- await timeout()
-
- const networkMenu = app.find('.network-indicator')[0]
+ const networkMenu = (await findAsync(app, '.network-indicator'))[0]
networkMenu.click()
- await timeout()
-
- const networkMenu2 = app.find('.network-indicator')[0]
+ const networkMenu2 = (await findAsync(app, '.network-indicator'))[0]
const children2 = networkMenu2.children
children2.length[3]
assert.ok(children2, 'All network options present')
}
-
-function timeout (time) {
- return new Promise((resolve, reject) => {
- setTimeout(resolve, time || 1500)
- })
-} \ No newline at end of file
diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js
index 515c7f383..bcbc94ff6 100644
--- a/test/integration/lib/mascara-first-time.js
+++ b/test/integration/lib/mascara-first-time.js
@@ -1,119 +1,95 @@
const PASSWORD = 'password123'
const reactTriggerChange = require('react-trigger-change')
+const {
+ timeout,
+ findAsync,
+ queryAsync,
+} = require('../../lib/util')
async function runFirstTimeUsageTest (assert, done) {
await timeout(4000)
- const app = $('#app-content')
+ const app = await queryAsync($, '#app-content')
await skipNotices(app)
- await timeout()
-
// Scroll through terms
- const title = app.find('.create-password__title').text()
+ const title = (await findAsync(app, '.create-password__title')).text()
assert.equal(title, 'Create Password', 'create password screen')
// enter password
- const pwBox = app.find('.first-time-flow__input')[0]
- const confBox = app.find('.first-time-flow__input')[1]
+ const pwBox = (await findAsync(app, '.first-time-flow__input'))[0]
+ const confBox = (await findAsync(app, '.first-time-flow__input'))[1]
pwBox.value = PASSWORD
confBox.value = PASSWORD
reactTriggerChange(pwBox)
reactTriggerChange(confBox)
-
- await timeout()
-
// Create Password
- const createButton = app.find('button.first-time-flow__button')[0]
+ const createButton = (await findAsync(app, 'button.first-time-flow__button'))[0]
createButton.click()
- await timeout(3000)
-
- const created = app.find('.unique-image__title')[0]
+ const created = (await findAsync(app, '.unique-image__title'))[0]
assert.equal(created.textContent, 'Your unique account image', 'unique image screen')
// Agree button
- let button = app.find('button')[0]
+ let button = (await findAsync(app, 'button'))[0]
assert.ok(button, 'button present')
button.click()
- await timeout(1000)
-
await skipNotices(app)
// secret backup phrase
- const seedTitle = app.find('.backup-phrase__title')[0]
+ const seedTitle = (await findAsync(app, '.backup-phrase__title'))[0]
assert.equal(seedTitle.textContent, 'Secret Backup Phrase', 'seed phrase screen')
- app.find('.backup-phrase__reveal-button').click()
-
- await timeout(1000)
- const seedPhrase = app.find('.backup-phrase__secret-words').text().split(' ')
- app.find('.first-time-flow__button').click()
+ ;(await findAsync(app, '.backup-phrase__reveal-button')).click()
+ const seedPhrase = (await findAsync(app, '.backup-phrase__secret-words')).text().split(' ')
+ ;(await findAsync(app, '.first-time-flow__button')).click()
+ await timeout()
const selectPhrase = text => {
const option = $('.backup-phrase__confirm-seed-option')
.filter((i, d) => d.textContent === text)[0]
-
$(option).click()
}
- await timeout(1000)
-
seedPhrase.forEach(sp => selectPhrase(sp))
- app.find('.first-time-flow__button').click()
- await timeout(1000)
+ ;(await findAsync(app, '.first-time-flow__button')).click()
// Deposit Ether Screen
- const buyEthTitle = app.find('.buy-ether__title')[0]
+ const buyEthTitle = (await findAsync(app, '.buy-ether__title'))[0]
assert.equal(buyEthTitle.textContent, 'Deposit Ether', 'deposit ether screen')
- app.find('.buy-ether__do-it-later').click()
- await timeout(1000)
+ ;(await findAsync(app, '.buy-ether__do-it-later')).click()
- const menu = app.find('.account-menu__icon')[0]
+ const menu = (await findAsync(app, '.account-menu__icon'))[0]
menu.click()
- await timeout()
-
- const lock = app.find('.account-menu__logout-button')[0]
+ const lock = (await findAsync(app, '.account-menu__logout-button'))[0]
assert.ok(lock, 'Lock menu item found')
lock.click()
- await timeout(1000)
-
- const pwBox2 = app.find('#password-box')[0]
+ const pwBox2 = (await findAsync(app, '#password-box'))[0]
pwBox2.value = PASSWORD
- const createButton2 = app.find('button.primary')[0]
+ const createButton2 = (await findAsync(app, 'button.primary'))[0]
createButton2.click()
- await timeout(1000)
-
- const detail2 = app.find('.wallet-view')[0]
+ const detail2 = (await findAsync(app, '.wallet-view'))[0]
assert.ok(detail2, 'Account detail section loaded again.')
- await timeout()
-
// open account settings dropdown
- const qrButton = app.find('.wallet-view__details-button')[0]
+ const qrButton = (await findAsync(app, '.wallet-view__details-button'))[0]
qrButton.click()
- await timeout(1000)
-
- const qrHeader = app.find('.editable-label__value')[0]
- const qrContainer = app.find('.qr-wrapper')[0]
+ const qrHeader = (await findAsync(app, '.editable-label__value'))[0]
+ const qrContainer = (await findAsync(app, '.qr-wrapper'))[0]
assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.')
assert.ok(qrContainer, 'QR Container found')
- await timeout()
-
- const networkMenu = app.find('.network-component')[0]
+ const networkMenu = (await findAsync(app, '.network-component'))[0]
networkMenu.click()
- await timeout()
-
- const networkMenu2 = app.find('.network-indicator')[0]
+ const networkMenu2 = (await findAsync(app, '.network-indicator'))[0]
const children2 = networkMenu2.children
children2.length[3]
assert.ok(children2, 'All network options present')
@@ -121,18 +97,12 @@ async function runFirstTimeUsageTest (assert, done) {
module.exports = runFirstTimeUsageTest
-function timeout (time) {
- return new Promise((resolve, reject) => {
- setTimeout(resolve, time || 1500)
- })
-}
-
async function skipNotices (app) {
while (true) {
- const button = app.find('button')
+ const button = await findAsync(app, 'button')
if (button && button.html() === 'Accept') {
// still notices to accept
- const termsPage = app.find('.markdown')[0]
+ const termsPage = (await findAsync(app, '.markdown'))[0]
if (!termsPage) {
break
}
diff --git a/test/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js
index 3456f2367..573faaee3 100644
--- a/test/integration/lib/send-new-ui.js
+++ b/test/integration/lib/send-new-ui.js
@@ -1,4 +1,9 @@
-const reactTriggerChange = require('react-trigger-change')
+const reactTriggerChange = require('../../lib/react-trigger-change')
+const {
+ timeout,
+ queryAsync,
+ findAsync,
+} = require('../../lib/util')
const PASSWORD = 'password123'
@@ -18,83 +23,65 @@ global.ethQuery = {
async function runSendFlowTest(assert, done) {
console.log('*** start runSendFlowTest')
- const selectState = $('select')
+ const selectState = await queryAsync($, 'select')
selectState.val('send new ui')
reactTriggerChange(selectState[0])
- await timeout(2000)
-
- const sendScreenButton = $('button.btn-clear.hero-balance-button')
+ const sendScreenButton = await queryAsync($, 'button.btn-clear.hero-balance-button')
assert.ok(sendScreenButton[1], 'send screen button present')
sendScreenButton[1].click()
- await timeout(1000)
-
- const sendTitle = $('.page-container__title')
+ const sendTitle = await queryAsync($, '.page-container__title')
assert.equal(sendTitle[0].textContent, 'Send ETH', 'Send screen title is correct')
- const sendCopy = $('.page-container__subtitle')
+ const sendCopy = await queryAsync($, '.page-container__subtitle')
assert.equal(sendCopy[0].textContent, 'Only send ETH to an Ethereum address.', 'Send screen has copy')
- const sendFromField = $('.send-v2__form-field')
+ const sendFromField = await queryAsync($, '.send-v2__form-field')
assert.ok(sendFromField[0], 'send screen has a from field')
- let sendFromFieldItemAddress = $('.account-list-item__account-name')
+ let sendFromFieldItemAddress = await queryAsync($, '.account-list-item__account-name')
assert.equal(sendFromFieldItemAddress[0].textContent, 'Send Account 4', 'send from field shows correct account name')
- const sendFromFieldItem = $('.account-list-item')
+ const sendFromFieldItem = await queryAsync($, '.account-list-item')
sendFromFieldItem[0].click()
- await timeout()
-
- const sendFromDropdownList = $('.send-v2__from-dropdown__list')
+ // this seems to fail if the firefox window is not in focus...
+ const sendFromDropdownList = await queryAsync($, '.send-v2__from-dropdown__list')
assert.equal(sendFromDropdownList.children().length, 4, 'send from dropdown shows all accounts')
- console.log(`!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sendFromDropdownList.children()[1]`, sendFromDropdownList.children()[1]);
sendFromDropdownList.children()[1].click()
- await timeout()
-
- sendFromFieldItemAddress = $('.account-list-item__account-name')
- console.log(`!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sendFromFieldItemAddress[0]`, sendFromFieldItemAddress[0]);
+ sendFromFieldItemAddress = await queryAsync($, '.account-list-item__account-name')
assert.equal(sendFromFieldItemAddress[0].textContent, 'Send Account 2', 'send from field dropdown changes account name')
- let sendToFieldInput = $('.send-v2__to-autocomplete__input')
+ let sendToFieldInput = await queryAsync($, '.send-v2__to-autocomplete__input')
sendToFieldInput[0].focus()
- await timeout()
-
- const sendToDropdownList = $('.send-v2__from-dropdown__list')
+ const sendToDropdownList = await queryAsync($, '.send-v2__from-dropdown__list')
assert.equal(sendToDropdownList.children().length, 5, 'send to dropdown shows all accounts and address book accounts')
sendToDropdownList.children()[2].click()
- await timeout()
-
const sendToAccountAddress = sendToFieldInput.val()
assert.equal(sendToAccountAddress, '0x2f8d4a878cfa04a6e60d46362f5644deab66572d', 'send to dropdown selects the correct address')
- const sendAmountField = $('.send-v2__form-row:eq(2)')
+ const sendAmountField = await queryAsync($, '.send-v2__form-row:eq(2)')
sendAmountField.find('.currency-display')[0].click()
- await timeout()
-
- const sendAmountFieldInput = sendAmountField.find('input:text')
+ const sendAmountFieldInput = await findAsync(sendAmountField, 'input:text')
sendAmountFieldInput.val('5.1')
reactTriggerChange(sendAmountField.find('input')[0])
- await timeout()
-
- let errorMessage = $('.send-v2__error')
+ let errorMessage = await queryAsync($, '.send-v2__error')
assert.equal(errorMessage[0].textContent, 'Insufficient funds.', 'send should render an insufficient fund error message')
sendAmountFieldInput.val('2.0')
reactTriggerChange(sendAmountFieldInput[0])
-
await timeout()
errorMessage = $('.send-v2__error')
assert.equal(errorMessage.length, 0, 'send should stop rendering amount error message after amount is corrected')
- const sendGasField = $('.send-v2__gas-fee-display')
+ const sendGasField = await queryAsync($, '.send-v2__gas-fee-display')
assert.equal(
sendGasField.find('.currency-display__input-wrapper > input').val(),
'0.000198',
@@ -106,120 +93,86 @@ async function runSendFlowTest(assert, done) {
'send gas field should show estimated gas total converted to USD'
)
- const sendGasOpenCustomizeModalButton = $('.send-v2__sliders-icon-container'
- )
+ const sendGasOpenCustomizeModalButton = await queryAsync($, '.sliders-icon-container')
sendGasOpenCustomizeModalButton[0].click()
- await timeout(1000)
-
- const customizeGasModal = $('.send-v2__customize-gas')
+ const customizeGasModal = await queryAsync($, '.send-v2__customize-gas')
assert.ok(customizeGasModal[0], 'should render the customize gas modal')
- const customizeGasPriceInput = $('.send-v2__gas-modal-card').first().find('input')
+ const customizeGasPriceInput = (await queryAsync($, '.send-v2__gas-modal-card')).first().find('input')
customizeGasPriceInput.val(50)
reactTriggerChange(customizeGasPriceInput[0])
- const customizeGasLimitInput = $('.send-v2__gas-modal-card').last().find('input')
+ const customizeGasLimitInput = (await queryAsync($, '.send-v2__gas-modal-card')).last().find('input')
customizeGasLimitInput.val(60000)
reactTriggerChange(customizeGasLimitInput[0])
- await timeout()
-
- const customizeGasSaveButton = $('.send-v2__customize-gas__save')
+ const customizeGasSaveButton = await queryAsync($, '.send-v2__customize-gas__save')
customizeGasSaveButton[0].click()
- await timeout()
-
assert.equal(
- sendGasField.find('.currency-display__input-wrapper > input').val(),
+ (await findAsync(sendGasField, '.currency-display__input-wrapper > input')).val(),
'0.003',
'send gas field should show customized gas total'
)
assert.equal(
- sendGasField.find('.currency-display__converted-value')[0].textContent,
+ (await findAsync(sendGasField, '.currency-display__converted-value'))[0].textContent,
'3.60 USD',
'send gas field should show customized gas total converted to USD'
)
- const sendButton = $('button.btn-clear.page-container__footer-button')
+ const sendButton = await queryAsync($, 'button.btn-clear.page-container__footer-button')
assert.equal(sendButton[0].textContent, 'Next', 'next button rendered')
sendButton[0].click()
-
- await timeout(2000)
+ await timeout()
selectState.val('send edit')
reactTriggerChange(selectState[0])
- await timeout(2000)
-
- const confirmFromName = $('.confirm-screen-account-name').first()
+ const confirmFromName = (await queryAsync($, '.confirm-screen-account-name')).first()
assert.equal(confirmFromName[0].textContent, 'Send Account 2', 'confirm screen should show correct from name')
- const confirmToName = $('.confirm-screen-account-name').last()
+ const confirmToName = (await queryAsync($, '.confirm-screen-account-name')).last()
assert.equal(confirmToName[0].textContent, 'Send Account 3', 'confirm screen should show correct to name')
- const confirmScreenRows = $('.confirm-screen-rows')
- const confirmScreenGas = confirmScreenRows.find('.confirm-screen-row-info')[2]
- assert.equal(confirmScreenGas.textContent, '3.6 USD', 'confirm screen should show correct gas')
- const confirmScreenTotal = confirmScreenRows.find('.confirm-screen-row-info')[3]
+ const confirmScreenRows = await queryAsync($, '.confirm-screen-rows')
+ const confirmScreenGas = confirmScreenRows.find('.currency-display__converted-value')[0]
+ assert.equal(confirmScreenGas.textContent, '3.60 USD', 'confirm screen should show correct gas')
+ const confirmScreenTotal = confirmScreenRows.find('.confirm-screen-row-info')[2]
assert.equal(confirmScreenTotal.textContent, '2405.36 USD', 'confirm screen should show correct total')
- const confirmScreenBackButton = $('.confirm-screen-back-button')
+ const confirmScreenBackButton = await queryAsync($, '.confirm-screen-back-button')
confirmScreenBackButton[0].click()
- await timeout(1000)
-
- const sendFromFieldItemInEdit = $('.account-list-item')
+ const sendFromFieldItemInEdit = await queryAsync($, '.account-list-item')
sendFromFieldItemInEdit[0].click()
- await timeout()
-
- const sendFromDropdownListInEdit = $('.send-v2__from-dropdown__list')
+ const sendFromDropdownListInEdit = await queryAsync($, '.send-v2__from-dropdown__list')
sendFromDropdownListInEdit.children()[2].click()
- await timeout()
-
- const sendToFieldInputInEdit = $('.send-v2__to-autocomplete__input')
+ const sendToFieldInputInEdit = await queryAsync($, '.send-v2__to-autocomplete__input')
sendToFieldInputInEdit[0].focus()
sendToFieldInputInEdit.val('0xd85a4b6a394794842887b8284293d69163007bbb')
- await timeout()
-
- const sendAmountFieldInEdit = $('.send-v2__form-row:eq(2)')
+ const sendAmountFieldInEdit = await queryAsync($, '.send-v2__form-row:eq(2)')
sendAmountFieldInEdit.find('.currency-display')[0].click()
- await timeout()
-
const sendAmountFieldInputInEdit = sendAmountFieldInEdit.find('input:text')
sendAmountFieldInputInEdit.val('1.0')
reactTriggerChange(sendAmountFieldInputInEdit[0])
- await timeout()
-
- const sendButtonInEdit = $('.btn-clear.page-container__footer-button')
+ const sendButtonInEdit = await queryAsync($, '.btn-clear.page-container__footer-button')
assert.equal(sendButtonInEdit[0].textContent, 'Next', 'next button in edit rendered')
sendButtonInEdit[0].click()
- await timeout()
-
// TODO: Need a way to mock background so that we can test correct transition from editing to confirm
selectState.val('confirm new ui')
reactTriggerChange(selectState[0])
-
- await timeout(2000)
- const confirmScreenConfirmButton = $('.confirm-screen-confirm-button')
+ const confirmScreenConfirmButton = await queryAsync($, '.btn-confirm.page-container__footer-button')
console.log(`+++++++++++++++++++++++++++++++= confirmScreenConfirmButton[0]`, confirmScreenConfirmButton[0]);
confirmScreenConfirmButton[0].click()
- await timeout(2000)
-
- const txView = $('.tx-view')
+ const txView = await queryAsync($, '.tx-view')
console.log(`++++++++++++++++++++++++++++++++ txView[0]`, txView[0]);
assert.ok(txView[0], 'Should return to the account details screen after confirming')
}
-
-function timeout (time) {
- return new Promise((resolve, reject) => {
- setTimeout(resolve, time || 1500)
- })
-} \ No newline at end of file
diff --git a/test/lib/react-trigger-change.js b/test/lib/react-trigger-change.js
new file mode 100644
index 000000000..a25ddff00
--- /dev/null
+++ b/test/lib/react-trigger-change.js
@@ -0,0 +1,161 @@
+// Trigger React's synthetic change events on input, textarea and select elements
+// https://github.com/vitalyq/react-trigger-change
+
+/******************IMPORTANT NOTE******************/
+/* This file is a modification of the */
+/* 'react-trigger-change' library linked above. */
+/* That library breaks when 'onFocus' events are */
+/* added to components under test because it */
+/* dispatches focus events to ensure changes are */
+/* triggered in some versions of IE. */
+/* This modification removes the accomodations */
+/* 'react-trigger-change' makes for IE to ensure */
+/* our tests can pass in chrome and firefox. */
+/**************************************************/
+
+'use strict';
+
+// Constants and functions are declared inside the closure.
+// In this way, reactTriggerChange can be passed directly to executeScript in Selenium.
+module.exports = function reactTriggerChange(node) {
+ var supportedInputTypes = {
+ color: true,
+ date: true,
+ datetime: true,
+ 'datetime-local': true,
+ email: true,
+ month: true,
+ number: true,
+ password: true,
+ range: true,
+ search: true,
+ tel: true,
+ text: true,
+ time: true,
+ url: true,
+ week: true
+ };
+ var nodeName = node.nodeName.toLowerCase();
+ var type = node.type;
+ var event;
+ var descriptor;
+ var initialValue;
+ var initialChecked;
+ var initialCheckedRadio;
+
+ // Do not try to delete non-configurable properties.
+ // Value and checked properties on DOM elements are non-configurable in PhantomJS.
+ function deletePropertySafe(elem, prop) {
+ var desc = Object.getOwnPropertyDescriptor(elem, prop);
+ if (desc && desc.configurable) {
+ delete elem[prop];
+ }
+ }
+
+ function getCheckedRadio(radio) {
+ var name = radio.name;
+ var radios;
+ var i;
+ if (name) {
+ radios = document.querySelectorAll('input[type="radio"][name="' + name + '"]');
+ for (i = 0; i < radios.length; i += 1) {
+ if (radios[i].checked) {
+ return radios[i] !== radio ? radios[i] : null;
+ }
+ }
+ }
+ return null;
+ }
+
+ function preventChecking(e) {
+ e.preventDefault();
+ if (!initialChecked) {
+ e.target.checked = false;
+ }
+ if (initialCheckedRadio) {
+ initialCheckedRadio.checked = true;
+ }
+ }
+
+ if (nodeName === 'select' ||
+ (nodeName === 'input' && type === 'file')) {
+ // IE9-IE11, non-IE
+ // Dispatch change.
+ event = document.createEvent('HTMLEvents');
+ event.initEvent('change', true, false);
+ node.dispatchEvent(event);
+ } else if ((nodeName === 'input' && supportedInputTypes[type]) ||
+ nodeName === 'textarea') {
+ // React 16
+ // Cache artificial value property descriptor.
+ // Property doesn't exist in React <16, descriptor is undefined.
+ descriptor = Object.getOwnPropertyDescriptor(node, 'value');
+
+ // Update inputValueTracking cached value.
+ // Remove artificial value property.
+ // Restore initial value to trigger event with it.
+ initialValue = node.value;
+ node.value = initialValue + '#';
+ deletePropertySafe(node, 'value');
+ node.value = initialValue;
+
+ // React 0.14: IE10-IE11, non-IE
+ // React 15: non-IE
+ // React 16: IE10-IE11, non-IE
+ event = document.createEvent('HTMLEvents');
+ event.initEvent('input', true, false);
+ node.dispatchEvent(event);
+
+ // React 16
+ // Restore artificial value property descriptor.
+ if (descriptor) {
+ Object.defineProperty(node, 'value', descriptor);
+ }
+ } else if (nodeName === 'input' && type === 'checkbox') {
+ // Invert inputValueTracking cached value.
+ node.checked = !node.checked;
+
+ // Dispatch click.
+ // Click event inverts checked value.
+ event = document.createEvent('MouseEvents');
+ event.initEvent('click', true, true);
+ node.dispatchEvent(event);
+ } else if (nodeName === 'input' && type === 'radio') {
+ // Cache initial checked value.
+ initialChecked = node.checked;
+
+ // Find and cache initially checked radio in the group.
+ initialCheckedRadio = getCheckedRadio(node);
+
+ // React 16
+ // Cache property descriptor.
+ // Invert inputValueTracking cached value.
+ // Remove artificial checked property.
+ // Restore initial value, otherwise preventDefault will eventually revert the value.
+ descriptor = Object.getOwnPropertyDescriptor(node, 'checked');
+ node.checked = !initialChecked;
+ deletePropertySafe(node, 'checked');
+ node.checked = initialChecked;
+
+ // Prevent toggling during event capturing phase.
+ // Set checked value to false if initialChecked is false,
+ // otherwise next listeners will see true.
+ // Restore initially checked radio in the group.
+ node.addEventListener('click', preventChecking, true);
+
+ // Dispatch click.
+ // Click event inverts checked value.
+ event = document.createEvent('MouseEvents');
+ event.initEvent('click', true, true);
+ node.dispatchEvent(event);
+
+ // Remove listener to stop further change prevention.
+ node.removeEventListener('click', preventChecking, true);
+
+ // React 16
+ // Restore artificial checked property descriptor.
+ if (descriptor) {
+ Object.defineProperty(node, 'checked', descriptor);
+ }
+ }
+};
diff --git a/test/lib/util.js b/test/lib/util.js
new file mode 100644
index 000000000..626280745
--- /dev/null
+++ b/test/lib/util.js
@@ -0,0 +1,53 @@
+module.exports = {
+ timeout,
+ queryAsync,
+ findAsync,
+ pollUntilTruthy,
+}
+
+function timeout (time) {
+ return new Promise((resolve, reject) => {
+ setTimeout(resolve, time || 1500)
+ })
+}
+
+async function findAsync(container, selector, opts) {
+ try {
+ return await pollUntilTruthy(() => {
+ const result = container.find(selector)
+ if (result.length > 0) return result
+ }, opts)
+ } catch (err) {
+ throw new Error(`Failed to find element within interval: "${selector}"`)
+ }
+}
+
+async function queryAsync(jQuery, selector, opts) {
+ try {
+ return await pollUntilTruthy(() => {
+ const result = jQuery(selector)
+ if (result.length > 0) return result
+ }, opts)
+ } catch (err) {
+ throw new Error(`Failed to find element within interval: "${selector}"`)
+ }
+}
+
+async function pollUntilTruthy(fn, opts = {}){
+ const pollingInterval = opts.pollingInterval || 100
+ const timeoutInterval = opts.timeoutInterval || 5000
+ const start = Date.now()
+ let result
+ while (!result) {
+ // check if timedout
+ const now = Date.now()
+ if ((now - start) > timeoutInterval) {
+ throw new Error(`pollUntilTruthy - failed to return truthy within interval`)
+ }
+ // check for result
+ result = fn()
+ // run again after timeout
+ await timeout(pollingInterval, timeoutInterval)
+ }
+ return result
+}
diff --git a/test/unit/components/binary-renderer-test.js b/test/unit/components/binary-renderer-test.js
index ee2fa8b60..7bf9250cc 100644
--- a/test/unit/components/binary-renderer-test.js
+++ b/test/unit/components/binary-renderer-test.js
@@ -1,5 +1,5 @@
var assert = require('assert')
-var BinaryRenderer = require('../../../ui/app/components/binary-renderer')
+var BinaryRenderer = require('../../../old-ui/app/components/binary-renderer')
describe('BinaryRenderer', function () {
let binaryRenderer
diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js
index 58ecc9c89..7b9d9814f 100644
--- a/test/unit/components/bn-as-decimal-input-test.js
+++ b/test/unit/components/bn-as-decimal-input-test.js
@@ -6,7 +6,7 @@ const ReactTestUtils = require('react-addons-test-utils')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
-var BnInput = require('../../../ui/app/components/bn-as-decimal-input')
+var BnInput = require('../../../old-ui/app/components/bn-as-decimal-input')
describe('BnInput', function () {
it('can tolerate a gas decimal number at a high precision', function (done) {
diff --git a/test/unit/development/version–bump-test.js b/test/unit/development/version–bump-test.js
index 1c445c8b4..5e37d4410 100644
--- a/test/unit/development/version–bump-test.js
+++ b/test/unit/development/version–bump-test.js
@@ -1,6 +1,6 @@
const assert = require('assert')
const versionBump = require('../../../development/version-bump')
-const { promisify } = require('util')
+const promisify = require('pify')
const fs = require('fs')
const readFile = promisify(fs.readFile)
const path = require('path')
@@ -41,5 +41,3 @@ describe('version bumper', function () {
assert.ok(result.changelog.includes(expected))
})
})
-
-
diff --git a/test/unit/nameForAccount_test.js b/test/unit/nameForAccount_test.js
index e7c0b18b4..32af49e9d 100644
--- a/test/unit/nameForAccount_test.js
+++ b/test/unit/nameForAccount_test.js
@@ -2,7 +2,7 @@ var assert = require('assert')
var sinon = require('sinon')
var path = require('path')
-var contractNamer = require(path.join(__dirname, '..', '..', 'ui', 'lib', 'contract-namer.js'))
+var contractNamer = require(path.join(__dirname, '..', '..', 'old-ui', 'lib', 'contract-namer.js'))
describe('contractNamer', function () {
beforeEach(function () {
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index cc99afee4..712097fce 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -392,6 +392,49 @@ describe('Transaction Controller', function () {
})
})
+ describe('#retryTransaction', function () {
+ it('should create a new txMeta with the same txParams as the original one', function (done) {
+ let txParams = {
+ nonce: '0x00',
+ from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
+ to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
+ data: '0x0',
+ }
+ txController.txStateManager._saveTxList([
+ { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams },
+ ])
+ txController.retryTransaction(1)
+ .then((txMeta) => {
+ assert.equal(txMeta.txParams.nonce, txParams.nonce, 'nonce should be the same')
+ assert.equal(txMeta.txParams.from, txParams.from, 'from should be the same')
+ assert.equal(txMeta.txParams.to, txParams.to, 'to should be the same')
+ assert.equal(txMeta.txParams.data, txParams.data, 'data should be the same')
+ assert.ok(('lastGasPrice' in txMeta), 'should have the key `lastGasPrice`')
+ assert.equal(txController.txStateManager.getTxList().length, 2)
+ done()
+ }).catch(done)
+ })
+ })
+
+ describe('#_markNonceDuplicatesDropped', function () {
+ it('should mark all nonce duplicates as dropped without marking the confirmed transaction as dropped', function () {
+ txController.txStateManager._saveTxList([
+ { id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 4, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 6, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ { id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, history: [{}], txParams: { nonce: '0x01' } },
+ ])
+ txController._markNonceDuplicatesDropped(1)
+ const confirmedTx = txController.txStateManager.getTx(1)
+ const droppedTxs = txController.txStateManager.getFilteredTxList({ nonce: '0x01', status: 'dropped' })
+ assert.equal(confirmedTx.status, 'confirmed', 'the confirmedTx should remain confirmed')
+ assert.equal(droppedTxs.length, 6, 'their should be 6 dropped txs')
+
+ })
+ })
describe('#getPendingTransactions', function () {
beforeEach(function () {
@@ -401,7 +444,7 @@ describe('Transaction Controller', function () {
{ id: 3, status: 'approved', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 4, status: 'signed', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} },
- { id: 6, status: 'confimed', metamaskNetworkId: currentNetworkId, txParams: {} },
+ { id: 6, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 7, status: 'failed', metamaskNetworkId: currentNetworkId, txParams: {} },
])
})