From a915dfdeaa51c80c599b15f4e1ec14c90ac00fbf Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 5 Jul 2017 22:36:52 -0700 Subject: Add failing test for retrying an over-spending tx --- test/unit/tx-controller-test.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test') diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 0d35cd62c..b5df7f970 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -322,4 +322,41 @@ 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: + const getStateStub = sinon.stub(txController.ethStore, 'getState') + .returns(fakeStoreState) + + // Adding the fake tx: + txController.addTx(txMeta, noop) + + it('should fail the transaction', function (done) { + txController._resubmitTx(txMeta, function (err) { + assert.ifError('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.') + }) + }) + }) + }) + -- cgit From ef1282b55648ad5e787b170cc06e5f8b292f5983 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 5 Jul 2017 22:48:11 -0700 Subject: Typo fix --- test/unit/tx-controller-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index b5df7f970..074e6c954 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -327,7 +327,7 @@ describe('Transaction Controller', function () { const from = '0xda0da0' const txMeta = { id: 1, - status: 'submitted' + status: 'submitted', txParams: { from, nonce: '0x1' -- cgit From 96df7ad8d36b68e521e670d28e3efda38e41972f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 5 Jul 2017 23:04:51 -0700 Subject: Add missing done --- test/unit/tx-controller-test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 074e6c954..7b0ad66bd 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -342,6 +342,7 @@ describe('Transaction Controller', function () { } // Stubbing out current account state: + txController.ethStore = { getState: noop } const getStateStub = sinon.stub(txController.ethStore, 'getState') .returns(fakeStoreState) @@ -354,9 +355,9 @@ describe('Transaction Controller', function () { const updatedMeta = txController.getTx(txMeta.id) assert.notEqual(updatedMeta.status, txMeta.status, 'status changed.') assert.notEqual(updatedMeta.status, 'failed', 'tx set to failed.') + done() }) }) }) - }) -- cgit From 07d4e4fe6f31d99a9f15c3862671c5c07831ff2a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 5 Jul 2017 23:23:57 -0700 Subject: Fix failing test --- test/unit/tx-controller-test.js | 56 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'test') 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() }) }) -- cgit From ab8bae421e6b172f811694a597536c7d222043cd Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 7 Jul 2017 14:26:52 -0700 Subject: test - tx-controller - stub block-tracker method --- test/unit/tx-controller-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index c9eff5d01..9dfe0b982 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -18,7 +18,7 @@ describe('Transaction Controller', function () { txController = new TransactionController({ networkStore: new ObservableStore(currentNetworkId), txHistoryLimit: 10, - blockTracker: { getCurrentBlock: noop, on: noop }, + blockTracker: { getCurrentBlock: noop, on: noop, once: noop }, provider: { sendAsync: noop }, ethQuery: new EthQuery({ sendAsync: noop }), ethStore: { getState: noop }, -- cgit From f5de16c91174fbbf208e5aef8f542d3bbbb3cb93 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 7 Jul 2017 14:32:03 -0700 Subject: test - tx controller - fix promise handling --- test/unit/tx-controller-test.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 9dfe0b982..a5af13915 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -270,7 +270,7 @@ describe('Transaction Controller', function () { }) - it('does not overwrite set values', function (done) { + it('does not overwrite set values', function () { this.timeout(15000) const wrongValue = '0x05' @@ -289,9 +289,7 @@ describe('Transaction Controller', function () { const pubStub = sinon.stub(txController.txProviderUtils, 'publishTransaction') .callsArgWithAsync(1, null, originalValue) - txController.approveTransaction(txMeta.id).then((err) => { - assert.ifError(err, 'should not error') - + return txController.approveTransaction(txMeta.id).then(() => { const result = txController.getTx(txMeta.id) const params = result.txParams @@ -303,7 +301,6 @@ describe('Transaction Controller', function () { priceStub.restore() signStub.restore() pubStub.restore() - done() }) }) }) -- cgit