mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1747 from MetaMask/FailingTestForFailingLowBalanceTx
Fail txs on retry if balance is insufficient
This commit is contained in:
commit
33c2b864db
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- Re-enable default token list.
|
- Re-enable default token list.
|
||||||
- Add origin header to dapp-bound requests to allow providers to throttle sites.
|
- Add origin header to dapp-bound requests to allow providers to throttle sites.
|
||||||
|
- Fix bug that could sometimes resubmit a transaction that had been stalled due to low balance after balance was restored.
|
||||||
|
|
||||||
## 3.8.2 2017-7-3
|
## 3.8.2 2017-7-3
|
||||||
|
|
||||||
|
@ -428,10 +428,22 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
const gtBalance = Number.parseInt(txMeta.txParams.value) > Number.parseInt(balance)
|
const gtBalance = Number.parseInt(txMeta.txParams.value) > Number.parseInt(balance)
|
||||||
if (!('retryCount' in txMeta)) txMeta.retryCount = 0
|
if (!('retryCount' in txMeta)) txMeta.retryCount = 0
|
||||||
|
|
||||||
// if the value of the transaction is greater then the balance
|
// if the value of the transaction is greater then the balance, fail.
|
||||||
// or the nonce of the transaction is lower then the accounts nonce
|
if (gtBalance) {
|
||||||
// dont resubmit the tx
|
const message = 'Insufficient balance.'
|
||||||
if (gtBalance || txNonce < nonce) return cb()
|
this.setTxStatusFailed(txMeta.id, message)
|
||||||
|
cb()
|
||||||
|
return log.error(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the nonce of the transaction is lower then the accounts nonce, fail.
|
||||||
|
if (txNonce < nonce) {
|
||||||
|
const message = 'Invalid nonce.'
|
||||||
|
this.setTxStatusFailed(txMeta.id, message)
|
||||||
|
cb()
|
||||||
|
return log.error(message)
|
||||||
|
}
|
||||||
|
|
||||||
// Only auto-submit already-signed txs:
|
// Only auto-submit already-signed txs:
|
||||||
if (!('rawTx' in txMeta)) return cb()
|
if (!('rawTx' in txMeta)) return cb()
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ describe('Transaction Controller', function () {
|
|||||||
txController = new TransactionController({
|
txController = new TransactionController({
|
||||||
networkStore: new ObservableStore(currentNetworkId),
|
networkStore: new ObservableStore(currentNetworkId),
|
||||||
txHistoryLimit: 10,
|
txHistoryLimit: 10,
|
||||||
|
ethStore: { getState: noop },
|
||||||
provider: { _blockTracker: new EventEmitter()},
|
provider: { _blockTracker: new EventEmitter()},
|
||||||
blockTracker: new EventEmitter(),
|
blockTracker: new EventEmitter(),
|
||||||
ethQuery: new EthQuery(new EventEmitter()),
|
ethQuery: new EthQuery(new EventEmitter()),
|
||||||
@ -322,4 +323,43 @@ describe('Transaction Controller', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('#_resubmitTx with a too-low balance', function () {
|
||||||
|
it('should fail the transaction', function (done) {
|
||||||
|
const from = '0xda0da0'
|
||||||
|
const txMeta = {
|
||||||
|
id: 1,
|
||||||
|
status: 'submitted',
|
||||||
|
metamaskNetworkId: currentNetworkId,
|
||||||
|
txParams: {
|
||||||
|
from,
|
||||||
|
nonce: '0x1',
|
||||||
|
value: '0xfffff',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const lowBalance = '0x0'
|
||||||
|
const fakeStoreState = { accounts: {} }
|
||||||
|
fakeStoreState.accounts[from] = {
|
||||||
|
balance: lowBalance,
|
||||||
|
nonce: '0x0',
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stubbing out current account state:
|
||||||
|
const getStateStub = sinon.stub(txController.ethStore, 'getState')
|
||||||
|
.returns(fakeStoreState)
|
||||||
|
|
||||||
|
// Adding the fake tx:
|
||||||
|
txController.addTx(clone(txMeta))
|
||||||
|
|
||||||
|
txController._resubmitTx(txMeta, function (err) {
|
||||||
|
assert.ifError(err, 'should not throw an error')
|
||||||
|
const updatedMeta = txController.getTx(txMeta.id)
|
||||||
|
assert.notEqual(updatedMeta.status, txMeta.status, 'status changed.')
|
||||||
|
assert.equal(updatedMeta.status, 'failed', 'tx set to failed.')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user