aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-07-06 14:23:57 +0800
committerDan Finlay <dan@danfinlay.com>2017-07-06 14:24:33 +0800
commit07d4e4fe6f31d99a9f15c3862671c5c07831ff2a (patch)
treeb358084dd6a442b86a79c7740d16a53679292687
parent96df7ad8d36b68e521e670d28e3efda38e41972f (diff)
downloadtangerine-wallet-browser-07d4e4fe6f31d99a9f15c3862671c5c07831ff2a.tar.gz
tangerine-wallet-browser-07d4e4fe6f31d99a9f15c3862671c5c07831ff2a.tar.zst
tangerine-wallet-browser-07d4e4fe6f31d99a9f15c3862671c5c07831ff2a.zip
Fix failing test
-rw-r--r--app/scripts/controllers/transactions.js18
-rw-r--r--test/unit/tx-controller-test.js56
2 files changed, 35 insertions, 39 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 3f5834756..7946d10d1 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -430,24 +430,18 @@ module.exports = class TransactionController extends EventEmitter {
// if the value of the transaction is greater then the balance, fail.
if (gtBalance) {
- txMeta.err = {
- isWarning: true,
- message: 'Insufficient balance.',
- }
- this.updateTx(txMeta)
+ const message = 'Insufficient balance.'
+ this.setTxStatusFailed(txMeta.id, message)
cb()
- return log.error(txMeta.err.message)
+ return log.error(message)
}
// if the nonce of the transaction is lower then the accounts nonce, fail.
if (txNonce < nonce) {
- txMeta.err = {
- isWarning: true,
- message: 'Invalid nonce.',
- }
- this.updateTx(txMeta)
+ const message = 'Invalid nonce.'
+ this.setTxStatusFailed(txMeta.id, message)
cb()
- return log.error(txMeta.err.message)
+ return log.error(message)
}
// Only auto-submit already-signed txs:
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index 7b0ad66bd..01a498820 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -19,6 +19,7 @@ describe('Transaction Controller', function () {
txController = new TransactionController({
networkStore: new ObservableStore(currentNetworkId),
txHistoryLimit: 10,
+ ethStore: { getState: noop },
provider: { _blockTracker: new EventEmitter()},
blockTracker: new EventEmitter(),
ethQuery: new EthQuery(new EventEmitter()),
@@ -324,37 +325,38 @@ describe('Transaction Controller', function () {
})
describe('#_resubmitTx with a too-low balance', function () {
- const from = '0xda0da0'
- const txMeta = {
- id: 1,
- status: 'submitted',
- txParams: {
- from,
- nonce: '0x1'
- },
- }
-
- const lowBalance = '0x0'
- const fakeStoreState = {}
- fakeStoreState[from] = {
- balance: lowBalance,
- nonce: '0x0',
- }
-
- // Stubbing out current account state:
- txController.ethStore = { getState: noop }
- const getStateStub = sinon.stub(txController.ethStore, 'getState')
- .returns(fakeStoreState)
-
- // Adding the fake tx:
- txController.addTx(txMeta, noop)
-
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('should not throw an error')
+ assert.ifError(err, 'should not throw an error')
const updatedMeta = txController.getTx(txMeta.id)
assert.notEqual(updatedMeta.status, txMeta.status, 'status changed.')
- assert.notEqual(updatedMeta.status, 'failed', 'tx set to failed.')
+ assert.equal(updatedMeta.status, 'failed', 'tx set to failed.')
done()
})
})