aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-12-07 01:41:14 +0800
committerDan <danjm.com@gmail.com>2017-12-07 01:41:14 +0800
commit3356c15d04d947c92a2c19690384396651c352e5 (patch)
tree3e88cfb9aa60a50ad3c2ca6efbc2b4d68104c287 /test
parentaf8fcb67778fadd7056c0930eeb9d22eb28b0e69 (diff)
downloadtangerine-wallet-browser-3356c15d04d947c92a2c19690384396651c352e5.tar
tangerine-wallet-browser-3356c15d04d947c92a2c19690384396651c352e5.tar.gz
tangerine-wallet-browser-3356c15d04d947c92a2c19690384396651c352e5.tar.bz2
tangerine-wallet-browser-3356c15d04d947c92a2c19690384396651c352e5.tar.lz
tangerine-wallet-browser-3356c15d04d947c92a2c19690384396651c352e5.tar.xz
tangerine-wallet-browser-3356c15d04d947c92a2c19690384396651c352e5.tar.zst
tangerine-wallet-browser-3356c15d04d947c92a2c19690384396651c352e5.zip
Add tests for exponential backoff code in _resubmitTx
Diffstat (limited to 'test')
-rw-r--r--test/unit/pending-tx-test.js80
1 files changed, 63 insertions, 17 deletions
diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js
index 7069554f7..393601a57 100644
--- a/test/unit/pending-tx-test.js
+++ b/test/unit/pending-tx-test.js
@@ -273,24 +273,70 @@ describe('PendingTransactionTracker', function () {
})
})
describe('#_resubmitTx', function () {
- it('should publishing the transaction', function (done) {
- const enoughBalance = '0x100000'
- pendingTxTracker.getBalance = (address) => {
- assert.equal(address, txMeta.txParams.from, 'Should pass the address')
- return enoughBalance
- }
- pendingTxTracker.publishTransaction = async (rawTx) => {
- assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx')
- }
+ const mockFirstRetryBlockNumber = '0x1'
+ let txMetaToTestExponentialBackoff
+
+ beforeEach(() => {
+ pendingTxTracker.getBalance = (address) => {
+ assert.equal(address, txMeta.txParams.from, 'Should pass the address')
+ return enoughBalance
+ }
+ pendingTxTracker.publishTransaction = async (rawTx) => {
+ assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx')
+ }
+ sinon.spy(pendingTxTracker, 'publishTransaction')
+
+ txMetaToTestExponentialBackoff = Object.assign({}, txMeta, {
+ retryCount: 4,
+ firstRetryBlockNumber: mockFirstRetryBlockNumber,
+ })
+ })
- // Stubbing out current account state:
- // Adding the fake tx:
- pendingTxTracker._resubmitTx(txMeta)
- .then(() => done())
- .catch((err) => {
- assert.ifError(err, 'should not throw an error')
- done(err)
+ afterEach(() => {
+ pendingTxTracker.publishTransaction.reset()
+ })
+
+ it('should publish the transaction', function (done) {
+ const enoughBalance = '0x100000'
+
+ // Stubbing out current account state:
+ // Adding the fake tx:
+ pendingTxTracker._resubmitTx(txMeta)
+ .then(() => done())
+ .catch((err) => {
+ assert.ifError(err, 'should not throw an error')
+ done(err)
+ })
+
+ assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction')
+ })
+
+ it('should not publish the transaction if the limit of retries has been exceeded', function (done) {
+ const enoughBalance = '0x100000'
+ const mockLatestBlockNumber = '0x5'
+
+ pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
+ .then(() => done())
+ .catch((err) => {
+ assert.ifError(err, 'should not throw an error')
+ done(err)
+ })
+
+ assert.equal(pendingTxTracker.publishTransaction.callCount, 0, 'Should NOT call publish transaction')
+ })
+
+ it('should publish the transaction if the number of blocks since last retry exceeds the last set limit', function (done) {
+ const enoughBalance = '0x100000'
+ const mockLatestBlockNumber = '0x11'
+
+ pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
+ .then(() => done())
+ .catch((err) => {
+ assert.ifError(err, 'should not throw an error')
+ done(err)
+ })
+
+ assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction')
})
- })
})
})