Skip to content

Commit

Permalink
test: fix transaction controller integration tests with nonce tracker…
Browse files Browse the repository at this point in the history
… 6 (#4591)
  • Loading branch information
matthewwalsh0 authored Aug 12, 2024
1 parent 128282f commit 5318618
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@metamask/controller-utils": "^11.0.2",
"@metamask/eth-query": "^4.0.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/nonce-tracker": "^5.0.0",
"@metamask/nonce-tracker": "^6.0.0",
"@metamask/rpc-errors": "^6.3.1",
"@metamask/utils": "^9.1.0",
"async-mutex": "^0.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3405,7 +3405,7 @@ export class TransactionController extends BaseController<
// TODO: Fix types
// eslint-disable-next-line @typescript-eslint/no-explicit-any
provider: provider as any,
// @ts-expect-error TODO: Fix types
// TODO: Fix types
blockTracker,
getPendingTransactions: this.#getNonceTrackerPendingTransactions.bind(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
import type {
TransactionControllerActions,
TransactionControllerEvents,
TransactionControllerOptions,
} from './TransactionController';
import { TransactionController } from './TransactionController';
import type { TransactionMeta } from './types';
Expand Down Expand Up @@ -113,7 +114,7 @@ const ACCOUNT_2_MOCK = '0x08f137f335ea1b8f193b8f6ea92561a60d23a211';
const ACCOUNT_3_MOCK = '0xe688b84b23f322a994a53dbf8e15fa82cdb71127';
const infuraProjectId = 'fake-infura-project-id';

const BLOCK_TRACKER_POLLING_INTERVAL = 20000;
const BLOCK_TRACKER_POLLING_INTERVAL = 30000;

/**
* Builds the Infura network client configuration.
Expand Down Expand Up @@ -209,7 +210,7 @@ const setupController = async (
mockGetSelectedAccount,
);

const options = {
const options: TransactionControllerOptions = {
blockTracker,
disableHistory: false,
disableSendFlowHistory: false,
Expand All @@ -232,6 +233,9 @@ const setupController = async (
onNetworkStateChange: () => {
// noop
},
pendingTransactions: {
isResubmitEnabled: () => false,
},
provider,
sign: async (transaction: TypedTransaction) => transaction,
transactionHistoryLimit: 40,
Expand Down Expand Up @@ -267,7 +271,7 @@ describe('TransactionController Integration', () => {
});

// eslint-disable-next-line jest/no-disabled-tests
it.skip('should submit all approved transactions in state', async () => {
it('should submit all approved transactions in state', async () => {
mockNetwork({
networkClientConfiguration: buildInfuraNetworkClientConfiguration(
InfuraNetworkType.goerli,
Expand Down Expand Up @@ -371,6 +375,8 @@ describe('TransactionController Integration', () => {
],
},
});

await advanceTime({ clock, duration: 1 });
await advanceTime({ clock, duration: 1 });

expect(transactionController.state.transactions).toMatchObject([
Expand Down Expand Up @@ -806,7 +812,7 @@ describe('TransactionController Integration', () => {

describe('when transactions are added concurrently with different networkClientIds but on the same chainId', () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should add each transaction with consecutive nonces', async () => {
it('should add each transaction with consecutive nonces', async () => {
mockNetwork({
networkClientConfiguration: buildInfuraNetworkClientConfiguration(
InfuraNetworkType.goerli,
Expand Down Expand Up @@ -903,6 +909,7 @@ describe('TransactionController Integration', () => {
approvalController.accept(addTx2.transactionMeta.id),
]);
await advanceTime({ clock, duration: 1 });
await advanceTime({ clock, duration: 1 });

await Promise.all([addTx1.result, addTx2.result]);

Expand All @@ -916,7 +923,7 @@ describe('TransactionController Integration', () => {

describe('when transactions are added concurrently with the same networkClientId', () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should add each transaction with consecutive nonces', async () => {
it('should add each transaction with consecutive nonces', async () => {
mockNetwork({
networkClientConfiguration: buildInfuraNetworkClientConfiguration(
InfuraNetworkType.goerli,
Expand All @@ -929,6 +936,7 @@ describe('TransactionController Integration', () => {
buildEthEstimateGasRequestMock(ACCOUNT_MOCK, ACCOUNT_2_MOCK),
buildEthGasPriceRequestMock(),
buildEthGetTransactionCountRequestMock(ACCOUNT_MOCK),
buildEthGetTransactionCountRequestMock(ACCOUNT_MOCK),
buildEthSendRawTransactionRequestMock(
'0x02e2050101018252089408f137f335ea1b8f193b8f6ea92561a60d23a2118080c0808080',
'0x1',
Expand Down Expand Up @@ -979,6 +987,7 @@ describe('TransactionController Integration', () => {
approvalController.accept(addTx2.transactionMeta.id),
]);

await advanceTime({ clock, duration: 1 });
await advanceTime({ clock, duration: 1 });

await Promise.all([addTx1.result, addTx2.result]);
Expand Down Expand Up @@ -1195,7 +1204,7 @@ describe('TransactionController Integration', () => {
describe('startIncomingTransactionPolling', () => {
// TODO(JL): IncomingTransactionHelper doesn't populate networkClientId on the generated tx object. Should it?..
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should add incoming transactions to state with the correct chainId for the given networkClientId on the next block', async () => {
it('should add incoming transactions to state with the correct chainId for the given networkClientId on the next block', async () => {
mockNetwork({
networkClientConfiguration: buildInfuraNetworkClientConfiguration(
InfuraNetworkType.mainnet,
Expand Down Expand Up @@ -1622,7 +1631,7 @@ describe('TransactionController Integration', () => {

describe('updateIncomingTransactions', () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should add incoming transactions to state with the correct chainId for the given networkClientId without waiting for the next block', async () => {
it('should add incoming transactions to state with the correct chainId for the given networkClientId without waiting for the next block', async () => {
const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK.to;
const selectedAccountMock = createMockInternalAccount({
address: selectedAddress,
Expand Down Expand Up @@ -1682,6 +1691,7 @@ describe('TransactionController Integration', () => {

// we have to wait for the mutex to be released after the 5 second API rate limit timer
await advanceTime({ clock, duration: 1 });
await advanceTime({ clock, duration: 1 });

expect(transactionController.state.transactions).toHaveLength(
2 * networkClientIds.length,
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3274,15 +3274,15 @@ __metadata:
languageName: unknown
linkType: soft

"@metamask/nonce-tracker@npm:^5.0.0":
version: 5.0.0
resolution: "@metamask/nonce-tracker@npm:5.0.0"
"@metamask/nonce-tracker@npm:^6.0.0":
version: 6.0.0
resolution: "@metamask/nonce-tracker@npm:6.0.0"
dependencies:
"@ethersproject/providers": "npm:^5.7.2"
async-mutex: "npm:^0.3.1"
peerDependencies:
"@metamask/eth-block-tracker": ">=9"
checksum: 10/72bce31702c5575b6dd583dd772312994103ff25389643526284d0e4320588cb0c7b389739fbdb1828f3e6ab387deddfc8cf2b674aa65bf3054db089cafce1db
checksum: 10/e62edd38eeaba6d917bc3aed38017294f2bfdb59120a9fb4f093fe96a46d8d9214453a802fe782faaf4a007f4cd5f393607c70a2ff8479ecd7ef18827cad067a
languageName: node
linkType: hard

Expand Down Expand Up @@ -3948,7 +3948,7 @@ __metadata:
"@metamask/keyring-api": "npm:^8.1.0"
"@metamask/metamask-eth-abis": "npm:^3.1.1"
"@metamask/network-controller": "npm:^20.1.0"
"@metamask/nonce-tracker": "npm:^5.0.0"
"@metamask/nonce-tracker": "npm:^6.0.0"
"@metamask/rpc-errors": "npm:^6.3.1"
"@metamask/utils": "npm:^9.1.0"
"@types/bn.js": "npm:^5.1.5"
Expand Down

0 comments on commit 5318618

Please sign in to comment.