aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-09-27 07:24:43 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-09-27 07:24:43 +0800
commit8ab23c713db1f5d45abb0ba433450591b8759809 (patch)
treec192fcf5eec3c7b422f3d0a91a4a96037c7f2fa6 /test
parent77a48fb0b16d7415377b02a3b7d383c9ef86fcb6 (diff)
parent6ca519e97c4c282023ab6b7788715ff8d7ec8189 (diff)
downloadtangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar
tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.gz
tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.bz2
tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.lz
tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.xz
tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.tar.zst
tangerine-wallet-browser-8ab23c713db1f5d45abb0ba433450591b8759809.zip
Merge branch 'master' into transactionControllerRefractorPt3
Diffstat (limited to 'test')
-rw-r--r--test/base.conf.js59
-rw-r--r--test/flat.conf.js8
-rw-r--r--test/integration/helpers.js7
-rw-r--r--test/integration/index.js19
-rw-r--r--test/integration/lib/first-time.js191
-rw-r--r--test/lib/mock-encryptor.js4
-rw-r--r--test/mascara.conf.js17
-rw-r--r--test/unit/components/pending-tx-test.js5
-rw-r--r--test/unit/keyring-controller-test.js7
-rw-r--r--test/unit/nonce-tracker-test.js19
-rw-r--r--test/unit/pending-balance-test.js93
-rw-r--r--test/unit/tx-controller-test.js4
12 files changed, 320 insertions, 113 deletions
diff --git a/test/base.conf.js b/test/base.conf.js
new file mode 100644
index 000000000..122392822
--- /dev/null
+++ b/test/base.conf.js
@@ -0,0 +1,59 @@
+// Karma configuration
+// Generated on Mon Sep 11 2017 18:45:48 GMT-0700 (PDT)
+
+module.exports = function(config) {
+ return {
+ // base path that will be used to resolve all patterns (eg. files, exclude)
+ basePath: process.cwd(),
+
+ browserConsoleLogOptions: {
+ terminal: false,
+ },
+
+ // frameworks to use
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
+ frameworks: ['qunit'],
+
+ // list of files / patterns to load in the browser
+ files: [
+ 'test/integration/jquery-3.1.0.min.js',
+ { pattern: 'dist/chrome/images/**/*.*', watched: false, included: false, served: true },
+ { pattern: 'dist/chrome/fonts/**/*.*', watched: false, included: false, served: true },
+ ],
+
+ proxies: {
+ '/images/': '/base/dist/chrome/images/',
+ '/fonts/': '/base/dist/chrome/fonts/',
+ },
+
+ // test results reporter to use
+ // possible values: 'dots', 'progress'
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+ reporters: ['progress'],
+
+ // web server port
+ port: 9876,
+
+ // enable / disable colors in the output (reporters and logs)
+ colors: true,
+
+ // level of logging
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+ logLevel: config.LOG_INFO,
+
+ // enable / disable watching file and executing tests whenever any file changes
+ autoWatch: false,
+
+ // start these browsers
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+ browsers: ['Chrome', 'Firefox'],
+
+ // Continuous Integration mode
+ // if true, Karma captures browsers, runs the tests and exits
+ singleRun: true,
+
+ // Concurrency level
+ // how many browser should be started simultaneous
+ concurrency: Infinity
+ }
+}
diff --git a/test/flat.conf.js b/test/flat.conf.js
new file mode 100644
index 000000000..cd2dbdcdc
--- /dev/null
+++ b/test/flat.conf.js
@@ -0,0 +1,8 @@
+const getBaseConfig = require('./base.conf.js')
+
+module.exports = function(config) {
+ const settings = getBaseConfig(config)
+ settings.files.push('development/bundle.js')
+ settings.files.push('test/integration/bundle.js')
+ config.set(settings)
+}
diff --git a/test/integration/helpers.js b/test/integration/helpers.js
deleted file mode 100644
index 10cd74e64..000000000
--- a/test/integration/helpers.js
+++ /dev/null
@@ -1,7 +0,0 @@
-function wait(time) {
- return new Promise(function (resolve, reject) {
- setTimeout(function () {
- resolve()
- }, time * 3 || 1500)
- })
-}
diff --git a/test/integration/index.js b/test/integration/index.js
index e089fc39b..144303dbb 100644
--- a/test/integration/index.js
+++ b/test/integration/index.js
@@ -1,5 +1,6 @@
const fs = require('fs')
const path = require('path')
+const pump = require('pump')
const browserify = require('browserify')
const tests = fs.readdirSync(path.join(__dirname, 'lib'))
const bundlePath = path.join(__dirname, 'bundle.js')
@@ -9,11 +10,17 @@ const b = browserify()
const writeStream = fs.createWriteStream(bundlePath)
tests.forEach(function (fileName) {
- b.add(path.join(__dirname, 'lib', fileName))
+ const filePath = path.join(__dirname, 'lib', fileName)
+ console.log(`bundling test "${filePath}"`)
+ b.add(filePath)
})
-b.bundle()
-.pipe(writeStream)
-.on('error', (err) => {
- throw err
-})
+pump(
+ b.bundle(),
+ writeStream,
+ (err) => {
+ if (err) throw err
+ console.log(`Integration test build completed: "${bundlePath}"`)
+ process.exit(0)
+ }
+) \ No newline at end of file
diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js
index 0e4b802da..cedb14f6e 100644
--- a/test/integration/lib/first-time.js
+++ b/test/integration/lib/first-time.js
@@ -2,125 +2,130 @@ const PASSWORD = 'password123'
QUnit.module('first time usage')
-QUnit.test('render init screen', function (assert) {
- var done = assert.async()
- let app
-
- wait().then(function() {
- app = $('iframe').contents().find('#app-content .mock-app-root')
-
- const recurseNotices = function () {
- let button = app.find('button')
- if (button.html() === 'Accept') {
- let termsPage = app.find('.markdown')[0]
- termsPage.scrollTop = termsPage.scrollHeight
- return wait().then(() => {
- button.click()
- return wait()
- }).then(() => {
- return recurseNotices()
- })
- } else {
- return wait()
- }
+QUnit.test('render init screen', (assert) => {
+ const done = assert.async()
+ runFirstTimeUsageTest(assert).then(done).catch((err) => {
+ assert.notOk(err, `Error was thrown: ${err.stack}`)
+ done()
+ })
+})
+
+async function runFirstTimeUsageTest(assert, done) {
+ let waitTime = 0
+ if (window.METAMASK_PLATFORM_TYPE === 'mascara') waitTime = 4000
+ await timeout(waitTime)
+
+ const app = $('#app-content')
+
+ // recurse notices
+ while (true) {
+ const button = app.find('button')
+ if (button.html() === 'Accept') {
+ // still notices to accept
+ const termsPage = app.find('.markdown')[0]
+ termsPage.scrollTop = termsPage.scrollHeight
+ await timeout()
+ console.log('Clearing notice')
+ button.click()
+ await timeout()
+ } else {
+ // exit loop
+ console.log('No more notices...')
+ break
}
- return recurseNotices()
- }).then(function() {
- // Scroll through terms
- var title = app.find('h1').text()
- assert.equal(title, 'MetaMask', 'title screen')
+ }
- // enter password
- var pwBox = app.find('#password-box')[0]
- var confBox = app.find('#password-box-confirm')[0]
- pwBox.value = PASSWORD
- confBox.value = PASSWORD
+ await timeout()
- return wait()
- }).then(function() {
+ // Scroll through terms
+ const title = app.find('h1').text()
+ assert.equal(title, 'MetaMask', 'title screen')
- // create vault
- var createButton = app.find('button.primary')[0]
- createButton.click()
+ // enter password
+ const pwBox = app.find('#password-box')[0]
+ const confBox = app.find('#password-box-confirm')[0]
+ pwBox.value = PASSWORD
+ confBox.value = PASSWORD
- return wait(1500)
- }).then(function() {
+ await timeout()
- var created = app.find('h3')[0]
- assert.equal(created.textContent, 'Vault Created', 'Vault created screen')
+ // create vault
+ const createButton = app.find('button.primary')[0]
+ createButton.click()
- // Agree button
- var button = app.find('button')[0]
- assert.ok(button, 'button present')
- button.click()
+ await timeout(3000)
- return wait(1000)
- }).then(function() {
+ const created = app.find('h3')[0]
+ assert.equal(created.textContent, 'Vault Created', 'Vault created screen')
- var detail = app.find('.account-detail-section')[0]
- assert.ok(detail, 'Account detail section loaded.')
+ // Agree button
+ const button = app.find('button')[0]
+ assert.ok(button, 'button present')
+ button.click()
- var sandwich = app.find('.sandwich-expando')[0]
- sandwich.click()
+ await timeout(1000)
- return wait()
- }).then(function() {
+ const detail = app.find('.account-detail-section')[0]
+ assert.ok(detail, 'Account detail section loaded.')
- var sandwich = app.find('.menu-droppo')[0]
- var children = sandwich.children
- var lock = children[children.length - 2]
- assert.ok(lock, 'Lock menu item found')
- lock.click()
+ const sandwich = app.find('.sandwich-expando')[0]
+ sandwich.click()
- return wait(1000)
- }).then(function() {
+ await timeout()
- var pwBox = app.find('#password-box')[0]
- pwBox.value = PASSWORD
+ const menu = app.find('.menu-droppo')[0]
+ const children = menu.children
+ const lock = children[children.length - 2]
+ assert.ok(lock, 'Lock menu item found')
+ lock.click()
- var createButton = app.find('button.primary')[0]
- createButton.click()
+ await timeout(1000)
- return wait(1000)
- }).then(function() {
+ const pwBox2 = app.find('#password-box')[0]
+ pwBox2.value = PASSWORD
- var detail = app.find('.account-detail-section')[0]
- assert.ok(detail, 'Account detail section loaded again.')
+ const createButton2 = app.find('button.primary')[0]
+ createButton2.click()
- return wait()
- }).then(function (){
+ await timeout(1000)
- var qrButton = app.find('.fa.fa-ellipsis-h')[0] // open account settings dropdown
- qrButton.click()
+ const detail2 = app.find('.account-detail-section')[0]
+ assert.ok(detail2, 'Account detail section loaded again.')
- return wait(1000)
- }).then(function (){
+ await timeout()
- var qrButton = app.find('.dropdown-menu-item')[1] // qr code item
- qrButton.click()
+ // open account settings dropdown
+ const qrButton = app.find('.fa.fa-ellipsis-h')[0]
+ qrButton.click()
- return wait(1000)
- }).then(function (){
+ await timeout(1000)
- var qrHeader = app.find('.qr-header')[0]
- var qrContainer = app.find('#qr-container')[0]
- assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.')
- assert.ok(qrContainer, 'QR Container found')
+ // qr code item
+ const qrButton2 = app.find('.dropdown-menu-item')[1]
+ qrButton2.click()
- return wait()
- }).then(function (){
+ await timeout(1000)
- var networkMenu = app.find('.network-indicator')[0]
- networkMenu.click()
+ const qrHeader = app.find('.qr-header')[0]
+ const qrContainer = app.find('#qr-container')[0]
+ assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.')
+ assert.ok(qrContainer, 'QR Container found')
- return wait()
- }).then(function (){
+ await timeout()
- var networkMenu = app.find('.network-indicator')[0]
- var children = networkMenu.children
- children.length[3]
- assert.ok(children, 'All network options present')
+ const networkMenu = app.find('.network-indicator')[0]
+ networkMenu.click()
- done()
+ await timeout()
+
+ const networkMenu2 = app.find('.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/lib/mock-encryptor.js b/test/lib/mock-encryptor.js
index cdf13c507..ef229a82f 100644
--- a/test/lib/mock-encryptor.js
+++ b/test/lib/mock-encryptor.js
@@ -29,4 +29,8 @@ module.exports = {
return 'WHADDASALT!'
},
+ getRandomValues () {
+ return 'SOO RANDO!!!1'
+ }
+
}
diff --git a/test/mascara.conf.js b/test/mascara.conf.js
new file mode 100644
index 000000000..97e53fc2b
--- /dev/null
+++ b/test/mascara.conf.js
@@ -0,0 +1,17 @@
+const getBaseConfig = require('./base.conf.js')
+
+module.exports = function(config) {
+ const settings = getBaseConfig(config)
+
+ // ui and tests
+ settings.files.push('dist/mascara/ui.js')
+ settings.files.push('dist/mascara/tests.js')
+ // service worker background
+ settings.files.push({ pattern: 'dist/mascara/background.js', watched: false, included: false, served: true }),
+ settings.proxies['/background.js'] = '/base/dist/mascara/background.js'
+
+ // use this to keep the browser open for debugging
+ settings.browserNoActivityTimeout = 10000000
+
+ config.set(settings)
+}
diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js
index 906564558..20feba2a3 100644
--- a/test/unit/components/pending-tx-test.js
+++ b/test/unit/components/pending-tx-test.js
@@ -35,10 +35,15 @@ describe('PendingTx', function () {
const renderer = ReactTestUtils.createRenderer()
const newGasPrice = '0x77359400'
+ const computedBalances = {}
+ computedBalances[Object.keys(identities)[0]] = {
+ ethBalance: '0x00000000000000056bc75e2d63100000',
+ }
const props = {
identities,
accounts: identities,
txData,
+ computedBalances,
sendTransaction: (txMeta, event) => {
// Assert changes:
const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice)
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index 2d9a53723..135edf365 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -24,15 +24,12 @@ describe('KeyringController', function () {
getTxList: () => [],
getUnapprovedTxList: () => [],
},
- ethStore: {
+ accountTracker: {
addAccount (acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
},
+ encryptor: mockEncryptor,
})
- // Stub out the browser crypto for a mock encryptor.
- // Browser crypto is tested in the integration test suite.
- keyringController.encryptor = mockEncryptor
-
keyringController.createNewVaultAndKeychain(password)
.then(function (newState) {
newState
diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js
index 3312a3bd0..8970cf84d 100644
--- a/test/unit/nonce-tracker-test.js
+++ b/test/unit/nonce-tracker-test.js
@@ -162,6 +162,25 @@ describe('Nonce Tracker', function () {
await nonceLock.releaseLock()
})
})
+
+ describe('Faq issue 67', function () {
+ beforeEach(function () {
+ const txGen = new MockTxGen()
+ const confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 64 })
+ const pendingTxs = txGen.generate({
+ status: 'submitted',
+ }, { count: 10 })
+ // 0x40 is 64 in hex:
+ nonceTracker = generateNonceTrackerWith(pendingTxs, [], '0x40')
+ })
+
+ it('should return nonce after network nonce', async function () {
+ this.timeout(15000)
+ const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926')
+ assert.equal(nonceLock.nextNonce, '74', `nonce should be 74 got ${nonceLock.nextNonce}`)
+ await nonceLock.releaseLock()
+ })
+ })
})
})
diff --git a/test/unit/pending-balance-test.js b/test/unit/pending-balance-test.js
new file mode 100644
index 000000000..5048d487b
--- /dev/null
+++ b/test/unit/pending-balance-test.js
@@ -0,0 +1,93 @@
+const assert = require('assert')
+const PendingBalanceCalculator = require('../../app/scripts/lib/pending-balance-calculator')
+const MockTxGen = require('../lib/mock-tx-gen')
+const BN = require('ethereumjs-util').BN
+let providerResultStub = {}
+
+const zeroBn = new BN(0)
+const etherBn = new BN(String(1e18))
+const ether = '0x' + etherBn.toString(16)
+
+describe('PendingBalanceCalculator', function () {
+ let balanceCalculator
+
+ describe('#calculateMaxCost(tx)', function () {
+ it('returns a BN for a given tx value', function () {
+ const txGen = new MockTxGen()
+ pendingTxs = txGen.generate({
+ status: 'submitted',
+ txParams: {
+ value: ether,
+ gasPrice: '0x0',
+ gas: '0x0',
+ }
+ }, { count: 1 })
+
+ const balanceCalculator = generateBalanceCalcWith([], zeroBn)
+ const result = balanceCalculator.calculateMaxCost(pendingTxs[0])
+ assert.equal(result.toString(), etherBn.toString(), 'computes one ether')
+ })
+
+ it('calculates gas costs as well', function () {
+ const txGen = new MockTxGen()
+ pendingTxs = txGen.generate({
+ status: 'submitted',
+ txParams: {
+ value: '0x0',
+ gasPrice: '0x2',
+ gas: '0x3',
+ }
+ }, { count: 1 })
+
+ const balanceCalculator = generateBalanceCalcWith([], zeroBn)
+ const result = balanceCalculator.calculateMaxCost(pendingTxs[0])
+ assert.equal(result.toString(), '6', 'computes 6 wei of gas')
+ })
+ })
+
+ describe('if you have no pending txs and one ether', function () {
+
+ beforeEach(function () {
+ balanceCalculator = generateBalanceCalcWith([], etherBn)
+ })
+
+ it('returns the network balance', async function () {
+ const result = await balanceCalculator.getBalance()
+ assert.equal(result, ether, `gave ${result} needed ${ether}`)
+ })
+ })
+
+ describe('if you have a one ether pending tx and one ether', function () {
+ beforeEach(function () {
+ const txGen = new MockTxGen()
+ pendingTxs = txGen.generate({
+ status: 'submitted',
+ txParams: {
+ value: ether,
+ gasPrice: '0x0',
+ gas: '0x0',
+ }
+ }, { count: 1 })
+
+ balanceCalculator = generateBalanceCalcWith(pendingTxs, etherBn)
+ })
+
+ it('returns the subtracted result', async function () {
+ const result = await balanceCalculator.getBalance()
+ assert.equal(result, '0x0', `gave ${result} needed '0x0'`)
+ return true
+ })
+
+ })
+})
+
+function generateBalanceCalcWith (transactions, providerStub = zeroBn) {
+ const getPendingTransactions = async () => transactions
+ const getBalance = async () => providerStub
+
+ return new PendingBalanceCalculator({
+ getBalance,
+ getPendingTransactions,
+ })
+}
+
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index 47bfe66f8..8d45fb9b5 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -27,7 +27,7 @@ describe('Transaction Controller', function () {
networkStore: new ObservableStore(currentNetworkId),
txHistoryLimit: 10,
blockTracker: { getCurrentBlock: noop, on: noop, once: noop },
- ethStore: { getState: noop },
+ accountTracker: { getState: noop },
signTransaction: (ethTx) => new Promise((resolve) => {
ethTx.sign(privKey)
resolve()
@@ -286,4 +286,4 @@ describe('Transaction Controller', function () {
}).catch(done)
})
})
-}) \ No newline at end of file
+})