aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@users.noreply.github.com>2017-12-23 03:40:20 +0800
committerGitHub <noreply@github.com>2017-12-23 03:40:20 +0800
commit409d1d30e9d836926e5361fb9e4b5b025b66e313 (patch)
treec7f247d1e973c50697af8b9905d9fd40d4575659 /test/unit
parentb944a63ff89e3c45f7d7e49b2d93a5442cde4462 (diff)
parent5a58add797fcdbb023678af84a61f1d2bfdafaf1 (diff)
downloadtangerine-wallet-browser-409d1d30e9d836926e5361fb9e4b5b025b66e313.tar.gz
tangerine-wallet-browser-409d1d30e9d836926e5361fb9e4b5b025b66e313.tar.zst
tangerine-wallet-browser-409d1d30e9d836926e5361fb9e4b5b025b66e313.zip
Merge pull request #2799 from MetaMask/NewUI-flat
Update UAT to version 4.0.5
Diffstat (limited to 'test/unit')
-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
7 files changed, 154 insertions, 27 deletions
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 () {