diff options
author | Kevin Serrano <kevin.serrano@consensys.net> | 2017-10-10 23:38:27 +0800 |
---|---|---|
committer | Kevin Serrano <kevin.serrano@consensys.net> | 2017-10-10 23:38:27 +0800 |
commit | 1816eca9144b13b3e869e2c3c95476b27c3e3aba (patch) | |
tree | 356cc6269f6920bc20585e455811a43253fff777 /test/unit | |
parent | 24a55cf7770a6154fe723cf13cdc9998e1759f3b (diff) | |
parent | f18615a82abafee1a648e8de6f60ecc54e1aabb4 (diff) | |
download | tangerine-wallet-browser-1816eca9144b13b3e869e2c3c95476b27c3e3aba.tar.gz tangerine-wallet-browser-1816eca9144b13b3e869e2c3c95476b27c3e3aba.tar.zst tangerine-wallet-browser-1816eca9144b13b3e869e2c3c95476b27c3e3aba.zip |
Merge branch 'master' into version-debugging
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/components/bn-as-decimal-input-test.js | 38 | ||||
-rw-r--r-- | test/unit/nodeify-test.js | 7 | ||||
-rw-r--r-- | test/unit/pending-tx-test.js | 54 |
3 files changed, 94 insertions, 5 deletions
diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 106b3a871..58ecc9c89 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -48,4 +48,42 @@ describe('BnInput', function () { checkValidity () { return true } }, }) }) + + it('can tolerate wei precision', function (done) { + const renderer = ReactTestUtils.createRenderer() + + let valueStr = '1000000000' + + const value = new BN(valueStr, 10) + const inputStr = '1.000000001' + + + let targetStr = '1000000001' + + const target = new BN(targetStr, 10) + + const precision = 9 // gwei precision + const scale = 9 + + const props = { + value, + scale, + precision, + onChange: (newBn) => { + assert.equal(newBn.toString(), target.toString(), 'should tolerate increase') + const reInput = BnInput.prototype.downsize(newBn.toString(), 9, 9) + assert.equal(reInput.toString(), inputStr, 'should tolerate increase') + done() + }, + } + + const inputComponent = h(BnInput, props) + const component = additions.renderIntoDocument(inputComponent) + renderer.render(inputComponent) + const input = additions.find(component, 'input.hex-input')[0] + ReactTestUtils.Simulate.change(input, { preventDefault () {}, target: { + value: inputStr, + checkValidity () { return true } }, + }) + }) }) diff --git a/test/unit/nodeify-test.js b/test/unit/nodeify-test.js index 537dae605..c7b127889 100644 --- a/test/unit/nodeify-test.js +++ b/test/unit/nodeify-test.js @@ -18,14 +18,13 @@ describe('nodeify', function () { }) }) - it('should throw if the last argument is not a function', function (done) { + it('should allow the last argument to not be a function', function (done) { const nodified = nodeify(obj.promiseFunc, obj) try { nodified('baz') - done(new Error('should have thrown if the last argument is not a function')) - } catch (err) { - assert.equal(err.message, 'callback is not a function') done() + } catch (err) { + done(new Error('should not have thrown if the last argument is not a function')) } }) }) diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 6b62bb5b1..32421a44f 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -5,6 +5,8 @@ const ObservableStore = require('obs-store') const clone = require('clone') const { createStubedProvider } = require('../stub/provider') const PendingTransactionTracker = require('../../app/scripts/lib/pending-tx-tracker') +const MockTxGen = require('../lib/mock-tx-gen') +const sinon = require('sinon') const noop = () => true const currentNetworkId = 42 const otherNetworkId = 36 @@ -46,10 +48,60 @@ describe('PendingTransactionTracker', function () { } }, getPendingTransactions: () => {return []}, + getCompletedTransactions: () => {return []}, publishTransaction: () => {}, }) }) + describe('_checkPendingTx state management', function () { + let stub + + afterEach(function () { + if (stub) { + stub.restore() + } + }) + + it('should become failed if another tx with the same nonce succeeds', async function () { + + // SETUP + const txGen = new MockTxGen() + + txGen.generate({ + id: '456', + value: '0x01', + hash: '0xbad', + status: 'confirmed', + nonce: '0x01', + }, { count: 1 }) + + const pending = txGen.generate({ + id: '123', + value: '0x02', + hash: '0xfad', + status: 'submitted', + nonce: '0x01', + }, { count: 1 })[0] + + stub = sinon.stub(pendingTxTracker, 'getCompletedTransactions') + .returns(txGen.txs) + + // THE EXPECTATION + const spy = sinon.spy() + pendingTxTracker.on('tx:failed', (txId, err) => { + assert.equal(txId, pending.id, 'should fail the pending tx') + assert.equal(err.name, 'NonceTakenErr', 'should emit a nonce taken error.') + spy(txId, err) + }) + + // THE METHOD + await pendingTxTracker._checkPendingTx(pending) + + // THE ASSERTION + assert.ok(spy.calledWith(pending.id), 'tx failed should be emitted') + }) + }) + describe('#checkForTxInBlock', function () { it('should return if no pending transactions', function () { // throw a type error if it trys to do anything on the block @@ -239,4 +291,4 @@ describe('PendingTransactionTracker', function () { }) }) }) -})
\ No newline at end of file +}) |