Add tests for exponential backoff code in _resubmitTx

feature/default_network_editable
Dan 7 years ago
parent af8fcb6777
commit 3356c15d04
  1. 50
      test/unit/pending-tx-test.js

@ -273,8 +273,10 @@ describe('PendingTransactionTracker', function () {
}) })
}) })
describe('#_resubmitTx', function () { describe('#_resubmitTx', function () {
it('should publishing the transaction', function (done) { const mockFirstRetryBlockNumber = '0x1'
const enoughBalance = '0x100000' let txMetaToTestExponentialBackoff
beforeEach(() => {
pendingTxTracker.getBalance = (address) => { pendingTxTracker.getBalance = (address) => {
assert.equal(address, txMeta.txParams.from, 'Should pass the address') assert.equal(address, txMeta.txParams.from, 'Should pass the address')
return enoughBalance return enoughBalance
@ -282,6 +284,20 @@ describe('PendingTransactionTracker', function () {
pendingTxTracker.publishTransaction = async (rawTx) => { pendingTxTracker.publishTransaction = async (rawTx) => {
assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx') assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx')
} }
sinon.spy(pendingTxTracker, 'publishTransaction')
txMetaToTestExponentialBackoff = Object.assign({}, txMeta, {
retryCount: 4,
firstRetryBlockNumber: mockFirstRetryBlockNumber,
})
})
afterEach(() => {
pendingTxTracker.publishTransaction.reset()
})
it('should publish the transaction', function (done) {
const enoughBalance = '0x100000'
// Stubbing out current account state: // Stubbing out current account state:
// Adding the fake tx: // Adding the fake tx:
@ -291,6 +307,36 @@ describe('PendingTransactionTracker', function () {
assert.ifError(err, 'should not throw an error') assert.ifError(err, 'should not throw an error')
done(err) 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')
}) })
}) })
}) })

Loading…
Cancel
Save