From fa8c74fe9b19229580224815cc131611ee29027c Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 21 Jun 2017 17:28:19 -0700 Subject: add a test for #getNonceLock --- test/unit/nonce-tracker-test.js | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/unit/nonce-tracker-test.js (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js new file mode 100644 index 000000000..5a05d6170 --- /dev/null +++ b/test/unit/nonce-tracker-test.js @@ -0,0 +1,46 @@ +const assert = require('assert') +const NonceTracker = require('../../app/scripts/lib/nonce-tracker') + +describe('Nonce Tracker', function () { + let nonceTracker, provider, getPendingTransactions, pendingTxs + const noop = () => {} + + + beforeEach(function () { + pendingTxs =[{ + 'status': 'submitted', + 'txParams': { + 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', + 'gas': '0x30d40', + 'value': '0x0', + 'nonce': '0x1', + }, + }] + + + getPendingTransactions = () => pendingTxs + provider = { sendAsync: (_, cb) => { cb(undefined , {result: '0x0'}) }, } + nonceTracker = new NonceTracker({ + blockTracker: { + getCurrentBlock: () => '0x11b568', + once: (...args) => { + setTimeout(() => { + args.pop()() + }, 5000) + } + }, + provider, + getPendingTransactions, + }) + }) + + describe('#getNonceLock', function () { + it('should work', async function (done) { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') + nonceLock.releaseLock() + done() + }) + }) +}) -- cgit From 92df9965ebd4a833817c32fd32f7e4533ec7fe19 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 21 Jun 2017 19:51:00 -0700 Subject: fix nonceTracker --- test/unit/nonce-tracker-test.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 5a05d6170..16cd6d008 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -3,31 +3,25 @@ const NonceTracker = require('../../app/scripts/lib/nonce-tracker') describe('Nonce Tracker', function () { let nonceTracker, provider, getPendingTransactions, pendingTxs - const noop = () => {} beforeEach(function () { - pendingTxs =[{ + pendingTxs = [{ 'status': 'submitted', 'txParams': { 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', 'gas': '0x30d40', 'value': '0x0', - 'nonce': '0x1', + 'nonce': '0x0', }, }] getPendingTransactions = () => pendingTxs - provider = { sendAsync: (_, cb) => { cb(undefined , {result: '0x0'}) }, } + provider = { sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) } } nonceTracker = new NonceTracker({ blockTracker: { - getCurrentBlock: () => '0x11b568', - once: (...args) => { - setTimeout(() => { - args.pop()() - }, 5000) - } + getCurrentBlock: () => '0x11b568', }, provider, getPendingTransactions, @@ -38,8 +32,8 @@ describe('Nonce Tracker', function () { it('should work', async function (done) { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') - nonceLock.releaseLock() + assert.equal(nonceLock.nextNonce, '1', 'nonce should be 1') + await nonceLock.releaseLock() done() }) }) -- cgit From da16f396266daa5ab0acc8f0c04d3e25b98c39f0 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 3 Aug 2017 15:05:32 -0700 Subject: Merge branch 'master' of github.com:MetaMask/metamask-extension into greenkeeper/initial --- test/unit/nonce-tracker-test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 16cd6d008..b0283e159 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -18,11 +18,13 @@ describe('Nonce Tracker', function () { getPendingTransactions = () => pendingTxs - provider = { sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) } } - nonceTracker = new NonceTracker({ - blockTracker: { + provider = { + sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) }, + _blockTracker: { getCurrentBlock: () => '0x11b568', }, + } + nonceTracker = new NonceTracker({ provider, getPendingTransactions, }) -- cgit From e223b0c7898ad49bd3df044ff72386869b0702be Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 3 Aug 2017 16:34:38 -0700 Subject: test - dont mix callback and promise --- test/unit/nonce-tracker-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index b0283e159..36025a360 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -31,12 +31,11 @@ describe('Nonce Tracker', function () { }) describe('#getNonceLock', function () { - it('should work', async function (done) { + it('should work', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') assert.equal(nonceLock.nextNonce, '1', 'nonce should be 1') await nonceLock.releaseLock() - done() }) }) }) -- cgit From bf8a62eb39aac454c1f23e549078ce5f4b8a2d2a Mon Sep 17 00:00:00 2001 From: frankiebee Date: Fri, 18 Aug 2017 13:53:18 -0700 Subject: add test for using localNonce --- test/unit/nonce-tracker-test.js | 46 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 36025a360..2171d859d 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -2,24 +2,53 @@ const assert = require('assert') const NonceTracker = require('../../app/scripts/lib/nonce-tracker') describe('Nonce Tracker', function () { - let nonceTracker, provider, getPendingTransactions, pendingTxs - + let nonceTracker, provider + let getPendingTransactions, pendingTxs + let getConfirmedTransactions, confirmedTxs + let providerResultStub = {} beforeEach(function () { pendingTxs = [{ 'status': 'submitted', + 'txParams': { + 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', + 'gas': '0x30d40', + 'value': '0x0', + 'nonce': '0x3', + }, + }] + confirmedTxs = [{ + 'status': 'confirmed', 'txParams': { 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', 'gas': '0x30d40', 'value': '0x0', 'nonce': '0x0', }, + }, { + 'status': 'confirmed', + 'txParams': { + 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', + 'gas': '0x30d40', + 'value': '0x0', + 'nonce': '0x1', + }, + }, { + 'status': 'confirmed', + 'txParams': { + 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', + 'gas': '0x30d40', + 'value': '0x0', + 'nonce': '0x2', + }, }] getPendingTransactions = () => pendingTxs + getConfirmedTransactions = () => confirmedTxs + providerResultStub.result = '0x3' provider = { - sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) }, + sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, _blockTracker: { getCurrentBlock: () => '0x11b568', }, @@ -27,6 +56,7 @@ describe('Nonce Tracker', function () { nonceTracker = new NonceTracker({ provider, getPendingTransactions, + getConfirmedTransactions, }) }) @@ -34,7 +64,15 @@ describe('Nonce Tracker', function () { it('should work', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '1', 'nonce should be 1') + assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') + await nonceLock.releaseLock() + }) + + it('should use localNonce if network returns a nonce lower then a confirmed tx in state', async function () { + this.timeout(15000) + providerResultStub.result = '0x1' + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') await nonceLock.releaseLock() }) }) -- cgit From c76194d7c315f9fb8e536328f97a2ac2dc411097 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Aug 2017 11:35:18 -0700 Subject: Move mock txs to tx mocking class --- test/unit/nonce-tracker-test.js | 43 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 2171d859d..225cfbae5 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -1,5 +1,6 @@ const assert = require('assert') const NonceTracker = require('../../app/scripts/lib/nonce-tracker') +const MockTxGen = require('../lib/mock-tx-gen') describe('Nonce Tracker', function () { let nonceTracker, provider @@ -8,41 +9,9 @@ describe('Nonce Tracker', function () { let providerResultStub = {} beforeEach(function () { - pendingTxs = [{ - 'status': 'submitted', - 'txParams': { - 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', - 'gas': '0x30d40', - 'value': '0x0', - 'nonce': '0x3', - }, - }] - confirmedTxs = [{ - 'status': 'confirmed', - 'txParams': { - 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', - 'gas': '0x30d40', - 'value': '0x0', - 'nonce': '0x0', - }, - }, { - 'status': 'confirmed', - 'txParams': { - 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', - 'gas': '0x30d40', - 'value': '0x0', - 'nonce': '0x1', - }, - }, { - 'status': 'confirmed', - 'txParams': { - 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926', - 'gas': '0x30d40', - 'value': '0x0', - 'nonce': '0x2', - }, - }] - + const txGen = new MockTxGen() + confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) + pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 }) getPendingTransactions = () => pendingTxs getConfirmedTransactions = () => confirmedTxs @@ -68,6 +37,10 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) + it('should return 0 if there are no previous transactions', async function () { + + }) + it('should use localNonce if network returns a nonce lower then a confirmed tx in state', async function () { this.timeout(15000) providerResultStub.result = '0x1' -- cgit From f13c637b23135dcf9ba1b4fbd82da1422e8ea326 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Aug 2017 11:37:39 -0700 Subject: Confine mock strategy to describe block --- test/unit/nonce-tracker-test.js | 74 ++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 225cfbae5..5b8318f59 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -8,45 +8,49 @@ describe('Nonce Tracker', function () { let getConfirmedTransactions, confirmedTxs let providerResultStub = {} - beforeEach(function () { - const txGen = new MockTxGen() - confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) - pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 }) - - getPendingTransactions = () => pendingTxs - getConfirmedTransactions = () => confirmedTxs - providerResultStub.result = '0x3' - provider = { - sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, - _blockTracker: { - getCurrentBlock: () => '0x11b568', - }, - } - nonceTracker = new NonceTracker({ - provider, - getPendingTransactions, - getConfirmedTransactions, - }) - }) - describe('#getNonceLock', function () { - it('should work', async function () { - this.timeout(15000) - const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') - await nonceLock.releaseLock() - }) - it('should return 0 if there are no previous transactions', async function () { + describe('with 3 confirmed and 1 pending', function () { + beforeEach(function () { + const txGen = new MockTxGen() + confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) + pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 }) - }) + getPendingTransactions = () => pendingTxs + getConfirmedTransactions = () => confirmedTxs + providerResultStub.result = '0x3' + provider = { + sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, + _blockTracker: { + getCurrentBlock: () => '0x11b568', + }, + } + nonceTracker = new NonceTracker({ + provider, + getPendingTransactions, + getConfirmedTransactions, + }) + }) + + it('should work', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') + await nonceLock.releaseLock() + }) + + it('should return 0 if there are no previous transactions', async function () { + + }) + + it('should use localNonce if network returns a nonce lower then a confirmed tx in state', async function () { + this.timeout(15000) + providerResultStub.result = '0x1' + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') + await nonceLock.releaseLock() + }) - it('should use localNonce if network returns a nonce lower then a confirmed tx in state', async function () { - this.timeout(15000) - providerResultStub.result = '0x1' - const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') - await nonceLock.releaseLock() }) }) }) -- cgit From 306249e89e84db3d3eab9b454b8ef9daad4ac035 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Aug 2017 11:39:22 -0700 Subject: Add test for no previous txs --- test/unit/nonce-tracker-test.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 5b8318f59..617d9b56c 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -39,10 +39,6 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) - it('should return 0 if there are no previous transactions', async function () { - - }) - it('should use localNonce if network returns a nonce lower then a confirmed tx in state', async function () { this.timeout(15000) providerResultStub.result = '0x1' @@ -50,7 +46,32 @@ describe('Nonce Tracker', function () { assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') await nonceLock.releaseLock() }) + }) + + describe('with no previous txs', function () { + beforeEach(function () { + getPendingTransactions = () => [] + getConfirmedTransactions = () => [] + providerResultStub.result = '0x0' + provider = { + sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, + _blockTracker: { + getCurrentBlock: () => '0x11b568', + }, + } + nonceTracker = new NonceTracker({ + provider, + getPendingTransactions, + getConfirmedTransactions, + }) + }) + it('should return 0', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '0', 'nonce should be 0') + await nonceLock.releaseLock() + }) }) }) }) -- cgit From 440101f2b561a92e81545140f0232b94af143831 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Aug 2017 11:52:41 -0700 Subject: Add new assertions and de-duplicate nonce tracker generation --- test/unit/nonce-tracker-test.js | 102 ++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 29 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 617d9b56c..3ed0eda9b 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -15,21 +15,7 @@ describe('Nonce Tracker', function () { const txGen = new MockTxGen() confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 }) - - getPendingTransactions = () => pendingTxs - getConfirmedTransactions = () => confirmedTxs - providerResultStub.result = '0x3' - provider = { - sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, - _blockTracker: { - getCurrentBlock: () => '0x11b568', - }, - } - nonceTracker = new NonceTracker({ - provider, - getPendingTransactions, - getConfirmedTransactions, - }) + nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs) }) it('should work', async function () { @@ -50,20 +36,7 @@ describe('Nonce Tracker', function () { describe('with no previous txs', function () { beforeEach(function () { - getPendingTransactions = () => [] - getConfirmedTransactions = () => [] - providerResultStub.result = '0x0' - provider = { - sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, - _blockTracker: { - getCurrentBlock: () => '0x11b568', - }, - } - nonceTracker = new NonceTracker({ - provider, - getPendingTransactions, - getConfirmedTransactions, - }) + nonceTracker = generateNonceTrackerWith([], []) }) it('should return 0', async function () { @@ -73,5 +46,76 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) }) + + describe('with multiple previous txs with same nonce', function () { + beforeEach(function () { + const txGen = new MockTxGen() + confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 1 }) + pendingTxs = txGen.generate({ + status: 'pending', + txParams: { nonce: '0x01' }, + }, { count: 5 }) + + nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs) + }) + + it('should return nonce after those', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + console.dir(nonceLock.nextNonce) + assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') + await nonceLock.releaseLock() + }) + }) + + describe('when local confirmed count is higher than network nonce', function () { + beforeEach(function () { + const txGen = new MockTxGen() + confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 2 }) + nonceTracker = generateNonceTrackerWith([], confirmedTxs) + }) + + it('should return nonce after those', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + console.dir(nonceLock.nextNonce) + assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') + await nonceLock.releaseLock() + }) + }) + + describe('when local pending count is higher than other metrics', function () { + beforeEach(function () { + const txGen = new MockTxGen() + pendingTxs = txGen.generate({ status: 'pending' }, { count: 2 }) + nonceTracker = generateNonceTrackerWith(pendingTxs, []) + }) + + it('should return nonce after those', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + console.dir(nonceLock.nextNonce) + assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') + await nonceLock.releaseLock() + }) + }) }) }) + +function generateNonceTrackerWith(pending, confirmed) { + const getPendingTransactions = () => pending + const getConfirmedTransactions = () => confirmed + providerResultStub.result = '0x0' + const provider = { + sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, + _blockTracker: { + getCurrentBlock: () => '0x11b568', + }, + } + return new NonceTracker({ + provider, + getPendingTransactions, + getConfirmedTransactions, + }) +} + -- cgit From 0f36e0e6da4027ea4b41510e9a81939d71b11586 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Aug 2017 11:57:42 -0700 Subject: Fix test --- test/unit/nonce-tracker-test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 3ed0eda9b..e8fa73b55 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -1,12 +1,12 @@ const assert = require('assert') const NonceTracker = require('../../app/scripts/lib/nonce-tracker') const MockTxGen = require('../lib/mock-tx-gen') +let providerResultStub = {} describe('Nonce Tracker', function () { let nonceTracker, provider let getPendingTransactions, pendingTxs let getConfirmedTransactions, confirmedTxs - let providerResultStub = {} describe('#getNonceLock', function () { @@ -15,7 +15,8 @@ describe('Nonce Tracker', function () { const txGen = new MockTxGen() confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 }) - nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs) + console.dir(txGen.txs) + nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs, '0x1') }) it('should work', async function () { @@ -27,7 +28,6 @@ describe('Nonce Tracker', function () { it('should use localNonce if network returns a nonce lower then a confirmed tx in state', async function () { this.timeout(15000) - providerResultStub.result = '0x1' const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') await nonceLock.releaseLock() @@ -102,10 +102,10 @@ describe('Nonce Tracker', function () { }) }) -function generateNonceTrackerWith(pending, confirmed) { +function generateNonceTrackerWith(pending, confirmed, providerStub = '0x0') { const getPendingTransactions = () => pending const getConfirmedTransactions = () => confirmed - providerResultStub.result = '0x0' + providerResultStub.result = providerStub const provider = { sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, _blockTracker: { -- cgit From bb24f07b1759eb46fa4e4f733c348f1b87521eb6 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Aug 2017 11:59:51 -0700 Subject: When network nonce is highest, it should be used. --- test/unit/nonce-tracker-test.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index e8fa73b55..78fdee209 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -15,7 +15,6 @@ describe('Nonce Tracker', function () { const txGen = new MockTxGen() confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 }) - console.dir(txGen.txs) nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs, '0x1') }) @@ -62,7 +61,6 @@ describe('Nonce Tracker', function () { it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - console.dir(nonceLock.nextNonce) assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') await nonceLock.releaseLock() }) @@ -78,7 +76,6 @@ describe('Nonce Tracker', function () { it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - console.dir(nonceLock.nextNonce) assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') await nonceLock.releaseLock() }) @@ -94,11 +91,25 @@ describe('Nonce Tracker', function () { it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - console.dir(nonceLock.nextNonce) assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') await nonceLock.releaseLock() }) }) + + describe('when provider nonce is higher than other metrics', function () { + beforeEach(function () { + const txGen = new MockTxGen() + pendingTxs = txGen.generate({ status: 'pending' }, { count: 2 }) + nonceTracker = generateNonceTrackerWith(pendingTxs, [], '0x05') + }) + + it('should return nonce after those', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '6', 'nonce should be 6') + await nonceLock.releaseLock() + }) + }) }) }) -- cgit From e43db262d8aa3fb725bc8e05d2ecbf38de32688a Mon Sep 17 00:00:00 2001 From: frankiebee Date: Mon, 21 Aug 2017 16:44:29 -0700 Subject: fix test --- test/unit/nonce-tracker-test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 78fdee209..9a819b146 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -14,7 +14,7 @@ describe('Nonce Tracker', function () { beforeEach(function () { const txGen = new MockTxGen() confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) - pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 }) + pendingTxs = txGen.generate({ status: 'submitted' }, { count: 1 }) nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs, '0x1') }) @@ -51,7 +51,7 @@ describe('Nonce Tracker', function () { const txGen = new MockTxGen() confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 1 }) pendingTxs = txGen.generate({ - status: 'pending', + status: 'submitted', txParams: { nonce: '0x01' }, }, { count: 5 }) @@ -61,7 +61,7 @@ describe('Nonce Tracker', function () { it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') + assert.equal(nonceLock.nextNonce, '2', `nonce should be 2 got ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) }) @@ -76,7 +76,7 @@ describe('Nonce Tracker', function () { it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') + assert.equal(nonceLock.nextNonce, '2', `nonce should be 2 got ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) }) @@ -84,14 +84,14 @@ describe('Nonce Tracker', function () { describe('when local pending count is higher than other metrics', function () { beforeEach(function () { const txGen = new MockTxGen() - pendingTxs = txGen.generate({ status: 'pending' }, { count: 2 }) + pendingTxs = txGen.generate({ status: 'submitted' }, { count: 2 }) nonceTracker = generateNonceTrackerWith(pendingTxs, []) }) it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '2', 'nonce should be 2') + assert.equal(nonceLock.nextNonce, '2', `nonce should be 2 got ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) }) @@ -99,21 +99,21 @@ describe('Nonce Tracker', function () { describe('when provider nonce is higher than other metrics', function () { beforeEach(function () { const txGen = new MockTxGen() - pendingTxs = txGen.generate({ status: 'pending' }, { count: 2 }) + pendingTxs = txGen.generate({ status: 'submitted' }, { count: 2 }) nonceTracker = generateNonceTrackerWith(pendingTxs, [], '0x05') }) it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '6', 'nonce should be 6') + assert.equal(nonceLock.nextNonce, '5', `nonce should be 5 got ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) }) }) }) -function generateNonceTrackerWith(pending, confirmed, providerStub = '0x0') { +function generateNonceTrackerWith (pending, confirmed, providerStub = '0x0') { const getPendingTransactions = () => pending const getConfirmedTransactions = () => confirmed providerResultStub.result = providerStub -- cgit From 38ba31bbe01785761c03f5d7d781939104d34f37 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Aug 2017 17:29:31 -0700 Subject: Refer to pending nonces, not just their count --- test/unit/nonce-tracker-test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 9a819b146..11f99751c 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -110,6 +110,21 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) }) + + describe('when there are some pending nonces below the remote one and some over.', function () { + beforeEach(function () { + const txGen = new MockTxGen() + pendingTxs = txGen.generate({ status: 'submitted' }, { count: 5 }) + nonceTracker = generateNonceTrackerWith(pendingTxs, [], '0x03') + }) + + it('should return nonce after those', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '5', `nonce should be 5 got ${nonceLock.nextNonce}`) + await nonceLock.releaseLock() + }) + }) }) }) -- cgit From 5feda433607fc5a762e1e0843598bacda9d11ca9 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 23 Aug 2017 19:34:37 -0700 Subject: Add failing test for newly identified error state Reproduces #1966 --- test/unit/nonce-tracker-test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 11f99751c..5b0732d44 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -125,6 +125,23 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) }) + + describe('when there are pending nonces non sequentially over the network nonce.', function () { + beforeEach(function () { + const txGen = new MockTxGen() + txGen.generate({ status: 'submitted' }, { count: 5 }) + // 5 over that number + pendingTxs = txGen.generate({ status: 'submitted' }, { count: 5 }) + nonceTracker = generateNonceTrackerWith(pendingTxs, [], '0x00') + }) + + it('should return nonce after network nonce', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '0', `nonce should be 0 got ${nonceLock.nextNonce}`) + await nonceLock.releaseLock() + }) + }) }) }) -- cgit From 221575a191a0a8b8c4c17465a0530561e1905297 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 23 Aug 2017 20:04:03 -0700 Subject: Fix new test, break an older maybe wrong one --- test/unit/nonce-tracker-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 5b0732d44..c5a71d6c8 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -18,10 +18,10 @@ describe('Nonce Tracker', function () { nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs, '0x1') }) - it('should work', async function () { + it('should return 4', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '4', 'nonce should be 4') + assert.equal(nonceLock.nextNonce, '4', `nonce should be 4 got ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) @@ -41,7 +41,7 @@ describe('Nonce Tracker', function () { it('should return 0', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '0', 'nonce should be 0') + assert.equal(nonceLock.nextNonce, '0', `nonce should be 0 returned ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) }) -- cgit From 855f4eeacbcf7b3e056cf7956edea2c84fa256d5 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 23 Aug 2017 20:31:03 -0700 Subject: Pass nonce tests --- test/unit/nonce-tracker-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index c5a71d6c8..758bf9eb6 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -55,7 +55,7 @@ describe('Nonce Tracker', function () { txParams: { nonce: '0x01' }, }, { count: 5 }) - nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs) + nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs, '0x0') }) it('should return nonce after those', async function () { @@ -69,14 +69,14 @@ describe('Nonce Tracker', function () { describe('when local confirmed count is higher than network nonce', function () { beforeEach(function () { const txGen = new MockTxGen() - confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 2 }) - nonceTracker = generateNonceTrackerWith([], confirmedTxs) + confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 }) + nonceTracker = generateNonceTrackerWith([], confirmedTxs, '0x1') }) it('should return nonce after those', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '2', `nonce should be 2 got ${nonceLock.nextNonce}`) + assert.equal(nonceLock.nextNonce, '3', `nonce should be 3 got ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) }) -- cgit From dae7c632d6b7bed74abbe6bbc7b6b43deb2f2f0d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 23 Aug 2017 21:01:42 -0700 Subject: Add mysterious failing test --- test/unit/nonce-tracker-test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 758bf9eb6..5f247b46b 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -142,6 +142,26 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) }) + + describe('A normal usage condition.', function () { + beforeEach(function () { + const txGen = new MockTxGen() + const confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 10 }) + const pendingTxs = txGen.generate({ + status: 'submitted', + nonce: 100, + }, { count: 1 }) + // 0x32 is 50 in hex: + nonceTracker = generateNonceTrackerWith(pendingTxs, confirmedTxs, '0x32') + }) + + it('should return nonce after network nonce', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '10', `nonce should be 10 got ${nonceLock.nextNonce}`) + await nonceLock.releaseLock() + }) + }) }) }) -- cgit From e057c37b337f34556af1734ceb44e7a4d9a7b08c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 23 Aug 2017 21:03:29 -0700 Subject: Corrected test constraints --- test/unit/nonce-tracker-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 5f247b46b..3312a3bd0 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -143,7 +143,7 @@ describe('Nonce Tracker', function () { }) }) - describe('A normal usage condition.', function () { + describe('When all three return different values', function () { beforeEach(function () { const txGen = new MockTxGen() const confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 10 }) @@ -158,7 +158,7 @@ describe('Nonce Tracker', function () { it('should return nonce after network nonce', async function () { this.timeout(15000) const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') - assert.equal(nonceLock.nextNonce, '10', `nonce should be 10 got ${nonceLock.nextNonce}`) + assert.equal(nonceLock.nextNonce, '50', `nonce should be 50 got ${nonceLock.nextNonce}`) await nonceLock.releaseLock() }) }) -- cgit From 2117490d41a31eeb2d39383bfc5ae7751f445420 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 29 Aug 2017 11:36:53 -0700 Subject: Add test for trying to reproduce faq#67 Failed to reproduce this issue with the same inputs. --- test/unit/nonce-tracker-test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 3312a3bd0..8970cf84d 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -162,6 +162,25 @@ describe('Nonce Tracker', function () { await nonceLock.releaseLock() }) }) + + describe('Faq issue 67', function () { + beforeEach(function () { + const txGen = new MockTxGen() + const confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 64 }) + const pendingTxs = txGen.generate({ + status: 'submitted', + }, { count: 10 }) + // 0x40 is 64 in hex: + nonceTracker = generateNonceTrackerWith(pendingTxs, [], '0x40') + }) + + it('should return nonce after network nonce', async function () { + this.timeout(15000) + const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926') + assert.equal(nonceLock.nextNonce, '74', `nonce should be 74 got ${nonceLock.nextNonce}`) + await nonceLock.releaseLock() + }) + }) }) }) -- cgit From dcf10f3d7559b428cc189fb4406580d816eae365 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Oct 2017 18:33:02 -0700 Subject: nonce-tracker - use blockTracker directly --- test/unit/nonce-tracker-test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 8970cf84d..77af2a21c 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -190,12 +190,13 @@ function generateNonceTrackerWith (pending, confirmed, providerStub = '0x0') { providerResultStub.result = providerStub const provider = { sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, - _blockTracker: { - getCurrentBlock: () => '0x11b568', - }, + } + const blockTracker = { + getCurrentBlock: () => '0x11b568', } return new NonceTracker({ provider, + blockTracker, getPendingTransactions, getConfirmedTransactions, }) -- cgit From 8da0d0b28a52d476da3623774159e8d6a595da2d Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 18 Oct 2017 15:09:32 -0700 Subject: Revert "NetworkController refactor for new EthClient interface" --- test/unit/nonce-tracker-test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/unit/nonce-tracker-test.js') diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 77af2a21c..8970cf84d 100644 --- a/test/unit/nonce-tracker-test.js +++ b/test/unit/nonce-tracker-test.js @@ -190,13 +190,12 @@ function generateNonceTrackerWith (pending, confirmed, providerStub = '0x0') { providerResultStub.result = providerStub const provider = { sendAsync: (_, cb) => { cb(undefined, providerResultStub) }, - } - const blockTracker = { - getCurrentBlock: () => '0x11b568', + _blockTracker: { + getCurrentBlock: () => '0x11b568', + }, } return new NonceTracker({ provider, - blockTracker, getPendingTransactions, getConfirmedTransactions, }) -- cgit