Add tests for exponential backoff code in _resubmitTx

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

@ -273,24 +273,70 @@ describe('PendingTransactionTracker', function () {
}) })
}) })
describe('#_resubmitTx', function () { describe('#_resubmitTx', function () {
it('should publishing the transaction', function (done) { const mockFirstRetryBlockNumber = '0x1'
const enoughBalance = '0x100000' let txMetaToTestExponentialBackoff
pendingTxTracker.getBalance = (address) => {
assert.equal(address, txMeta.txParams.from, 'Should pass the address') beforeEach(() => {
return enoughBalance pendingTxTracker.getBalance = (address) => {
} assert.equal(address, txMeta.txParams.from, 'Should pass the address')
pendingTxTracker.publishTransaction = async (rawTx) => { return enoughBalance
assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx') }
} 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: afterEach(() => {
// Adding the fake tx: pendingTxTracker.publishTransaction.reset()
pendingTxTracker._resubmitTx(txMeta) })
.then(() => done())
.catch((err) => { it('should publish the transaction', function (done) {
assert.ifError(err, 'should not throw an error') const enoughBalance = '0x100000'
done(err)
// 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')
}) })
})
}) })
}) })

Loading…
Cancel
Save