aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/base.conf.js4
-rw-r--r--test/helper.js4
-rw-r--r--test/integration/lib/mascara-first-time.js59
-rw-r--r--test/lib/shallow-with-store.js15
-rw-r--r--test/unit/actions/tx_test.js3
-rw-r--r--test/unit/components/balance-component-test.js2
-rw-r--r--test/unit/components/pending-tx-test.js2
-rw-r--r--test/unit/metamask-controller-test.js33
-rw-r--r--test/unit/pending-tx-test.js87
-rw-r--r--test/unit/preferences-controller-test.js48
-rw-r--r--test/unit/responsive/components/dropdown-test.js6
11 files changed, 195 insertions, 68 deletions
diff --git a/test/base.conf.js b/test/base.conf.js
index 122392822..82b9d8eec 100644
--- a/test/base.conf.js
+++ b/test/base.conf.js
@@ -54,6 +54,8 @@ module.exports = function(config) {
// Concurrency level
// how many browser should be started simultaneous
- concurrency: Infinity
+ concurrency: 1,
+
+ nocache: true,
}
}
diff --git a/test/helper.js b/test/helper.js
index 1c5934a89..a3abbebf2 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -1,3 +1,7 @@
+import Enzyme from 'enzyme'
+import Adapter from 'enzyme-adapter-react-15'
+
+Enzyme.configure({ adapter: new Adapter() })
// disallow promises from swallowing errors
enableFailureOnUnhandledPromiseRejection()
diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js
index 398ecea0e..515c7f383 100644
--- a/test/integration/lib/mascara-first-time.js
+++ b/test/integration/lib/mascara-first-time.js
@@ -6,23 +6,7 @@ async function runFirstTimeUsageTest (assert, done) {
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
- }
- }
+ await skipNotices(app)
await timeout()
@@ -51,28 +35,13 @@ async function runFirstTimeUsageTest (assert, done) {
assert.equal(created.textContent, 'Your unique account image', 'unique image screen')
// Agree button
- const button = app.find('button')[0]
+ let button = app.find('button')[0]
assert.ok(button, 'button present')
button.click()
await timeout(1000)
- // Privacy Screen
- const detail = app.find('.tou__title')[0]
- assert.equal(detail.textContent, 'Privacy Notice', 'privacy notice screen')
- app.find('button').click()
-
- await timeout(1000)
-
-
- // terms of service screen
- const tou = app.find('.tou__title')[0]
- assert.equal(tou.textContent, 'Terms of Use', 'terms of use screen')
- app.find('.tou__body').scrollTop(100000)
- await timeout(1000)
-
- app.find('.first-time-flow__button').click()
- await timeout(1000)
+ await skipNotices(app)
// secret backup phrase
const seedTitle = app.find('.backup-phrase__title')[0]
@@ -156,4 +125,24 @@ function timeout (time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time || 1500)
})
-} \ No newline at end of file
+}
+
+async function skipNotices (app) {
+ while (true) {
+ const button = app.find('button')
+ if (button && button.html() === 'Accept') {
+ // still notices to accept
+ const termsPage = app.find('.markdown')[0]
+ if (!termsPage) {
+ break
+ }
+ termsPage.scrollTop = termsPage.scrollHeight
+ await timeout()
+ button.click()
+ await timeout()
+ } else {
+ console.log('No more notices...')
+ break
+ }
+ }
+}
diff --git a/test/lib/shallow-with-store.js b/test/lib/shallow-with-store.js
index 411aa0455..2a66adb17 100644
--- a/test/lib/shallow-with-store.js
+++ b/test/lib/shallow-with-store.js
@@ -1,11 +1,16 @@
-const shallow = require('enzyme').shallow
+const { shallow, mount } = require('enzyme')
-module.exports = shallowWithStore
-
-function shallowWithStore (component, store) {
+exports.shallowWithStore = function shallowWithStore (component, store) {
const context = {
store,
}
return shallow(component, { context })
-};
+}
+
+exports.mountWithStore = function mountWithStore (component, store) {
+ const context = {
+ store,
+ }
+ return mount(component, { context })
+}
diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js
index ea6dfda6a..b6a691860 100644
--- a/test/unit/actions/tx_test.js
+++ b/test/unit/actions/tx_test.js
@@ -51,9 +51,8 @@ describe('tx confirmation screen', function () {
actions.cancelTx({value: firstTxId})((action) => {
result = reducers(initialState, action)
- done()
})
-
+ done()
})
it('should transition to the account detail view', function () {
diff --git a/test/unit/components/balance-component-test.js b/test/unit/components/balance-component-test.js
index a5fededc8..9b1e82acf 100644
--- a/test/unit/components/balance-component-test.js
+++ b/test/unit/components/balance-component-test.js
@@ -1,7 +1,7 @@
const assert = require('assert')
const h = require('react-hyperscript')
const { createMockStore } = require('redux-test-utils')
-const shallowWithStore = require('../../lib/shallow-with-store')
+const { shallowWithStore } = require('../../lib/shallow-with-store')
const BalanceComponent = require('../../../ui/app/components/balance-component')
const mockState = {
metamask: {
diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js
index 97cac3216..c6c588e1c 100644
--- a/test/unit/components/pending-tx-test.js
+++ b/test/unit/components/pending-tx-test.js
@@ -4,7 +4,7 @@ const PendingTx = require('../../../ui/app/components/pending-tx')
const ethUtil = require('ethereumjs-util')
const { createMockStore } = require('redux-test-utils')
-const shallowWithStore = require('../../lib/shallow-with-store')
+const { shallowWithStore } = require('../../lib/shallow-with-store')
const identities = { abc: {}, def: {} }
const mockState = {
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js
index ef6cae758..fd420a70f 100644
--- a/test/unit/metamask-controller-test.js
+++ b/test/unit/metamask-controller-test.js
@@ -11,6 +11,15 @@ describe('MetaMaskController', function () {
unlockAccountMessage: noop,
showUnapprovedTx: noop,
platform: {},
+ encryptor: {
+ encrypt: function(password, object) {
+ this.object = object
+ return Promise.resolve()
+ },
+ decrypt: function () {
+ return Promise.resolve(this.object)
+ }
+ },
// initial state
initState: clone(firstTimeState),
})
@@ -27,6 +36,30 @@ describe('MetaMaskController', function () {
describe('Metamask Controller', function () {
assert(metamaskController)
+
+ beforeEach(function () {
+ sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain')
+ })
+
+ afterEach(function () {
+ metamaskController.keyringController.createNewVaultAndKeychain.restore()
+ })
+
+ describe('#createNewVaultAndKeychain', function () {
+ it('can only create new vault on keyringController once', async function () {
+
+ const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity')
+
+ const password = 'a-fake-password'
+
+ const first = await metamaskController.createNewVaultAndKeychain(password)
+ const second = await metamaskController.createNewVaultAndKeychain(password)
+
+ assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce)
+
+ selectStub.reset()
+ })
+ })
})
})
diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js
index 32117a194..961fa6baf 100644
--- a/test/unit/pending-tx-test.js
+++ b/test/unit/pending-tx-test.js
@@ -207,6 +207,7 @@ describe('PendingTransactionTracker', function () {
})
describe('#resubmitPendingTxs', function () {
+ const blockStub = { number: '0x0' };
beforeEach(function () {
const txMeta2 = txMeta3 = txMeta
txList = [txMeta, txMeta2, txMeta3].map((tx) => {
@@ -224,7 +225,7 @@ describe('PendingTransactionTracker', function () {
Promise.all(txList.map((tx) => tx.processed))
.then((txCompletedList) => done())
.catch(done)
- pendingTxTracker.resubmitPendingTxs()
+ pendingTxTracker.resubmitPendingTxs(blockStub)
})
it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) {
knownErrors =[
@@ -251,7 +252,7 @@ describe('PendingTransactionTracker', function () {
.then((txCompletedList) => done())
.catch(done)
- pendingTxTracker.resubmitPendingTxs()
+ pendingTxTracker.resubmitPendingTxs(blockStub)
})
it('should emit \'tx:warning\' if it encountered a real error', function (done) {
pendingTxTracker.once('tx:warning', (txMeta, err) => {
@@ -269,28 +270,74 @@ describe('PendingTransactionTracker', function () {
.then((txCompletedList) => done())
.catch(done)
- pendingTxTracker.resubmitPendingTxs()
+ pendingTxTracker.resubmitPendingTxs(blockStub)
})
})
describe('#_resubmitTx', function () {
- it('should publishing the transaction', function (done) {
- const enoughBalance = '0x100000'
- pendingTxTracker.getBalance = (address) => {
- assert.equal(address, txMeta.txParams.from, 'Should pass the address')
- return enoughBalance
- }
- pendingTxTracker.publishTransaction = async (rawTx) => {
- assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx')
- }
+ const mockFirstRetryBlockNumber = '0x1'
+ let txMetaToTestExponentialBackoff
- // Stubbing out current account state:
- // Adding the fake tx:
- pendingTxTracker._resubmitTx(txMeta)
- .then(() => done())
- .catch((err) => {
- assert.ifError(err, 'should not throw an error')
- done(err)
+ beforeEach(() => {
+ pendingTxTracker.getBalance = (address) => {
+ assert.equal(address, txMeta.txParams.from, 'Should pass the address')
+ return enoughBalance
+ }
+ pendingTxTracker.publishTransaction = async (rawTx) => {
+ assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx')
+ }
+ sinon.spy(pendingTxTracker, 'publishTransaction')
+
+ txMetaToTestExponentialBackoff = Object.assign({}, txMeta, {
+ retryCount: 4,
+ firstRetryBlockNumber: mockFirstRetryBlockNumber,
+ })
+ })
+
+ afterEach(() => {
+ pendingTxTracker.publishTransaction.reset()
+ })
+
+ it('should publish the transaction', function (done) {
+ const enoughBalance = '0x100000'
+
+ // Stubbing out current account state:
+ // Adding the fake tx:
+ pendingTxTracker._resubmitTx(txMeta)
+ .then(() => done())
+ .catch((err) => {
+ assert.ifError(err, 'should not throw an error')
+ done(err)
+ })
+
+ assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction')
+ })
+
+ it('should not publish the transaction if the limit of retries has been exceeded', function (done) {
+ const enoughBalance = '0x100000'
+ const mockLatestBlockNumber = '0x5'
+
+ pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
+ .then(() => done())
+ .catch((err) => {
+ assert.ifError(err, 'should not throw an error')
+ done(err)
+ })
+
+ assert.equal(pendingTxTracker.publishTransaction.callCount, 0, 'Should NOT call publish transaction')
+ })
+
+ it('should publish the transaction if the number of blocks since last retry exceeds the last set limit', function (done) {
+ const enoughBalance = '0x100000'
+ const mockLatestBlockNumber = '0x11'
+
+ pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
+ .then(() => done())
+ .catch((err) => {
+ assert.ifError(err, 'should not throw an error')
+ done(err)
+ })
+
+ assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction')
})
- })
})
})
diff --git a/test/unit/preferences-controller-test.js b/test/unit/preferences-controller-test.js
new file mode 100644
index 000000000..9fb5e4251
--- /dev/null
+++ b/test/unit/preferences-controller-test.js
@@ -0,0 +1,48 @@
+const assert = require('assert')
+const PreferencesController = require('../../app/scripts/controllers/preferences')
+
+describe('preferences controller', function () {
+ let preferencesController
+
+ before(() => {
+ preferencesController = new PreferencesController()
+ })
+
+ describe('addToken', function () {
+ it('should add that token to its state', async function () {
+ const address = '0xabcdef1234567'
+ const symbol = 'ABBR'
+ const decimals = 5
+
+ await preferencesController.addToken(address, symbol, decimals)
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 1, 'one token added')
+
+ const added = tokens[0]
+ assert.equal(added.address, address, 'set address correctly')
+ assert.equal(added.symbol, symbol, 'set symbol correctly')
+ assert.equal(added.decimals, decimals, 'set decimals correctly')
+ })
+
+ it('should allow updating a token value', async function () {
+ const address = '0xabcdef1234567'
+ const symbol = 'ABBR'
+ const decimals = 5
+
+ await preferencesController.addToken(address, symbol, decimals)
+
+ const newDecimals = 6
+ await preferencesController.addToken(address, symbol, newDecimals)
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 1, 'one token added')
+
+ const added = tokens[0]
+ assert.equal(added.address, address, 'set address correctly')
+ assert.equal(added.symbol, symbol, 'set symbol correctly')
+ assert.equal(added.decimals, newDecimals, 'updated decimals correctly')
+ })
+ })
+})
+
diff --git a/test/unit/responsive/components/dropdown-test.js b/test/unit/responsive/components/dropdown-test.js
index 932b6c752..982d8c6ec 100644
--- a/test/unit/responsive/components/dropdown-test.js
+++ b/test/unit/responsive/components/dropdown-test.js
@@ -6,7 +6,7 @@ const path = require('path');
const Dropdown = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'app', 'components', 'dropdowns', 'index.js')).Dropdown;
const { createMockStore } = require('redux-test-utils')
-const shallowWithStore = require('../../../lib/shallow-with-store')
+const { mountWithStore } = require('../../../lib/shallow-with-store')
const mockState = {
metamask: {
@@ -39,7 +39,7 @@ describe('Dropdown components', function () {
onClick = sinon.spy();
store = createMockStore(mockState)
- component = shallowWithStore(h(
+ component = mountWithStore(h(
Dropdown,
dropdownComponentProps,
[
@@ -57,7 +57,7 @@ describe('Dropdown components', function () {
}, 'Item 2'),
]
), store)
- dropdownComponent = component.dive()
+ dropdownComponent = component
})
it('can render two items', function () {