2017-08-04 20:40:22 +02:00
|
|
|
const assert = require('assert')
|
2018-05-21 14:59:26 +02:00
|
|
|
const { createTestProviderTools } = require('../../../../stub/provider')
|
|
|
|
const PendingTransactionTracker = require('../../../../../app/scripts/controllers/transactions/pending-tx-tracker')
|
|
|
|
const MockTxGen = require('../../../../lib/mock-tx-gen')
|
2017-10-06 21:29:27 +02:00
|
|
|
const sinon = require('sinon')
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2017-11-02 18:28:41 +01:00
|
|
|
|
2018-05-23 01:41:00 +02:00
|
|
|
describe('PendingTransactionTracker', function () {
|
2018-07-03 02:12:50 +02:00
|
|
|
let pendingTxTracker, txMeta, txMetaNoHash, providerResultStub,
|
2019-07-31 22:17:11 +02:00
|
|
|
provider, txMeta3, txList, knownErrors
|
2017-08-04 20:40:22 +02:00
|
|
|
this.timeout(10000)
|
2018-05-25 08:19:54 +02:00
|
|
|
|
2017-08-04 20:40:22 +02:00
|
|
|
beforeEach(function () {
|
|
|
|
txMeta = {
|
|
|
|
id: 1,
|
2017-08-09 00:30:22 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2017-08-04 20:40:22 +02:00
|
|
|
status: 'signed',
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
2018-11-16 19:34:08 +01:00
|
|
|
history: [{}],
|
2017-08-04 20:40:22 +02:00
|
|
|
rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
}
|
|
|
|
txMetaNoHash = {
|
|
|
|
id: 2,
|
2018-11-16 19:34:08 +01:00
|
|
|
history: [{}],
|
2018-11-14 22:34:07 +01:00
|
|
|
status: 'submitted',
|
2019-12-03 21:50:55 +01:00
|
|
|
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d' },
|
2017-08-04 20:40:22 +02:00
|
|
|
}
|
2018-07-03 02:12:50 +02:00
|
|
|
|
2017-08-09 00:30:22 +02:00
|
|
|
providerResultStub = {}
|
2018-01-18 06:43:34 +01:00
|
|
|
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2017-08-09 00:30:22 +02:00
|
|
|
pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
provider,
|
2017-08-04 20:40:22 +02:00
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: async () => {
|
|
|
|
return { releaseLock: () => {} }
|
2018-07-03 00:49:33 +02:00
|
|
|
},
|
2017-08-04 20:40:22 +02:00
|
|
|
},
|
2019-11-20 01:03:20 +01:00
|
|
|
getPendingTransactions: () => {
|
|
|
|
return []
|
|
|
|
},
|
|
|
|
getCompletedTransactions: () => {
|
|
|
|
return []
|
|
|
|
},
|
2017-08-04 20:40:22 +02:00
|
|
|
publishTransaction: () => {},
|
2018-05-23 01:37:30 +02:00
|
|
|
confirmTransaction: () => {},
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
2018-05-23 01:37:30 +02:00
|
|
|
|
2019-11-20 01:03:20 +01:00
|
|
|
pendingTxTracker._getBlock = (blockNumber) => {
|
2019-12-03 21:50:55 +01:00
|
|
|
return { number: blockNumber, transactions: [] }
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
|
|
|
|
2017-10-06 21:29:27 +02:00
|
|
|
describe('_checkPendingTx state management', function () {
|
|
|
|
let stub
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
if (stub) {
|
|
|
|
stub.restore()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-05-16 07:36:53 +02:00
|
|
|
it('should emit dropped if another tx with the same nonce succeeds', async function () {
|
2017-10-06 21:29:27 +02:00
|
|
|
|
|
|
|
// SETUP
|
|
|
|
const txGen = new MockTxGen()
|
|
|
|
|
|
|
|
txGen.generate({
|
|
|
|
id: '456',
|
|
|
|
value: '0x01',
|
|
|
|
hash: '0xbad',
|
|
|
|
status: 'confirmed',
|
2019-12-05 20:34:10 +01:00
|
|
|
}, { count: 1, fromNonce: '0x01' })
|
2017-10-06 21:29:27 +02:00
|
|
|
|
|
|
|
const pending = txGen.generate({
|
|
|
|
id: '123',
|
|
|
|
value: '0x02',
|
2019-12-05 20:34:10 +01:00
|
|
|
hash: '0x2a919d2512ec963f524bfd9730fb66b6d5a2e399d1dd957abb5e2b544a12644b',
|
2017-10-06 21:29:27 +02:00
|
|
|
status: 'submitted',
|
2019-12-05 20:34:10 +01:00
|
|
|
}, { count: 1, fromNonce: '0x01' })[0]
|
2017-10-06 21:29:27 +02:00
|
|
|
|
2017-10-06 21:50:33 +02:00
|
|
|
stub = sinon.stub(pendingTxTracker, 'getCompletedTransactions')
|
2019-07-31 22:17:11 +02:00
|
|
|
.returns(txGen.txs)
|
2017-10-06 21:29:27 +02:00
|
|
|
|
|
|
|
// THE EXPECTATION
|
|
|
|
const spy = sinon.spy()
|
2019-05-16 07:36:53 +02:00
|
|
|
pendingTxTracker.on('tx:dropped', (txId) => {
|
2017-10-06 21:29:27 +02:00
|
|
|
assert.equal(txId, pending.id, 'should fail the pending tx')
|
2019-05-16 07:36:53 +02:00
|
|
|
spy(txId)
|
2017-10-06 21:29:27 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// THE METHOD
|
|
|
|
await pendingTxTracker._checkPendingTx(pending)
|
|
|
|
|
|
|
|
// THE ASSERTION
|
2019-05-16 07:36:53 +02:00
|
|
|
assert.ok(spy.calledWith(pending.id), 'tx dropped should be emitted')
|
2017-10-06 21:29:27 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-08-04 20:40:22 +02:00
|
|
|
describe('#_checkPendingTx', function () {
|
2017-10-03 00:14:15 +02:00
|
|
|
it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) {
|
2019-05-08 21:51:33 +02:00
|
|
|
pendingTxTracker.once('tx:failed', (txId) => {
|
2017-08-04 20:40:22 +02:00
|
|
|
assert(txId, txMetaNoHash.id, 'should pass txId')
|
|
|
|
done()
|
|
|
|
})
|
2017-08-09 00:30:22 +02:00
|
|
|
pendingTxTracker._checkPendingTx(txMetaNoHash)
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
|
|
|
|
2019-12-05 20:34:10 +01:00
|
|
|
it('should emit tx:dropped with the txMetas id only after the fourth call', function (done) {
|
2019-07-31 22:17:11 +02:00
|
|
|
txMeta = {
|
|
|
|
id: 1,
|
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
|
|
|
status: 'submitted',
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
}
|
2019-05-16 07:36:53 +02:00
|
|
|
|
2019-12-05 20:34:10 +01:00
|
|
|
let counter = 0
|
2019-05-16 07:36:53 +02:00
|
|
|
providerResultStub['eth_getTransactionCount'] = '0x02'
|
2019-12-05 20:34:10 +01:00
|
|
|
providerResultStub['eth_getTransactionReceipt'] = {}
|
2019-05-16 07:36:53 +02:00
|
|
|
pendingTxTracker.once('tx:dropped', (id) => {
|
|
|
|
if (id === txMeta.id) {
|
|
|
|
delete providerResultStub['eth_getTransactionCount']
|
2019-12-05 20:34:10 +01:00
|
|
|
delete providerResultStub['eth_getTransactionReceipt']
|
|
|
|
if (counter === 3) {
|
|
|
|
return done()
|
|
|
|
} else {
|
|
|
|
return done(new Error(`Counter does not equal 3 got ${counter} instead`))
|
|
|
|
}
|
2019-05-16 07:36:53 +02:00
|
|
|
} else {
|
|
|
|
done(new Error('wrong tx Id'))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
pendingTxTracker._checkPendingTx(txMeta).then(() => {
|
2019-12-05 20:34:10 +01:00
|
|
|
++counter
|
|
|
|
pendingTxTracker._checkPendingTx(txMeta).then(() => {
|
|
|
|
++counter
|
|
|
|
pendingTxTracker._checkPendingTx(txMeta).then(() => {
|
|
|
|
++counter
|
|
|
|
pendingTxTracker._checkPendingTx(txMeta)
|
|
|
|
})
|
|
|
|
})
|
2019-05-16 07:36:53 +02:00
|
|
|
}).catch(done)
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2017-08-04 20:40:22 +02:00
|
|
|
it('should should return if query does not return txParams', function () {
|
2017-08-09 00:30:22 +02:00
|
|
|
providerResultStub.eth_getTransactionByHash = null
|
|
|
|
pendingTxTracker._checkPendingTx(txMeta)
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#_checkPendingTxs', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
const txMeta2 = txMeta3 = txMeta
|
|
|
|
txMeta2.id = 2
|
|
|
|
txMeta3.id = 3
|
|
|
|
txList = [txMeta, txMeta2, txMeta3].map((tx) => {
|
2019-11-20 01:03:20 +01:00
|
|
|
tx.processed = new Promise((resolve) => {
|
|
|
|
tx.resolve = resolve
|
|
|
|
})
|
2017-08-04 20:40:22 +02:00
|
|
|
return tx
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-05-29 01:00:35 +02:00
|
|
|
it('should warp all txMeta\'s in #updatePendingTxs', function (done) {
|
2017-08-09 00:30:22 +02:00
|
|
|
pendingTxTracker.getPendingTransactions = () => txList
|
2019-11-20 01:03:20 +01:00
|
|
|
pendingTxTracker._checkPendingTx = (tx) => {
|
|
|
|
tx.resolve(tx)
|
|
|
|
}
|
2017-08-04 20:40:22 +02:00
|
|
|
Promise.all(txList.map((tx) => tx.processed))
|
2019-07-31 22:17:11 +02:00
|
|
|
.then(() => done())
|
|
|
|
.catch(done)
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2018-05-29 01:00:35 +02:00
|
|
|
pendingTxTracker.updatePendingTxs()
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#resubmitPendingTxs', function () {
|
2018-07-03 21:42:14 +02:00
|
|
|
const blockNumberStub = '0x0'
|
2017-08-04 20:40:22 +02:00
|
|
|
beforeEach(function () {
|
2019-07-31 22:17:11 +02:00
|
|
|
const txMeta2 = txMeta3 = txMeta
|
|
|
|
txList = [txMeta, txMeta2, txMeta3].map((tx) => {
|
2019-11-20 01:03:20 +01:00
|
|
|
tx.processed = new Promise((resolve) => {
|
|
|
|
tx.resolve = resolve
|
|
|
|
})
|
2017-08-04 20:40:22 +02:00
|
|
|
return tx
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return if no pending transactions', function () {
|
2017-08-09 00:30:22 +02:00
|
|
|
pendingTxTracker.resubmitPendingTxs()
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
|
|
|
it('should call #_resubmitTx for all pending tx\'s', function (done) {
|
2017-08-09 00:30:22 +02:00
|
|
|
pendingTxTracker.getPendingTransactions = () => txList
|
2019-11-20 01:03:20 +01:00
|
|
|
pendingTxTracker._resubmitTx = async (tx) => {
|
|
|
|
tx.resolve(tx)
|
|
|
|
}
|
2017-08-04 20:40:22 +02:00
|
|
|
Promise.all(txList.map((tx) => tx.processed))
|
2019-07-31 22:17:11 +02:00
|
|
|
.then(() => done())
|
|
|
|
.catch(done)
|
2018-07-03 21:42:14 +02:00
|
|
|
pendingTxTracker.resubmitPendingTxs(blockNumberStub)
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
2017-10-03 00:14:15 +02:00
|
|
|
it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) {
|
2018-05-28 23:29:31 +02:00
|
|
|
knownErrors = [
|
2017-08-04 20:40:22 +02:00
|
|
|
// geth
|
|
|
|
' Replacement transaction Underpriced ',
|
|
|
|
' known transaction',
|
|
|
|
// parity
|
|
|
|
'Gas price too low to replace ',
|
|
|
|
' transaction with the sAme hash was already imported',
|
|
|
|
// other
|
|
|
|
' gateway timeout',
|
|
|
|
' noncE too low ',
|
|
|
|
]
|
|
|
|
const enoughForAllErrors = txList.concat(txList)
|
|
|
|
|
2017-09-27 01:55:11 +02:00
|
|
|
pendingTxTracker.on('tx:failed', (_, err) => done(err))
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2017-08-09 00:30:22 +02:00
|
|
|
pendingTxTracker.getPendingTransactions = () => enoughForAllErrors
|
|
|
|
pendingTxTracker._resubmitTx = async (tx) => {
|
2017-08-04 20:40:22 +02:00
|
|
|
tx.resolve()
|
|
|
|
throw new Error(knownErrors.pop())
|
|
|
|
}
|
|
|
|
Promise.all(txList.map((tx) => tx.processed))
|
2019-07-31 22:17:11 +02:00
|
|
|
.then(() => done())
|
|
|
|
.catch(done)
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2018-07-03 21:42:14 +02:00
|
|
|
pendingTxTracker.resubmitPendingTxs(blockNumberStub)
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
2017-10-03 00:20:18 +02:00
|
|
|
it('should emit \'tx:warning\' if it encountered a real error', function (done) {
|
|
|
|
pendingTxTracker.once('tx:warning', (txMeta, err) => {
|
|
|
|
if (err.message === 'im some real error') {
|
|
|
|
const matchingTx = txList.find(tx => tx.id === txMeta.id)
|
|
|
|
matchingTx.resolve()
|
|
|
|
} else {
|
|
|
|
done(err)
|
|
|
|
}
|
|
|
|
})
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2017-08-09 00:30:22 +02:00
|
|
|
pendingTxTracker.getPendingTransactions = () => txList
|
2019-11-20 01:03:20 +01:00
|
|
|
pendingTxTracker._resubmitTx = async () => {
|
|
|
|
throw new TypeError('im some real error')
|
|
|
|
}
|
2017-08-04 20:40:22 +02:00
|
|
|
Promise.all(txList.map((tx) => tx.processed))
|
2019-07-31 22:17:11 +02:00
|
|
|
.then(() => done())
|
|
|
|
.catch(done)
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2018-07-03 21:42:14 +02:00
|
|
|
pendingTxTracker.resubmitPendingTxs(blockNumberStub)
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
|
|
|
})
|
2017-09-29 21:54:05 +02:00
|
|
|
describe('#_resubmitTx', function () {
|
2017-12-06 18:41:14 +01:00
|
|
|
const mockFirstRetryBlockNumber = '0x1'
|
2018-07-03 02:12:50 +02:00
|
|
|
let txMetaToTestExponentialBackoff, enoughBalance
|
2017-12-06 18:41:14 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
pendingTxTracker.getBalance = (address) => {
|
|
|
|
assert.equal(address, txMeta.txParams.from, 'Should pass the address')
|
|
|
|
return enoughBalance
|
|
|
|
}
|
|
|
|
pendingTxTracker.publishTransaction = async (rawTx) => {
|
|
|
|
assert.equal(rawTx, txMeta.rawTx, 'Should pass the rawTx')
|
|
|
|
}
|
2018-11-14 22:34:07 +01:00
|
|
|
pendingTxTracker.approveTransaction = async () => {}
|
2017-12-06 18:41:14 +01:00
|
|
|
sinon.spy(pendingTxTracker, 'publishTransaction')
|
|
|
|
|
|
|
|
txMetaToTestExponentialBackoff = Object.assign({}, txMeta, {
|
|
|
|
retryCount: 4,
|
|
|
|
firstRetryBlockNumber: mockFirstRetryBlockNumber,
|
|
|
|
})
|
|
|
|
})
|
2017-08-04 20:40:22 +02:00
|
|
|
|
2017-12-06 18:41:14 +01:00
|
|
|
afterEach(() => {
|
2018-04-04 23:26:18 +02:00
|
|
|
pendingTxTracker.publishTransaction.restore()
|
2017-12-06 18:41:14 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should publish the transaction', function (done) {
|
2018-07-03 02:12:50 +02:00
|
|
|
enoughBalance = '0x100000'
|
2017-12-06 18:41:14 +01:00
|
|
|
|
|
|
|
// Stubbing out current account state:
|
|
|
|
// Adding the fake tx:
|
|
|
|
pendingTxTracker._resubmitTx(txMeta)
|
2019-07-31 22:17:11 +02:00
|
|
|
.then(() => done())
|
|
|
|
.catch((err) => {
|
|
|
|
assert.ifError(err, 'should not throw an error')
|
|
|
|
done(err)
|
|
|
|
})
|
2017-12-06 18:41:14 +01:00
|
|
|
|
|
|
|
assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not publish the transaction if the limit of retries has been exceeded', function (done) {
|
2018-07-03 02:12:50 +02:00
|
|
|
enoughBalance = '0x100000'
|
2017-12-06 18:41:14 +01:00
|
|
|
const mockLatestBlockNumber = '0x5'
|
|
|
|
|
|
|
|
pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
|
2019-07-31 22:17:11 +02:00
|
|
|
.then(() => done())
|
|
|
|
.catch((err) => {
|
|
|
|
assert.ifError(err, 'should not throw an error')
|
|
|
|
done(err)
|
|
|
|
})
|
2017-12-06 18:41:14 +01:00
|
|
|
|
|
|
|
assert.equal(pendingTxTracker.publishTransaction.callCount, 0, 'Should NOT call publish transaction')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should publish the transaction if the number of blocks since last retry exceeds the last set limit', function (done) {
|
2018-07-03 02:12:50 +02:00
|
|
|
enoughBalance = '0x100000'
|
2017-12-06 18:41:14 +01:00
|
|
|
const mockLatestBlockNumber = '0x11'
|
2017-12-28 02:45:03 +01:00
|
|
|
|
2017-12-06 18:41:14 +01:00
|
|
|
pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
|
2019-07-31 22:17:11 +02:00
|
|
|
.then(() => done())
|
|
|
|
.catch((err) => {
|
|
|
|
assert.ifError(err, 'should not throw an error')
|
|
|
|
done(err)
|
|
|
|
})
|
2017-12-06 18:41:14 +01:00
|
|
|
|
|
|
|
assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction')
|
2017-08-04 20:40:22 +02:00
|
|
|
})
|
2018-11-14 22:34:07 +01:00
|
|
|
|
|
|
|
it('should call opts.approveTransaction with the id if the tx is not signed', async () => {
|
|
|
|
const stubTx = {
|
|
|
|
id: 40,
|
|
|
|
}
|
|
|
|
const approveMock = sinon.stub(pendingTxTracker, 'approveTransaction')
|
|
|
|
|
|
|
|
pendingTxTracker._resubmitTx(stubTx)
|
|
|
|
|
|
|
|
assert.ok(approveMock.called)
|
|
|
|
approveMock.restore()
|
|
|
|
})
|
2017-12-28 02:45:03 +01:00
|
|
|
})
|
|
|
|
|
2019-05-16 07:36:53 +02:00
|
|
|
describe('#_checkIftxWasDropped', () => {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
|
|
|
status: 'submitted',
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
}
|
|
|
|
it('should return false when the nonce is the suggested network nonce', (done) => {
|
|
|
|
providerResultStub['eth_getTransactionCount'] = '0x01'
|
2019-12-05 20:34:10 +01:00
|
|
|
providerResultStub['eth_getTransactionReceipt'] = {}
|
|
|
|
pendingTxTracker._checkIftxWasDropped(txMeta, {}).then((dropped) => {
|
2019-05-16 07:36:53 +02:00
|
|
|
assert(!dropped, 'should be false')
|
|
|
|
done()
|
|
|
|
}).catch(done)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return true when the network nonce is higher then the txMeta nonce', function (done) {
|
|
|
|
providerResultStub['eth_getTransactionCount'] = '0x02'
|
2019-12-05 20:34:10 +01:00
|
|
|
providerResultStub['eth_getTransactionReceipt'] = {}
|
|
|
|
pendingTxTracker._checkIftxWasDropped(txMeta, {}).then((dropped) => {
|
2019-05-16 07:36:53 +02:00
|
|
|
assert(dropped, 'should be true')
|
|
|
|
done()
|
|
|
|
}).catch(done)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-12-28 02:45:03 +01:00
|
|
|
describe('#_checkIfNonceIsTaken', function () {
|
2018-05-25 08:19:54 +02:00
|
|
|
beforeEach(function () {
|
2018-07-03 00:49:33 +02:00
|
|
|
const confirmedTxList = [{
|
2017-12-28 02:45:03 +01:00
|
|
|
id: 1,
|
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
|
|
|
status: 'confirmed',
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
|
|
|
status: 'confirmed',
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x2',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
}]
|
|
|
|
pendingTxTracker.getCompletedTransactions = (address) => {
|
2019-11-20 01:03:20 +01:00
|
|
|
if (!address) {
|
|
|
|
throw new Error('unless behavior has changed #_checkIfNonceIsTaken needs a filtered list of transactions to see if the nonce is taken')
|
|
|
|
}
|
2017-12-28 02:45:03 +01:00
|
|
|
return confirmedTxList
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-12-29 00:48:22 +01:00
|
|
|
it('should return false if nonce has not been taken', function (done) {
|
2017-12-28 02:45:03 +01:00
|
|
|
pendingTxTracker._checkIfNonceIsTaken({
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x3',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
})
|
2019-07-31 22:17:11 +02:00
|
|
|
.then((taken) => {
|
|
|
|
assert.ok(!taken)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
.catch(done)
|
2017-12-28 02:45:03 +01:00
|
|
|
})
|
|
|
|
|
2017-12-29 00:48:22 +01:00
|
|
|
it('should return true if nonce has been taken', function (done) {
|
2017-12-28 02:45:03 +01:00
|
|
|
pendingTxTracker._checkIfNonceIsTaken({
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x2',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
}).then((taken) => {
|
|
|
|
assert.ok(taken)
|
|
|
|
done()
|
|
|
|
})
|
2019-07-31 22:17:11 +02:00
|
|
|
.catch(done)
|
2017-12-28 02:45:03 +01:00
|
|
|
})
|
|
|
|
})
|
2017-10-06 21:29:27 +02:00
|
|
|
})
|