From ce147bf6d8431f4f0cb5b4de46a5af9628b3e9e2 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 16 Nov 2018 08:34:08 -1000 Subject: Tx controller now uses safe event emitter (#5769) * transactions - use safe-event-emitter over events * tests - pass a platform object on init with a noop showTransactionNotification * test - fix for tx-state-history-helper trying to reduce an empty array * deps - safe-event-emitter * lint --- test/lib/mock-tx-gen.js | 1 + .../app/controllers/metamask-controller-test.js | 1 + .../controllers/transactions/pending-tx-test.js | 2 + .../controllers/transactions/tx-controller-test.js | 48 +++++++++++----------- 4 files changed, 28 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/lib/mock-tx-gen.js b/test/lib/mock-tx-gen.js index 106101500..e39551a7a 100644 --- a/test/lib/mock-tx-gen.js +++ b/test/lib/mock-tx-gen.js @@ -2,6 +2,7 @@ const extend = require('xtend') const BN = require('ethereumjs-util').BN const template = { 'status': 'submitted', + 'history': [{}], 'txParams': { 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', 'gas': '0x30d40', diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js index 17be2c028..1ed6a95fb 100644 --- a/test/unit/app/controllers/metamask-controller-test.js +++ b/test/unit/app/controllers/metamask-controller-test.js @@ -58,6 +58,7 @@ describe('MetaMaskController', function () { }, }, initState: clone(firstTimeState), + platform: { showTransactionNotification: () => {} }, }) // disable diagnostics metamaskController.diagnostics = null diff --git a/test/unit/app/controllers/transactions/pending-tx-test.js b/test/unit/app/controllers/transactions/pending-tx-test.js index 85b0969f5..2988bf61f 100644 --- a/test/unit/app/controllers/transactions/pending-tx-test.js +++ b/test/unit/app/controllers/transactions/pending-tx-test.js @@ -20,10 +20,12 @@ describe('PendingTransactionTracker', function () { nonce: '0x1', value: '0xfffff', }, + history: [{}], rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d', } txMetaNoHash = { id: 2, + history: [{}], status: 'submitted', txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d'}, } diff --git a/test/unit/app/controllers/transactions/tx-controller-test.js b/test/unit/app/controllers/transactions/tx-controller-test.js index 7f1d8e6f5..b76f256b9 100644 --- a/test/unit/app/controllers/transactions/tx-controller-test.js +++ b/test/unit/app/controllers/transactions/tx-controller-test.js @@ -52,9 +52,9 @@ describe('Transaction Controller', function () { describe('#getUnapprovedTxCount', function () { it('should return the number of unapproved txs', function () { txController.txStateManager._saveTxList([ - { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] }, - { id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] }, - { id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] }, + { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, ]) const unapprovedTxCount = txController.getUnapprovedTxCount() assert.equal(unapprovedTxCount, 3, 'should be 3') @@ -64,9 +64,9 @@ describe('Transaction Controller', function () { describe('#getPendingTxCount', function () { it('should return the number of pending txs', function () { txController.txStateManager._saveTxList([ - { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] }, - { id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] }, - { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] }, + { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, ]) const pendingTxCount = txController.getPendingTxCount() assert.equal(pendingTxCount, 3, 'should be 3') @@ -82,15 +82,15 @@ describe('Transaction Controller', function () { 'to': '0xc684832530fcbddae4b4230a47e991ddcec2831d', } txController.txStateManager._saveTxList([ - {id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] }, - {id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams, history: [] }, + {id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, + {id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, ]) }) @@ -112,7 +112,7 @@ describe('Transaction Controller', function () { id: 1, metamaskNetworkId: currentNetworkId, txParams, - history: [], + history: [{}], } txController.txStateManager._saveTxList([txMeta]) stub = sinon.stub(txController, 'addUnapprovedTransaction').callsFake(() => { @@ -232,7 +232,7 @@ describe('Transaction Controller', function () { from: '0xc684832530fcbddae4b4230a47e991ddcec2831d', to: '0xc684832530fcbddae4b4230a47e991ddcec2831d', }, - history: [], + history: [{}], } providerResultStub.eth_gasPrice = '4a817c800' providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' } @@ -423,7 +423,7 @@ describe('Transaction Controller', function () { data: '0x0', } txController.txStateManager._saveTxList([ - { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] }, + { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [{}] }, ]) txController.retryTransaction(1) .then((txMeta) => { @@ -462,12 +462,12 @@ describe('Transaction Controller', function () { beforeEach(function () { txController.txStateManager._saveTxList([ { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, - { id: 2, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {} }, - { id: 3, status: 'approved', metamaskNetworkId: currentNetworkId, txParams: {} }, - { id: 4, status: 'signed', metamaskNetworkId: currentNetworkId, txParams: {} }, - { id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} }, - { id: 6, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, - { id: 7, status: 'failed', metamaskNetworkId: currentNetworkId, txParams: {} }, + { id: 2, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 3, status: 'approved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 4, status: 'signed', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 6, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, + { id: 7, status: 'failed', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] }, ]) }) it('should show only submitted and approved transactions as pending transasction', function () { -- cgit v1.2.3 From 1988e1e96b09a47ad5428083bb2ed38cb2d7e0a8 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Fri, 16 Nov 2018 21:24:55 -0330 Subject: ESLint fixes (#5775) * eslint . --fix * Upgrade all ESLint warnings to errors --- test/unit/app/controllers/preferences-controller-test.js | 6 +++--- test/unit/ui/app/reducers/metamask.spec.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js index 473f22f8b..67d1875c1 100644 --- a/test/unit/app/controllers/preferences-controller-test.js +++ b/test/unit/app/controllers/preferences-controller-test.js @@ -515,14 +515,14 @@ describe('preferences controller', function () { it('should add custom RPC url to state', function () { preferencesController.addToFrequentRpcList('rpc_url', 1) preferencesController.addToFrequentRpcList('http://localhost:8545', 1) - assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }]) preferencesController.addToFrequentRpcList('rpc_url', 1) - assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }]) }) it('should remove custom RPC url from state', function () { preferencesController.addToFrequentRpcList('rpc_url', 1) - assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }]) preferencesController.removeFromFrequentRpcList('other_rpc_url') preferencesController.removeFromFrequentRpcList('http://localhost:8545') preferencesController.removeFromFrequentRpcList('rpc_url') diff --git a/test/unit/ui/app/reducers/metamask.spec.js b/test/unit/ui/app/reducers/metamask.spec.js index e1a50eef2..502e7ef33 100644 --- a/test/unit/ui/app/reducers/metamask.spec.js +++ b/test/unit/ui/app/reducers/metamask.spec.js @@ -5,7 +5,7 @@ import * as actions from '../../../../../ui/app/actions' describe('MetaMask Reducers', () => { it('init state', () => { - const initState = reduceMetamask({metamask:{}}, {}) + const initState = reduceMetamask({metamask: {}}, {}) assert(initState) }) -- cgit v1.2.3 From fdea642e6d5b23d4573759e4f1a1f4016557c0be Mon Sep 17 00:00:00 2001 From: Dan Finlay <542863+danfinlay@users.noreply.github.com> Date: Fri, 16 Nov 2018 21:27:01 -0800 Subject: Auto fail transactions that have been approved for over 12 hours (#5765) * Auto fail transactions that have been approved for over 12 hours Converts txs using a migration. This migration uses a new helper function that generates tx-failing migrations, and only requires a version, error message, and condition to run on each transaction. * Linted * Only migrate approved txs to failed * Cleanup * Cleanup * Small lint fixes --- test/unit/migrations/029-test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/unit/migrations/029-test.js (limited to 'test') diff --git a/test/unit/migrations/029-test.js b/test/unit/migrations/029-test.js new file mode 100644 index 000000000..a2876487b --- /dev/null +++ b/test/unit/migrations/029-test.js @@ -0,0 +1,38 @@ +const assert = require('assert') +const migration29 = require('../../../app/scripts/migrations/029') +const properTime = (new Date()).getTime() +const storage = { + 'meta': {}, + 'data': { + 'TransactionController': { + 'transactions': [ + { 'status': 'approved', id: 1, submittedTime: 0 }, + { 'status': 'approved', id: 2, submittedTime: properTime }, + { 'status': 'confirmed', id: 3, submittedTime: properTime }, + { 'status': 'submitted', id: 4, submittedTime: properTime }, + { 'status': 'submitted', id: 5, submittedTime: 0 }, + ], + }, + }, +} + +describe('storage is migrated successfully where transactions that are submitted have submittedTimes', () => { + it('should auto fail transactions more than 12 hours old', (done) => { + migration29.migrate(storage) + .then((migratedData) => { + const txs = migratedData.data.TransactionController.transactions + const [ txMeta1 ] = txs + assert.equal(migratedData.meta.version, 29) + + assert.equal(txMeta1.status, 'failed', 'old tx is auto failed') + assert(txMeta1.err.message.includes('too long'), 'error message assigned') + + txs.forEach((tx) => { + if (tx.id === 1) return + assert.notEqual(tx.status, 'failed', 'other tx is not auto failed') + }) + + done() + }).catch(done) + }) +}) -- cgit v1.2.3 From 4c87c05a02d5bf5634234a74910e5d3e559dd413 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Mon, 19 Nov 2018 16:06:34 -0800 Subject: Fix rounding issue when sending max tokens (#5695) * Fix rounding issue when sending max tokens * Ensure amount row shows exact amount of max tokens on send screen (#2) * Fix tests * Change stored redux value from BigNumber to hex string. Fix TokenInput default value --- test/e2e/beta/metamask-beta-ui.spec.js | 8 ++++---- test/unit/ui/app/selectors.spec.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js index 2b5c8ee18..0ef945f8d 100644 --- a/test/e2e/beta/metamask-beta-ui.spec.js +++ b/test/e2e/beta/metamask-beta-ui.spec.js @@ -840,7 +840,7 @@ describe('MetaMask', function () { }) it('renders the balance for the new token', async () => { - const balance = await findElement(driver, By.css('.transaction-view-balance .transaction-view-balance__token-balance')) + const balance = await findElement(driver, By.css('.transaction-view-balance .transaction-view-balance__primary-balance')) await driver.wait(until.elementTextMatches(balance, /^100\s*TST\s*$/)) const tokenAmount = await balance.getText() assert.ok(/^100\s*TST\s*$/.test(tokenAmount)) @@ -1019,8 +1019,8 @@ describe('MetaMask', function () { // test cancelled on firefox until https://github.com/mozilla/geckodriver/issues/906 is resolved, // or possibly until we use latest version of firefox in the tests if (process.env.SELENIUM_BROWSER !== 'firefox') { - const tokenBalanceAmount = await findElement(driver, By.css('.transaction-view-balance__token-balance')) - assert.equal(await tokenBalanceAmount.getText(), '43 TST') + const tokenBalanceAmount = await findElements(driver, By.css('.transaction-view-balance__primary-balance')) + await driver.wait(until.elementTextMatches(tokenBalanceAmount[0], /43\s*TST/)) } }) }) @@ -1180,7 +1180,7 @@ describe('MetaMask', function () { }) it('renders the balance for the chosen token', async () => { - const balance = await findElement(driver, By.css('.transaction-view-balance__token-balance')) + const balance = await findElement(driver, By.css('.transaction-view-balance__primary-balance')) await driver.wait(until.elementTextMatches(balance, /0\s*BAT/)) await delay(regularDelayMs) }) diff --git a/test/unit/ui/app/selectors.spec.js b/test/unit/ui/app/selectors.spec.js index 78c4267ee..e2b198abf 100644 --- a/test/unit/ui/app/selectors.spec.js +++ b/test/unit/ui/app/selectors.spec.js @@ -148,7 +148,7 @@ describe('Selectors', function () { it('#getSelectedTokenToFiatRate', () => { const selectedTokenToFiatRate = selectors.getSelectedTokenToFiatRate(mockState) - assert.equal(selectedTokenToFiatRate, '0.21880988420033493') + assert.equal(selectedTokenToFiatRate, '0.21880988420033492152') }) describe('#getSelectedTokenContract', () => { -- cgit v1.2.3 From 5956f8d260270d41f1e5be53f3c058782a1ae7f4 Mon Sep 17 00:00:00 2001 From: Dan Finlay <542863+danfinlay@users.noreply.github.com> Date: Tue, 20 Nov 2018 10:34:14 -0800 Subject: Version 5.0.3 (#5785) * Version 5.0.3 Includes a fix to the `version:bump` script that now correctly updates the changelog header. * Include inpage provider events --- test/unit/development/sample-changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/development/sample-changelog.md b/test/unit/development/sample-changelog.md index fd980e375..69f6513e6 100644 --- a/test/unit/development/sample-changelog.md +++ b/test/unit/development/sample-changelog.md @@ -1,6 +1,6 @@ # Changelog -## Current Master +## Current Develop Branch ## 4.1.3 2018-2-28 -- cgit v1.2.3