1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

ParseInt nextworkNextNonce correction (#8827)

* networkNextNonce toNumber

* nonceBN for all getTransactionCount

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
Thomas Huang 2020-06-17 14:13:33 -07:00 committed by GitHub
parent c8be5d0779
commit 753a3eb4c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -211,7 +211,7 @@ export default class PendingTransactionTracker extends EventEmitter {
const { hash: txHash, txParams: { nonce, from } } = txMeta const { hash: txHash, txParams: { nonce, from } } = txMeta
const networkNextNonce = await this.query.getTransactionCount(from) const networkNextNonce = await this.query.getTransactionCount(from)
if (parseInt(nonce, 16) >= parseInt(networkNextNonce, 16)) { if (parseInt(nonce, 16) >= networkNextNonce.toNumber()) {
return false return false
} }

View File

@ -1,5 +1,6 @@
import sinon from 'sinon' import sinon from 'sinon'
import { strict as assert } from 'assert' import { strict as assert } from 'assert'
import BN from 'bn.js'
import PendingTransactionTracker from '../../../../../app/scripts/controllers/transactions/pending-tx-tracker' import PendingTransactionTracker from '../../../../../app/scripts/controllers/transactions/pending-tx-tracker'
describe('PendingTransactionTracker', function () { describe('PendingTransactionTracker', function () {
@ -311,10 +312,11 @@ describe('PendingTransactionTracker', function () {
describe('#_checkIfTxWasDropped', function () { describe('#_checkIfTxWasDropped', function () {
it('should return true when the given nonce is lower than the network nonce', async function () { it('should return true when the given nonce is lower than the network nonce', async function () {
const nonceBN = new BN(2)
const pendingTxTracker = new PendingTransactionTracker({ const pendingTxTracker = new PendingTransactionTracker({
query: { query: {
getTransactionReceipt: sinon.stub(), getTransactionReceipt: sinon.stub(),
getTransactionCount: sinon.stub().resolves('0x02'), getTransactionCount: sinon.stub().resolves(nonceBN),
}, },
nonceTracker: { nonceTracker: {
getGlobalLock: sinon.stub().resolves({ getGlobalLock: sinon.stub().resolves({
@ -343,10 +345,11 @@ describe('PendingTransactionTracker', function () {
}) })
it('should return false when the given nonce is the network nonce', async function () { it('should return false when the given nonce is the network nonce', async function () {
const nonceBN = new BN(1)
const pendingTxTracker = new PendingTransactionTracker({ const pendingTxTracker = new PendingTransactionTracker({
query: { query: {
getTransactionReceipt: sinon.stub(), getTransactionReceipt: sinon.stub(),
getTransactionCount: sinon.stub().resolves('0x01'), getTransactionCount: sinon.stub().resolves(nonceBN),
}, },
nonceTracker: { nonceTracker: {
getGlobalLock: sinon.stub().resolves({ getGlobalLock: sinon.stub().resolves({
@ -487,10 +490,11 @@ describe('PendingTransactionTracker', function () {
history: [{}], history: [{}],
rawTx: '0xf86c808504a817c80082471d', rawTx: '0xf86c808504a817c80082471d',
} }
const nonceBN = new BN(2)
const pendingTxTracker = new PendingTransactionTracker({ const pendingTxTracker = new PendingTransactionTracker({
query: { query: {
getTransactionReceipt: sinon.stub().rejects(), getTransactionReceipt: sinon.stub().rejects(),
getTransactionCount: sinon.stub().resolves('0x02'), getTransactionCount: sinon.stub().resolves(nonceBN),
}, },
nonceTracker: { nonceTracker: {
getGlobalLock: sinon.stub().resolves({ getGlobalLock: sinon.stub().resolves({
@ -647,6 +651,7 @@ describe('PendingTransactionTracker', function () {
}) })
it("should emit 'tx:dropped' with the txMetas id only after the fourth call", async function () { it("should emit 'tx:dropped' with the txMetas id only after the fourth call", async function () {
const nonceBN = new BN(2)
const txMeta = { const txMeta = {
id: 1, id: 1,
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb', hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
@ -662,7 +667,7 @@ describe('PendingTransactionTracker', function () {
const pendingTxTracker = new PendingTransactionTracker({ const pendingTxTracker = new PendingTransactionTracker({
query: { query: {
getTransactionReceipt: sinon.stub().resolves(null), getTransactionReceipt: sinon.stub().resolves(null),
getTransactionCount: sinon.stub().resolves('0x02'), getTransactionCount: sinon.stub().resolves(nonceBN),
}, },
nonceTracker: { nonceTracker: {
getGlobalLock: sinon.stub().resolves({ getGlobalLock: sinon.stub().resolves({