2021-02-04 19:15:23 +01:00
|
|
|
import { strict as assert } from 'assert';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import BN from 'bn.js';
|
2021-03-16 22:00:08 +01:00
|
|
|
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
|
|
|
|
import PendingTransactionTracker from './pending-tx-tracker';
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
describe('PendingTransactionTracker', function () {
|
|
|
|
describe('#resubmitPendingTxs', function () {
|
|
|
|
it('should return early if there are no pending transactions', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const getPendingTransactions = sinon.stub().returns([]);
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions,
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
approveTransaction: sinon.spy(),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
const resubmitTx = sinon.stub(pendingTxTracker, '_resubmitTx').rejects();
|
|
|
|
const warningListener = sinon.spy();
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.on('tx:warning', warningListener);
|
|
|
|
await pendingTxTracker.resubmitPendingTxs('0x1');
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
getPendingTransactions.calledOnceWithExactly(),
|
|
|
|
'should call getPendingTransaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok(resubmitTx.notCalled, 'should NOT call _resubmitTx');
|
|
|
|
assert.ok(warningListener.notCalled, "should NOT emit 'tx:warning'");
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it('should resubmit each pending transaction', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const getPendingTransactions = sinon.stub().returns([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions,
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
approveTransaction: sinon.spy(),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
const resubmitTx = sinon.stub(pendingTxTracker, '_resubmitTx').resolves();
|
|
|
|
const warningListener = sinon.spy();
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.on('tx:warning', warningListener);
|
|
|
|
await pendingTxTracker.resubmitPendingTxs('0x1');
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
getPendingTransactions.calledOnceWithExactly(),
|
|
|
|
'should call getPendingTransaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok(resubmitTx.calledTwice, 'should call _resubmitTx');
|
|
|
|
assert.ok(warningListener.notCalled, "should NOT emit 'tx:warning'");
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it("should NOT emit 'tx:warning' for known failed resubmission", async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const getPendingTransactions = sinon.stub().returns([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions,
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
approveTransaction: sinon.spy(),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
const resubmitTx = sinon
|
|
|
|
.stub(pendingTxTracker, '_resubmitTx')
|
2021-02-04 19:15:23 +01:00
|
|
|
.rejects({ message: 'known transaction' });
|
|
|
|
const warningListener = sinon.spy();
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.on('tx:warning', warningListener);
|
|
|
|
await pendingTxTracker.resubmitPendingTxs('0x1');
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
getPendingTransactions.calledOnceWithExactly(),
|
|
|
|
'should call getPendingTransaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok(resubmitTx.calledOnce, 'should call _resubmitTx');
|
|
|
|
assert.ok(warningListener.notCalled, "should NOT emit 'tx:warning'");
|
|
|
|
});
|
2020-04-27 17:54:39 +02:00
|
|
|
|
|
|
|
it("should emit 'tx:warning' for unknown failed resubmission", async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const getPendingTransactions = sinon.stub().returns([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2020-04-27 17:54:39 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions,
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
approveTransaction: sinon.spy(),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
const resubmitTx = sinon
|
|
|
|
.stub(pendingTxTracker, '_resubmitTx')
|
2021-02-04 19:15:23 +01:00
|
|
|
.rejects({ message: 'who dis' });
|
|
|
|
const warningListener = sinon.spy();
|
2020-04-27 17:54:39 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.on('tx:warning', warningListener);
|
|
|
|
await pendingTxTracker.resubmitPendingTxs('0x1');
|
2020-04-27 17:54:39 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
getPendingTransactions.calledOnceWithExactly(),
|
|
|
|
'should call getPendingTransaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok(resubmitTx.calledOnce, 'should call _resubmitTx');
|
|
|
|
assert.ok(warningListener.calledOnce, "should emit 'tx:warning'");
|
|
|
|
});
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
describe('#updatePendingTxs', function () {
|
|
|
|
it('should call _checkPendingTx for each pending transaction', async function () {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SIGNED,
|
2020-04-23 17:49:04 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
history: [{}],
|
2020-11-03 00:41:28 +01:00
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const txList = [1, 2, 3].map((id) => ({ ...txMeta, id }));
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return { releaseLock: () => undefined };
|
2020-04-23 17:49:04 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
getPendingTransactions: () => txList,
|
|
|
|
getCompletedTransactions: () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return [];
|
2020-04-23 17:49:04 +02:00
|
|
|
},
|
2020-08-14 13:47:02 +02:00
|
|
|
publishTransaction: () => undefined,
|
|
|
|
confirmTransaction: () => undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const checkPendingTxStub = sinon
|
|
|
|
.stub(pendingTxTracker, '_checkPendingTx')
|
2021-02-04 19:15:23 +01:00
|
|
|
.resolves();
|
|
|
|
await pendingTxTracker.updatePendingTxs();
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(checkPendingTxStub.calledThrice);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
checkPendingTxStub.firstCall.calledWithExactly(
|
|
|
|
sinon.match.has('id', 1),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
checkPendingTxStub.secondCall.calledWithExactly(
|
|
|
|
sinon.match.has('id', 2),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
checkPendingTxStub.thirdCall.calledWithExactly(
|
|
|
|
sinon.match.has('id', 3),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
describe('#_resubmitTx', function () {
|
|
|
|
it('should publish a new transaction', async function () {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SIGNED,
|
2020-04-23 17:49:04 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
history: [{}],
|
2020-11-03 00:41:28 +01:00
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a817c80086a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const approveTransaction = sinon.spy();
|
|
|
|
const publishTransaction = sinon.spy();
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
approveTransaction,
|
|
|
|
publishTransaction,
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await pendingTxTracker._resubmitTx(txMeta);
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
publishTransaction.calledOnceWithExactly(txMeta.rawTx),
|
|
|
|
'should call publish transaction with the rawTx',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
approveTransaction.notCalled,
|
|
|
|
'should NOT try to approve transaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it('should publish the given transaction if more than 2**retryCount blocks have passed', async function () {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SIGNED,
|
2020-04-23 17:49:04 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
history: [{}],
|
2020-11-03 00:41:28 +01:00
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a817c800827b0d940c62bb85faa3311a996e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
2020-04-23 17:49:04 +02:00
|
|
|
retryCount: 4,
|
|
|
|
firstRetryBlockNumber: '0x1',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const approveTransaction = sinon.spy();
|
|
|
|
const publishTransaction = sinon.spy();
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction,
|
|
|
|
approveTransaction,
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await pendingTxTracker._resubmitTx(txMeta, '0x11' /* 16 */);
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
publishTransaction.calledOnceWithExactly(txMeta.rawTx),
|
|
|
|
'should try to publish transaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
approveTransaction.notCalled,
|
|
|
|
'should NOT try to approve transaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it('should NOT publish the given transaction if fewer than 2**retryCount blocks have passed', async function () {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SIGNED,
|
2020-04-23 17:49:04 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
history: [{}],
|
2020-11-03 00:41:28 +01:00
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a817c800827b0d940c62bb85faa3311a996e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
2020-04-23 17:49:04 +02:00
|
|
|
retryCount: 4,
|
|
|
|
firstRetryBlockNumber: '0x1',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const approveTransaction = sinon.spy();
|
|
|
|
const publishTransaction = sinon.spy();
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction,
|
|
|
|
approveTransaction,
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await pendingTxTracker._resubmitTx(txMeta, '0x5');
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
publishTransaction.notCalled,
|
|
|
|
'should NOT try to publish transaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
approveTransaction.notCalled,
|
|
|
|
'should NOT try to approve transaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it('should call approveTransaction if the tx is not yet signed', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const approveTransaction = sinon.spy();
|
|
|
|
const publishTransaction = sinon.spy();
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
approveTransaction,
|
|
|
|
publishTransaction,
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await pendingTxTracker._resubmitTx({ id: 40 });
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
approveTransaction.calledOnceWithExactly(40),
|
|
|
|
'should call approveTransaction with the tx ID',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
publishTransaction.notCalled,
|
|
|
|
'should NOT try to publish transaction',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
describe('#_checkIfTxWasDropped', function () {
|
|
|
|
it('should return true when the given nonce is lower than the network nonce', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const nonceBN = new BN(2);
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
2020-06-17 23:13:33 +02:00
|
|
|
getTransactionCount: sinon.stub().resolves(nonceBN),
|
2020-04-23 17:49:04 +02:00
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.DROPPED_BUFFER_COUNT = 0;
|
2020-05-01 19:49:29 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
await pendingTxTracker._checkIfTxWasDropped({
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2020-11-03 00:41:28 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx: '0xf86c808504a817c800827b0d940c62bba0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it('should return false when the given nonce is the network nonce', async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const nonceBN = new BN(1);
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub(),
|
2020-06-17 23:13:33 +02:00
|
|
|
getTransactionCount: sinon.stub().resolves(nonceBN),
|
2020-04-23 17:49:04 +02:00
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
const dropped = await pendingTxTracker._checkIfTxWasDropped({
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2020-04-23 17:49:04 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a89e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(!dropped, 'should be false');
|
|
|
|
});
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
describe('#_checkIfNonceIsTaken', function () {
|
|
|
|
it('should return false if the given nonce is not taken', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const confirmedTxList = [
|
|
|
|
{
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-11-03 00:41:28 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a817c800827b0d940c62bb85fa3320e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-11-03 00:41:28 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x2',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx:
|
|
|
|
'0xf86c808507a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
2020-04-23 17:49:04 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
|
|
|
const getCompletedTransactions = sinon.stub().returns(confirmedTxList);
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: sinon.spy(),
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions,
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
const taken = await pendingTxTracker._checkIfNonceIsTaken({
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x3',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
getCompletedTransactions.calledOnceWithExactly(
|
|
|
|
'0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok(!taken);
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it('should return true if the nonce is taken', async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const confirmedTxList = [
|
|
|
|
{
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-11-03 00:41:28 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a817c80082ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-11-03 00:41:28 +01:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x2',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
rawTx:
|
|
|
|
'0xf86c808504a817c800827b0d940c62bb760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
|
2020-04-23 17:49:04 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
|
|
|
const getCompletedTransactions = sinon.stub().returns(confirmedTxList);
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: sinon.spy(),
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions,
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
const taken = await pendingTxTracker._checkIfNonceIsTaken({
|
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x2',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
getCompletedTransactions.calledOnceWithExactly(
|
|
|
|
'0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok(taken);
|
|
|
|
});
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
describe('#_checkPendingTx', function () {
|
2020-05-01 19:49:29 +02:00
|
|
|
it("should emit 'tx:warning' if getTransactionReceipt rejects", async function () {
|
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2020-05-01 19:49:29 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
rawTx: '0xf86c808504a817c80082471d',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const nonceBN = new BN(2);
|
2020-05-01 19:49:29 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub().rejects(),
|
2020-06-17 23:13:33 +02:00
|
|
|
getTransactionCount: sinon.stub().resolves(nonceBN),
|
2020-05-01 19:49:29 +02:00
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-01 19:49:29 +02:00
|
|
|
const listeners = {
|
|
|
|
confirmed: sinon.spy(),
|
|
|
|
dropped: sinon.spy(),
|
|
|
|
failed: sinon.spy(),
|
|
|
|
warning: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-01 19:49:29 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.once('tx:confirmed', listeners.confirmed);
|
|
|
|
pendingTxTracker.once('tx:dropped', listeners.dropped);
|
|
|
|
pendingTxTracker.once('tx:failed', listeners.failed);
|
|
|
|
pendingTxTracker.once('tx:warning', listeners.warning);
|
|
|
|
await pendingTxTracker._checkPendingTx(txMeta);
|
2020-05-01 19:49:29 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(listeners.dropped.notCalled, "should not emit 'tx:dropped");
|
|
|
|
assert.ok(
|
|
|
|
listeners.confirmed.notCalled,
|
|
|
|
"should not emit 'tx:confirmed'",
|
|
|
|
);
|
|
|
|
assert.ok(listeners.failed.notCalled, "should not emit 'tx:failed'");
|
|
|
|
assert.ok(listeners.warning.calledOnce, "should emit 'tx:warning'");
|
|
|
|
});
|
2020-05-01 19:49:29 +02:00
|
|
|
|
2020-04-23 17:49:04 +02:00
|
|
|
it('should NOT emit anything if the tx is already not submitted', async function () {
|
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: sinon.spy(),
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
const listeners = {
|
|
|
|
confirmed: sinon.spy(),
|
|
|
|
dropped: sinon.spy(),
|
|
|
|
failed: sinon.spy(),
|
2020-05-01 19:49:29 +02:00
|
|
|
warning: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.once('tx:confirmed', listeners.confirmed);
|
|
|
|
pendingTxTracker.once('tx:dropped', listeners.dropped);
|
|
|
|
pendingTxTracker.once('tx:failed', listeners.failed);
|
|
|
|
pendingTxTracker.once('tx:warning', listeners.warning);
|
2020-04-23 17:49:04 +02:00
|
|
|
await pendingTxTracker._checkPendingTx({
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
txParams: { nonce: '0x1' },
|
|
|
|
id: '456',
|
|
|
|
value: '0x01',
|
|
|
|
hash: '0xbad',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(listeners.failed.notCalled, "should not emit 'tx:failed'");
|
|
|
|
assert.ok(
|
|
|
|
listeners.confirmed.notCalled,
|
|
|
|
"should not emit 'tx:confirmed'",
|
|
|
|
);
|
|
|
|
assert.ok(listeners.dropped.notCalled, "should not emit 'tx:dropped'");
|
|
|
|
assert.ok(listeners.warning.notCalled, "should not emit 'tx:warning'");
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it("should emit 'tx:failed' if the txMeta does NOT have a hash", async function () {
|
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: sinon.spy(),
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
const listeners = {
|
|
|
|
confirmed: sinon.spy(),
|
|
|
|
dropped: sinon.spy(),
|
|
|
|
failed: sinon.spy(),
|
2020-05-01 19:49:29 +02:00
|
|
|
warning: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.once('tx:confirmed', listeners.confirmed);
|
|
|
|
pendingTxTracker.once('tx:dropped', listeners.dropped);
|
|
|
|
pendingTxTracker.once('tx:failed', listeners.failed);
|
|
|
|
pendingTxTracker.once('tx:warning', listeners.warning);
|
2020-04-23 17:49:04 +02:00
|
|
|
await pendingTxTracker._checkPendingTx({
|
|
|
|
id: '2',
|
|
|
|
history: [{}],
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2020-04-23 17:49:04 +02:00
|
|
|
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
listeners.failed.calledOnceWithExactly(
|
|
|
|
'2',
|
|
|
|
sinon.match.instanceOf(Error),
|
|
|
|
),
|
|
|
|
"should pass txId to 'tx:failed' listener",
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
listeners.confirmed.notCalled,
|
|
|
|
"should not emit 'tx:confirmed'",
|
|
|
|
);
|
|
|
|
assert.ok(listeners.dropped.notCalled, "should not emit 'tx:dropped'");
|
|
|
|
assert.ok(listeners.warning.notCalled, "should not emit 'tx:warning'");
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it("should emit 'tx:dropped' if another tx with the same nonce succeeds", async function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const txs = [
|
|
|
|
{
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.CONFIRMED,
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
txParams: { nonce: '0x1' },
|
|
|
|
id: '456',
|
|
|
|
value: '0x01',
|
|
|
|
hash: '0xbad',
|
|
|
|
},
|
|
|
|
{
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2020-11-03 00:41:28 +01:00
|
|
|
history: [{}],
|
|
|
|
txParams: { nonce: '0x1' },
|
|
|
|
id: '123',
|
|
|
|
value: '0x02',
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x2a919d2512ec963f524bfd9730fb66b6d5a2e399d1dd957abb5e2b544a12644b',
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
2020-05-01 19:49:29 +02:00
|
|
|
query: {
|
|
|
|
getTransactionReceipt: sinon.stub().resolves(null),
|
|
|
|
},
|
2020-04-23 17:49:04 +02:00
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns(txs),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
const listeners = {
|
|
|
|
confirmed: sinon.spy(),
|
|
|
|
dropped: sinon.spy(),
|
|
|
|
failed: sinon.spy(),
|
2020-05-01 19:49:29 +02:00
|
|
|
warning: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
pendingTxTracker.once('tx:confirmed', listeners.confirmed);
|
|
|
|
pendingTxTracker.once('tx:dropped', listeners.dropped);
|
|
|
|
pendingTxTracker.once('tx:failed', listeners.failed);
|
|
|
|
pendingTxTracker.once('tx:warning', listeners.warning);
|
|
|
|
await pendingTxTracker._checkPendingTx(txs[1]);
|
2020-04-23 17:49:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.ok(listeners.dropped.calledOnceWithExactly('123'));
|
|
|
|
assert.ok(
|
|
|
|
listeners.confirmed.notCalled,
|
|
|
|
"should not emit 'tx:confirmed'",
|
|
|
|
);
|
|
|
|
assert.ok(listeners.failed.notCalled, "should not emit 'tx:failed'");
|
|
|
|
assert.ok(listeners.warning.notCalled, "should not emit 'tx:warning'");
|
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
|
|
|
|
it("should emit 'tx:dropped' with the txMetas id only after the fourth call", async function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const nonceBN = new BN(2);
|
2020-04-23 17:49:04 +02:00
|
|
|
const txMeta = {
|
|
|
|
id: 1,
|
2022-07-31 20:26:40 +02:00
|
|
|
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.SUBMITTED,
|
2020-04-23 17:49:04 +02:00
|
|
|
txParams: {
|
|
|
|
from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
|
|
|
nonce: '0x1',
|
|
|
|
value: '0xfffff',
|
|
|
|
},
|
|
|
|
history: [{}],
|
|
|
|
rawTx: '0xf86c808504a817c80082471d',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-04-23 17:49:04 +02:00
|
|
|
const pendingTxTracker = new PendingTransactionTracker({
|
|
|
|
query: {
|
2020-05-01 19:49:29 +02:00
|
|
|
getTransactionReceipt: sinon.stub().resolves(null),
|
2020-06-17 23:13:33 +02:00
|
|
|
getTransactionCount: sinon.stub().resolves(nonceBN),
|
2020-04-23 17:49:04 +02:00
|
|
|
},
|
|
|
|
nonceTracker: {
|
|
|
|
getGlobalLock: sinon.stub().resolves({
|
|
|
|
releaseLock: sinon.spy(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
getPendingTransactions: sinon.stub().returns([]),
|
|
|
|
getCompletedTransactions: sinon.stub().returns([]),
|
|
|
|
publishTransaction: sinon.spy(),
|
|
|
|
confirmTransaction: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-04-23 17:49:04 +02:00
|
|
|
const listeners = {
|
|
|
|
confirmed: sinon.spy(),
|
|
|
|
dropped: sinon.spy(),
|
|
|
|
failed: sinon.spy(),
|
2020-05-01 19:49:29 +02:00
|
|
|
warning: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pendingTxTracker.once('tx:confirmed', listeners.confirmed);
|
|
|
|
pendingTxTracker.once('tx:dropped', listeners.dropped);
|
|
|
|
pendingTxTracker.once('tx:failed', listeners.failed);
|
|
|
|
pendingTxTracker.once('tx:warning', listeners.warning);
|
|
|
|
await pendingTxTracker._checkPendingTx(txMeta);
|
|
|
|
await pendingTxTracker._checkPendingTx(txMeta);
|
|
|
|
await pendingTxTracker._checkPendingTx(txMeta);
|
|
|
|
await pendingTxTracker._checkPendingTx(txMeta);
|
|
|
|
|
|
|
|
assert.ok(listeners.dropped.calledOnceWithExactly(1));
|
|
|
|
assert.ok(
|
|
|
|
listeners.confirmed.notCalled,
|
|
|
|
"should not emit 'tx:confirmed'",
|
|
|
|
);
|
|
|
|
assert.ok(listeners.failed.notCalled, "should not emit 'tx:failed'");
|
|
|
|
assert.ok(listeners.warning.notCalled, "should not emit 'tx:warning'");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|