aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/pending-tx-test.js
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2017-10-19 14:04:54 +0800
committerGitHub <noreply@github.com>2017-10-19 14:04:54 +0800
commit776e8241f0464939cc3049f7155c150e3375c623 (patch)
tree017600778515e74eaf15bf4f889e5b26638c56d7 /test/unit/pending-tx-test.js
parentde1da7d1b215ade650fc644adf63384a401dc240 (diff)
parenta8bba2f4b7ca714d46b2e1ca405aec3135aa23b2 (diff)
downloadtangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar
tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar.gz
tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar.bz2
tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar.lz
tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar.xz
tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar.zst
tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.zip
Merge pull request #2402 from chikeichan/merge
[NewUI] Merge master into NewUI-flat
Diffstat (limited to 'test/unit/pending-tx-test.js')
-rw-r--r--test/unit/pending-tx-test.js54
1 files changed, 53 insertions, 1 deletions
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
+})