1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Add tests for exponential backoff code in _resubmitTx

This commit is contained in:
Dan 2017-12-06 14:11:14 -03:30
parent af8fcb6777
commit 3356c15d04

View File

@ -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')
return enoughBalance
}
pendingTxTracker.publishTransaction = async (rawTx) => {
assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx')
}
// Stubbing out current account state: beforeEach(() => {
// Adding the fake tx: pendingTxTracker.getBalance = (address) => {
pendingTxTracker._resubmitTx(txMeta) assert.equal(address, txMeta.txParams.from, 'Should pass the address')
.then(() => done()) return enoughBalance
.catch((err) => { }
assert.ifError(err, 'should not throw an error') pendingTxTracker.publishTransaction = async (rawTx) => {
done(err) 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:
// 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')
}) })
})
}) })
}) })