aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-10-07 03:29:27 +0800
committerDan Finlay <dan@danfinlay.com>2017-10-07 03:29:27 +0800
commita32d71e8ed4c91c8ad73f4a7afc52e506ccf5247 (patch)
treeac5ead5310dc26a1e0d9b3df8ffdf02227ca1ee3
parent53da368d2370edbb78eca063ff701c0492abbff6 (diff)
downloadtangerine-wallet-browser-a32d71e8ed4c91c8ad73f4a7afc52e506ccf5247.tar.gz
tangerine-wallet-browser-a32d71e8ed4c91c8ad73f4a7afc52e506ccf5247.tar.zst
tangerine-wallet-browser-a32d71e8ed4c91c8ad73f4a7afc52e506ccf5247.zip
Add failing test for issue #2294
-rw-r--r--test/unit/pending-tx-test.js53
1 files changed, 52 insertions, 1 deletions
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
+})