diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-01-15 14:51:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-15 14:51:13 +0800 |
commit | 86c0eaa5a430c1837f9ae203e3f0cadb88d0b777 (patch) | |
tree | 8100ded20ce5ea1154360e3715e2153f64ed3c7b /test | |
parent | c1253016fcd678445e860a666ee8c4e04506f01a (diff) | |
parent | 85634326e8b7fd077b36d4b007190da2a66d6a89 (diff) | |
download | tangerine-wallet-browser-86c0eaa5a430c1837f9ae203e3f0cadb88d0b777.tar tangerine-wallet-browser-86c0eaa5a430c1837f9ae203e3f0cadb88d0b777.tar.gz tangerine-wallet-browser-86c0eaa5a430c1837f9ae203e3f0cadb88d0b777.tar.bz2 tangerine-wallet-browser-86c0eaa5a430c1837f9ae203e3f0cadb88d0b777.tar.lz tangerine-wallet-browser-86c0eaa5a430c1837f9ae203e3f0cadb88d0b777.tar.xz tangerine-wallet-browser-86c0eaa5a430c1837f9ae203e3f0cadb88d0b777.tar.zst tangerine-wallet-browser-86c0eaa5a430c1837f9ae203e3f0cadb88d0b777.zip |
Merge pull request #1002 from MetaMask/bug-submitTx
handle tx finalization in controllers instead of provider-engine
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/metamask-controller-test.js | 18 | ||||
-rw-r--r-- | test/unit/notice-controller-test.js | 5 | ||||
-rw-r--r-- | test/unit/tx-manager-test.js | 69 |
3 files changed, 50 insertions, 42 deletions
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 414610404..a6164c9a0 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -25,24 +25,6 @@ describe('MetaMaskController', function() { this.sinon.restore() }) - describe('#enforceTxValidations', function () { - it('returns null for positive values', function() { - var sample = { - value: '0x01' - } - var res = controller.enforceTxValidations(sample) - assert.equal(res, null, 'no error') - }) - - - it('returns error for negative values', function() { - var sample = { - value: '-0x01' - } - var res = controller.enforceTxValidations(sample) - assert.ok(res, 'error') - }) - }) }) diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js index 4aa4c8e7b..cf00daeba 100644 --- a/test/unit/notice-controller-test.js +++ b/test/unit/notice-controller-test.js @@ -5,13 +5,14 @@ const nock = require('nock') const configManagerGen = require('../lib/mock-config-manager') const NoticeController = require('../../app/scripts/notice-controller') const STORAGE_KEY = 'metamask-persistance-key' -// Hacking localStorage support into JSDom -window.localStorage = {} describe('notice-controller', function() { var noticeController beforeEach(function() { + // simple localStorage polyfill + window.localStorage = {} + if (window.localStorage.clear) window.localStorage.clear() let configManager = configManagerGen() noticeController = new NoticeController({ configManager: configManager, diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js index be16facad..a66003f85 100644 --- a/test/unit/tx-manager-test.js +++ b/test/unit/tx-manager-test.js @@ -15,6 +15,28 @@ describe('Transaction Manager', function() { provider: "testnet", txHistoryLimit: 10, blockTracker: new EventEmitter(), + getNetwork: function(){ return 'unit test' } + }) + }) + + describe('#validateTxParams', function () { + it('returns null for positive values', function() { + var sample = { + value: '0x01' + } + var res = txManager.txProviderUtils.validateTxParams(sample, (err) => { + assert.equal(err, null, 'no error') + }) + }) + + + it('returns error for negative values', function() { + var sample = { + value: '-0x01' + } + var res = txManager.txProviderUtils.validateTxParams(sample, (err) => { + assert.ok(err, 'error') + }) }) }) @@ -31,7 +53,7 @@ describe('Transaction Manager', function() { describe('#_saveTxList', function() { it('saves the submitted data to the tx list', function() { - var target = [{ foo: 'bar' }] + var target = [{ foo: 'bar', metamaskNetworkId: 'unit test' }] txManager._saveTxList(target) var result = txManager.getTxList() assert.equal(result[0].foo, 'bar') @@ -40,7 +62,7 @@ describe('Transaction Manager', function() { describe('#addTx', function() { it('adds a tx returned in getTxList', function() { - var tx = { id: 1, status: 'confirmed',} + var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) var result = txManager.getTxList() assert.ok(Array.isArray(result)) @@ -51,7 +73,7 @@ describe('Transaction Manager', function() { it('cuts off early txs beyond a limit', function() { const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'confirmed'} + let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) } var result = txManager.getTxList() @@ -59,10 +81,10 @@ describe('Transaction Manager', function() { assert.equal(result[0].id, 1, 'early txs truncted') }) - it('cuts off early txs beyond a limit weather or not it is confirmed or rejected', function() { + it('cuts off early txs beyond a limit whether or not it is confirmed or rejected', function() { const limit = txManager.txHistoryLimit for (let i = 0; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'rejected'} + let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) } var result = txManager.getTxList() @@ -71,11 +93,11 @@ describe('Transaction Manager', function() { }) it('cuts off early txs beyond a limit but does not cut unapproved txs', function() { - var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved'} + var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: 'unit test' } txManager.addTx(unconfirmedTx, onTxDoneCb) const limit = txManager.txHistoryLimit for (let i = 1; i < limit + 1; i++) { - let tx = { id: i, time: new Date(), status: 'confirmed'} + let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) } var result = txManager.getTxList() @@ -88,7 +110,7 @@ describe('Transaction Manager', function() { describe('#setTxStatusSigned', function() { it('sets the tx status to signed', function() { - var tx = { id: 1, status: 'unapproved' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } txManager.addTx(tx, onTxDoneCb) txManager.setTxStatusSigned(1) var result = txManager.getTxList() @@ -99,20 +121,21 @@ describe('Transaction Manager', function() { it('should emit a signed event to signal the exciton of callback', (done) => { this.timeout(10000) - var tx = { id: 1, status: 'unapproved' } - let onTxDoneCb = function (err, txId) { + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + let onTxDoneCb = function () { assert(true, 'event listener has been triggered and onTxDoneCb executed') done() } - txManager.addTx(tx, onTxDoneCb) + txManager.addTx(tx) + txManager.on('1:signed', onTxDoneCb) txManager.setTxStatusSigned(1) }) }) describe('#setTxStatusRejected', function() { it('sets the tx status to rejected', function() { - var tx = { id: 1, status: 'unapproved' } - txManager.addTx(tx, onTxDoneCb) + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + txManager.addTx(tx) txManager.setTxStatusRejected(1) var result = txManager.getTxList() assert.ok(Array.isArray(result)) @@ -122,12 +145,13 @@ describe('Transaction Manager', function() { it('should emit a rejected event to signal the exciton of callback', (done) => { this.timeout(10000) - var tx = { id: 1, status: 'unapproved' } + var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' } + txManager.addTx(tx) let onTxDoneCb = function (err, txId) { assert(true, 'event listener has been triggered and onTxDoneCb executed') done() } - txManager.addTx(tx, onTxDoneCb) + txManager.on('1:rejected', onTxDoneCb) txManager.setTxStatusRejected(1) }) @@ -135,9 +159,9 @@ describe('Transaction Manager', function() { describe('#updateTx', function() { it('replaces the tx with the same id', function() { - txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) - txManager.updateTx({ id: '1', status: 'blah', hash: 'foo' }) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' }) var result = txManager.getTx('1') assert.equal(result.hash, 'foo') }) @@ -145,8 +169,8 @@ describe('Transaction Manager', function() { describe('#getUnapprovedTxList', function() { it('returns unapproved txs in a hash', function() { - txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) let result = txManager.getUnapprovedTxList() assert.equal(typeof result, 'object') assert.equal(result['1'].status, 'unapproved') @@ -156,8 +180,8 @@ describe('Transaction Manager', function() { describe('#getTx', function() { it('returns a tx with the requested id', function() { - txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb) - txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb) + txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb) + txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb) assert.equal(txManager.getTx('1').status, 'unapproved') assert.equal(txManager.getTx('2').status, 'confirmed') }) @@ -171,6 +195,7 @@ describe('Transaction Manager', function() { let everyOther = i % 2 txManager.addTx({ id: i, status: everyOther ? 'unapproved' : 'confirmed', + metamaskNetworkId: 'unit test', txParams: { from: everyOther ? 'foop' : 'zoop', to: everyOther ? 'zoop' : 'foop', |