diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-08-29 02:29:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-29 02:29:47 +0800 |
commit | 76de053b0b0a40f98fa88de950fdaae33dbbf666 (patch) | |
tree | f6e00b78db4f9c7ba0e5968c6df1637825d3db5e /test/unit/nonce-tracker-test.js | |
parent | 6bff55ba2ae36a1d005b052940d91e6e43262359 (diff) | |
parent | 34b327caf07cd395229806cedecdeb770c034562 (diff) | |
download | tangerine-wallet-browser-76de053b0b0a40f98fa88de950fdaae33dbbf666.tar tangerine-wallet-browser-76de053b0b0a40f98fa88de950fdaae33dbbf666.tar.gz tangerine-wallet-browser-76de053b0b0a40f98fa88de950fdaae33dbbf666.tar.bz2 tangerine-wallet-browser-76de053b0b0a40f98fa88de950fdaae33dbbf666.tar.lz tangerine-wallet-browser-76de053b0b0a40f98fa88de950fdaae33dbbf666.tar.xz tangerine-wallet-browser-76de053b0b0a40f98fa88de950fdaae33dbbf666.tar.zst tangerine-wallet-browser-76de053b0b0a40f98fa88de950fdaae33dbbf666.zip |
Merge branch 'master' into inpage-provider-fixes
Diffstat (limited to 'test/unit/nonce-tracker-test.js')
-rw-r--r-- | test/unit/nonce-tracker-test.js | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js index 11f99751c..3312a3bd0 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() }) }) @@ -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() }) }) @@ -125,6 +125,43 @@ 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() + }) + }) + + describe('When all three return different values', 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, '50', `nonce should be 50 got ${nonceLock.nextNonce}`) + await nonceLock.releaseLock() + }) + }) }) }) |