From a32d71e8ed4c91c8ad73f4a7afc52e506ccf5247 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 6 Oct 2017 12:29:27 -0700 Subject: Add failing test for issue #2294 --- test/unit/pending-tx-test.js | 53 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 6b62bb5b1..554bd5591 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 @@ -50,6 +52,55 @@ describe('PendingTransactionTracker', function () { }) }) + 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, 'getPendingTransactions') + .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 + return sinon.assert.calledWith(spy, 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 +290,4 @@ describe('PendingTransactionTracker', function () { }) }) }) -}) \ No newline at end of file +}) -- cgit From 94513cae7bf3c8310ae6a248e12a9b7dd73e306f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 6 Oct 2017 12:50:33 -0700 Subject: Provide method for tx tracker to refer to all txs --- test/unit/pending-tx-test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/unit') diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 554bd5591..32421a44f 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -48,6 +48,7 @@ describe('PendingTransactionTracker', function () { } }, getPendingTransactions: () => {return []}, + getCompletedTransactions: () => {return []}, publishTransaction: () => {}, }) }) @@ -82,7 +83,7 @@ describe('PendingTransactionTracker', function () { nonce: '0x01', }, { count: 1 })[0] - stub = sinon.stub(pendingTxTracker, 'getPendingTransactions') + stub = sinon.stub(pendingTxTracker, 'getCompletedTransactions') .returns(txGen.txs) // THE EXPECTATION @@ -97,7 +98,7 @@ describe('PendingTransactionTracker', function () { await pendingTxTracker._checkPendingTx(pending) // THE ASSERTION - return sinon.assert.calledWith(spy, pending.id, 'tx failed should be emitted') + assert.ok(spy.calledWith(pending.id), 'tx failed should be emitted') }) }) -- cgit From 3b3120c5f83d0971747abc28e9a3ddfc3da34be3 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 6 Oct 2017 13:16:44 -0700 Subject: nodeify - fix test --- test/unit/nodeify-test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/unit') 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')) } }) }) -- cgit From 6f0c0e83744514c7fe70838097d96b5e3c2778ae Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Mon, 9 Oct 2017 12:12:54 -0700 Subject: Add test to look for wei precision. --- test/unit/components/bn-as-decimal-input-test.js | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/unit') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 106b3a871..d74e0fa2e 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -48,4 +48,40 @@ describe('BnInput', function () { checkValidity () { return true } }, }) }) + + it('can tolerate wei precision', function (done) { + const renderer = ReactTestUtils.createRenderer() + + let valueStr = '1000000000000000000' + + const value = new BN(valueStr, 10) + + const inputStr = '1000000000.000000001' + + let targetStr = '1000000000000000001' + + const target = new BN(targetStr, 10) + + const precision = 9 // ether precision + const scale = 9 + + const props = { + value, + scale, + precision, + onChange: (newBn) => { + assert.equal(newBn.toString(), target.toString(), '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 } }, + }) + }) }) -- cgit From c12d56063da5ed533ba63cf6e0843631659de0d3 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Mon, 9 Oct 2017 13:01:58 -0700 Subject: Fix to actually fail in earlier versions. --- test/unit/components/bn-as-decimal-input-test.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test/unit') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index d74e0fa2e..81a8caa45 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -48,21 +48,21 @@ describe('BnInput', function () { checkValidity () { return true } }, }) }) - + it('can tolerate wei precision', function (done) { const renderer = ReactTestUtils.createRenderer() - let valueStr = '1000000000000000000' + let valueStr = '1000000000' const value = new BN(valueStr, 10) + const inputStr = '1.000000001' - const inputStr = '1000000000.000000001' - let targetStr = '1000000000000000001' + let targetStr = '1000000001' const target = new BN(targetStr, 10) - const precision = 9 // ether precision + const precision = 9 // gwei precision const scale = 9 const props = { @@ -71,6 +71,8 @@ describe('BnInput', function () { 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(), target.toString(), 'should tolerate increase') done() }, } -- cgit From d82d9215fbe593293a6badc523218878cfb13dd2 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Mon, 9 Oct 2017 13:02:52 -0700 Subject: Make modification --- test/unit/components/bn-as-decimal-input-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js index 81a8caa45..58ecc9c89 100644 --- a/test/unit/components/bn-as-decimal-input-test.js +++ b/test/unit/components/bn-as-decimal-input-test.js @@ -72,7 +72,7 @@ describe('BnInput', function () { onChange: (newBn) => { assert.equal(newBn.toString(), target.toString(), 'should tolerate increase') const reInput = BnInput.prototype.downsize(newBn.toString(), 9, 9) - assert.equal(reInput.toString(), target.toString(), 'should tolerate increase') + assert.equal(reInput.toString(), inputStr, 'should tolerate increase') done() }, } -- cgit