From ac80eaca1fc9923cd5696282ba2bc6bace22ff83 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Fri, 29 Sep 2017 12:54:05 -0700 Subject: pending-tx - dont check the balance to rebrodcast --- test/unit/pending-tx-test.js | 27 +-------------------------- test/unit/tx-controller-test.js | 25 ------------------------- 2 files changed, 1 insertion(+), 51 deletions(-) (limited to 'test') diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 1af464656..4da0eff5d 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -40,14 +40,12 @@ describe('PendingTransactionTracker', function () { pendingTxTracker = new PendingTransactionTracker({ provider, - getBalance: () => {}, nonceTracker: { getGlobalLock: async () => { return { releaseLock: () => {} } } }, getPendingTransactions: () => {return []}, - sufficientBalance: () => {}, publishTransaction: () => {}, }) }) @@ -213,30 +211,7 @@ describe('PendingTransactionTracker', function () { pendingTxTracker.resubmitPendingTxs() }) }) - describe('#_resubmitTx with a too-low balance', function () { - it('should return before publishing the transaction because to low of balance', function (done) { - const lowBalance = '0x0' - pendingTxTracker.getBalance = (address) => { - assert.equal(address, txMeta.txParams.from, 'Should pass the address') - return lowBalance - } - pendingTxTracker.publishTransaction = async (rawTx) => { - done(new Error('tried to publish transaction')) - } - - // Stubbing out current account state: - // Adding the fake tx: - pendingTxTracker.once('tx:failed', (txId, err) => { - assert(err, 'Should have a error') - done() - }) - pendingTxTracker._resubmitTx(txMeta) - .catch((err) => { - assert.ifError(err, 'should not throw an error') - done(err) - }) - }) - + describe('#_resubmitTx', function () { it('should publishing the transaction', function (done) { const enoughBalance = '0x100000' pendingTxTracker.getBalance = (address) => { diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 66772ff88..bb51ab01f 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -25,7 +25,6 @@ describe('Transaction Controller', function () { networkStore: new ObservableStore(currentNetworkId), txHistoryLimit: 10, blockTracker: { getCurrentBlock: noop, on: noop, once: noop }, - accountTracker: { store: { getState: noop } }, signTransaction: (ethTx) => new Promise((resolve) => { ethTx.sign(privKey) resolve() @@ -383,30 +382,6 @@ describe('Transaction Controller', function () { }) }) - describe('#getBalance', function () { - it('gets balance', function () { - sinon.stub(txController.accountTracker.store, 'getState').callsFake(() => { - return { - accounts: { - '0x1678a085c290ebd122dc42cba69373b5953b831d': { - address: '0x1678a085c290ebd122dc42cba69373b5953b831d', - balance: '0x00000000000000056bc75e2d63100000', - code: '0x', - nonce: '0x0', - }, - '0xc684832530fcbddae4b4230a47e991ddcec2831d': { - address: '0xc684832530fcbddae4b4230a47e991ddcec2831d', - balance: '0x0', - code: '0x', - nonce: '0x0', - }, - }, - } - }) - assert.equal(txController.pendingTxTracker.getBalance('0x1678a085c290ebd122dc42cba69373b5953b831d'), '0x00000000000000056bc75e2d63100000') - assert.equal(txController.pendingTxTracker.getBalance('0xc684832530fcbddae4b4230a47e991ddcec2831d'), '0x0') - }) - }) describe('#getPendingTransactions', function () { beforeEach(function () { -- cgit From d29b5f10ef5137ab56ecc9615e5e894082db9803 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 13:14:42 -0700 Subject: tx state history - fix bug where initial snapshot was mutated on updateTx --- test/unit/tx-state-history-helper.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js index 5bb6c9bee..e5075af88 100644 --- a/test/unit/tx-state-history-helper.js +++ b/test/unit/tx-state-history-helper.js @@ -20,4 +20,26 @@ describe('tx-state-history-helper', function () { }) }) }) + + it('replaying history does not mutate the original obj', function () { + const initialState = { test: true, message: 'hello', value: 1 } + const diff1 = { + "op": "replace", + "path": "/message", + "value": "haay", + } + const diff2 = { + "op": "replace", + "path": "/value", + "value": 2, + } + const history = [initialState, diff1, diff2] + + const beforeStateSnapshot = JSON.stringify(initialState) + const latestState = txStateHistoryHelper.replayHistory(history) + const afterStateSnapshot = JSON.stringify(initialState) + + assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state') + assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run') + }) }) -- cgit From c9c0e6f674c06d30794c73994c7776eb68ebedc0 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 13:43:26 -0700 Subject: tx state history - test - fix format of history entries --- test/unit/tx-state-history-helper.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js index 5bb6c9bee..1590f83d0 100644 --- a/test/unit/tx-state-history-helper.js +++ b/test/unit/tx-state-history-helper.js @@ -20,4 +20,30 @@ describe('tx-state-history-helper', function () { }) }) }) +<<<<<<< Updated upstream +======= + + it('replaying history does not mutate the original obj', function () { + const initialState = { test: true, message: 'hello', value: 1 } + const diff1 = [{ + "op": "replace", + "path": "/message", + "value": "haay", + }] + const diff2 = [{ + "op": "replace", + "path": "/value", + "value": 2, + }] + const history = [initialState, diff1, diff2] + + const beforeStateSnapshot = JSON.stringify(initialState) + const latestState = txStateHistoryHelper.replayHistory(history) + const afterStateSnapshot = JSON.stringify(initialState) + + assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state') + assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run') + }) + +>>>>>>> Stashed changes }) -- cgit From a86f6d6d90bda273861079b464c290dff6ef5c0e Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 15:14:15 -0700 Subject: pending tx tracker - test - rename tests to match event name --- test/unit/pending-tx-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 4da0eff5d..097564033 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -57,7 +57,7 @@ describe('PendingTransactionTracker', function () { const block = Proxy.revocable({}, {}).revoke() pendingTxTracker.checkForTxInBlock(block) }) - it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) { + it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) { const block = Proxy.revocable({}, {}).revoke() pendingTxTracker.getPendingTransactions = () => [txMetaNoHash] pendingTxTracker.once('tx:failed', (txId, err) => { @@ -105,7 +105,7 @@ describe('PendingTransactionTracker', function () { }) describe('#_checkPendingTx', function () { - it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) { + it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) { pendingTxTracker.once('tx:failed', (txId, err) => { assert(txId, txMetaNoHash.id, 'should pass txId') done() @@ -172,7 +172,7 @@ describe('PendingTransactionTracker', function () { .catch(done) pendingTxTracker.resubmitPendingTxs() }) - it('should not emit \'txFailed\' if the txMeta throws a known txError', function (done) { + it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) { knownErrors =[ // geth ' Replacement transaction Underpriced ', @@ -199,7 +199,7 @@ describe('PendingTransactionTracker', function () { pendingTxTracker.resubmitPendingTxs() }) - it('should emit \'txFailed\' if it encountered a real error', function (done) { + it('should emit \'tx:failed\' if it encountered a real error', function (done) { pendingTxTracker.once('tx:failed', (id, err) => err.message === 'im some real error' ? txList[id - 1].resolve() : done(err)) pendingTxTracker.getPendingTransactions = () => txList -- cgit From 25a80932a64f718ba1a39ab399b17395f0fd5d88 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 15:20:18 -0700 Subject: pending tx tracker - test - expect warning event on resubmit failure --- test/unit/pending-tx-test.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 097564033..6b62bb5b1 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -199,8 +199,15 @@ describe('PendingTransactionTracker', function () { pendingTxTracker.resubmitPendingTxs() }) - it('should emit \'tx:failed\' if it encountered a real error', function (done) { - pendingTxTracker.once('tx:failed', (id, err) => err.message === 'im some real error' ? txList[id - 1].resolve() : done(err)) + it('should emit \'tx:warning\' if it encountered a real error', function (done) { + pendingTxTracker.once('tx:warning', (txMeta, err) => { + if (err.message === 'im some real error') { + const matchingTx = txList.find(tx => tx.id === txMeta.id) + matchingTx.resolve() + } else { + done(err) + } + }) pendingTxTracker.getPendingTransactions = () => txList pendingTxTracker._resubmitTx = async (tx) => { throw new TypeError('im some real error') } -- cgit