mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Pass nonce tests
This commit is contained in:
parent
04d40b114d
commit
855f4eeacb
@ -30,10 +30,12 @@ class NonceTracker {
|
||||
const nonceDetails = {}
|
||||
const networkNonceResult = await this._getNetworkNextNonce(address)
|
||||
const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address)
|
||||
const nextNetworkNonce = networkNonceResult.nonce
|
||||
const highestLocalNonce = highestLocallyConfirmed
|
||||
const highestSuggested = Math.max(nextNetworkNonce, highestLocalNonce)
|
||||
|
||||
const highestConfirmed = Math.max(networkNonceResult.nonce, highestLocallyConfirmed)
|
||||
const pendingTxs = this.getPendingTransactions(address)
|
||||
const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestConfirmed) || 0
|
||||
const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0
|
||||
|
||||
nonceDetails.local = localNonceResult.details
|
||||
nonceDetails.network = networkNonceResult.details
|
||||
@ -90,7 +92,7 @@ class NonceTracker {
|
||||
_getHighestLocallyConfirmed (address) {
|
||||
const confirmedTransactions = this.getConfirmedTransactions(address)
|
||||
const highest = this._getHighestNonce(confirmedTransactions)
|
||||
return highest
|
||||
return Number.isInteger(highest) ? highest + 1 : 0
|
||||
}
|
||||
|
||||
_reduceTxListToUniqueNonces (txList) {
|
||||
@ -116,14 +118,11 @@ class NonceTracker {
|
||||
const nonces = txList.map((txMeta) => parseInt(txMeta.txParams.nonce, 16))
|
||||
|
||||
let highest = startPoint
|
||||
while (nonces.includes(highest + 1)) {
|
||||
while (nonces.includes(highest)) {
|
||||
highest++
|
||||
}
|
||||
|
||||
const haveHighestNonce = Number.isInteger(highest) && highest > 0
|
||||
const nonce = haveHighestNonce ? highest + 1 : 0
|
||||
|
||||
return { name: 'local', nonce }
|
||||
return { name: 'local', nonce: highest, details: { startPoint, highest } }
|
||||
}
|
||||
|
||||
// this is a hotfix for the fact that the blockTracker will
|
||||
|
@ -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()
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user