Skip to content

Commit

Permalink
ParseInt nextworkNextNonce correction (#8827)
Browse files Browse the repository at this point in the history
* networkNextNonce toNumber

* nonceBN for all getTransactionCount

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
  • Loading branch information
tmashuang and Gudahtt authored Jun 17, 2020
1 parent c8be5d0 commit 753a3eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/scripts/controllers/transactions/pending-tx-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default class PendingTransactionTracker extends EventEmitter {
const { hash: txHash, txParams: { nonce, from } } = txMeta
const networkNextNonce = await this.query.getTransactionCount(from)

if (parseInt(nonce, 16) >= parseInt(networkNextNonce, 16)) {
if (parseInt(nonce, 16) >= networkNextNonce.toNumber()) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sinon from 'sinon'
import { strict as assert } from 'assert'
import BN from 'bn.js'
import PendingTransactionTracker from '../../../../../app/scripts/controllers/transactions/pending-tx-tracker'

describe('PendingTransactionTracker', function () {
Expand Down Expand Up @@ -311,10 +312,11 @@ describe('PendingTransactionTracker', function () {

describe('#_checkIfTxWasDropped', 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({
query: {
getTransactionReceipt: sinon.stub(),
getTransactionCount: sinon.stub().resolves('0x02'),
getTransactionCount: sinon.stub().resolves(nonceBN),
},
nonceTracker: {
getGlobalLock: sinon.stub().resolves({
Expand Down Expand Up @@ -343,10 +345,11 @@ describe('PendingTransactionTracker', function () {
})

it('should return false when the given nonce is the network nonce', async function () {
const nonceBN = new BN(1)
const pendingTxTracker = new PendingTransactionTracker({
query: {
getTransactionReceipt: sinon.stub(),
getTransactionCount: sinon.stub().resolves('0x01'),
getTransactionCount: sinon.stub().resolves(nonceBN),
},
nonceTracker: {
getGlobalLock: sinon.stub().resolves({
Expand Down Expand Up @@ -487,10 +490,11 @@ describe('PendingTransactionTracker', function () {
history: [{}],
rawTx: '0xf86c808504a817c80082471d',
}
const nonceBN = new BN(2)
const pendingTxTracker = new PendingTransactionTracker({
query: {
getTransactionReceipt: sinon.stub().rejects(),
getTransactionCount: sinon.stub().resolves('0x02'),
getTransactionCount: sinon.stub().resolves(nonceBN),
},
nonceTracker: {
getGlobalLock: sinon.stub().resolves({
Expand Down Expand Up @@ -647,6 +651,7 @@ describe('PendingTransactionTracker', function () {
})

it("should emit 'tx:dropped' with the txMetas id only after the fourth call", async function () {
const nonceBN = new BN(2)
const txMeta = {
id: 1,
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
Expand All @@ -662,7 +667,7 @@ describe('PendingTransactionTracker', function () {
const pendingTxTracker = new PendingTransactionTracker({
query: {
getTransactionReceipt: sinon.stub().resolves(null),
getTransactionCount: sinon.stub().resolves('0x02'),
getTransactionCount: sinon.stub().resolves(nonceBN),
},
nonceTracker: {
getGlobalLock: sinon.stub().resolves({
Expand Down

0 comments on commit 753a3eb

Please sign in to comment.