From 88a7bfa8d9e6a24fffa9665cd9cfbda3062ee965 Mon Sep 17 00:00:00 2001 From: Matthew Walsh Date: Fri, 2 Aug 2024 17:32:07 +0100 Subject: [PATCH] Fix integration tests with nonce tracker 6 --- packages/transaction-controller/package.json | 2 +- .../src/TransactionController.ts | 2 +- .../TransactionControllerIntegration.test.ts | 24 +++++++++++++------ yarn.lock | 10 ++++---- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/transaction-controller/package.json b/packages/transaction-controller/package.json index 1346adcdb8c..8d9a5ffd8a8 100644 --- a/packages/transaction-controller/package.json +++ b/packages/transaction-controller/package.json @@ -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", diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index 2a49c54986e..5a76be847e8 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -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, diff --git a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts index 4b87353e0d7..9e792deddf2 100644 --- a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts +++ b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts @@ -52,6 +52,7 @@ import { import type { TransactionControllerActions, TransactionControllerEvents, + TransactionControllerOptions, } from './TransactionController'; import { TransactionController } from './TransactionController'; import type { TransactionMeta } from './types'; @@ -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. @@ -209,7 +210,7 @@ const setupController = async ( mockGetSelectedAccount, ); - const options = { + const options: TransactionControllerOptions = { blockTracker, disableHistory: false, disableSendFlowHistory: false, @@ -232,6 +233,9 @@ const setupController = async ( onNetworkStateChange: () => { // noop }, + pendingTransactions: { + isResubmitEnabled: () => false, + }, provider, sign: async (transaction: TypedTransaction) => transaction, transactionHistoryLimit: 40, @@ -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, @@ -371,6 +375,8 @@ describe('TransactionController Integration', () => { ], }, }); + + await advanceTime({ clock, duration: 1 }); await advanceTime({ clock, duration: 1 }); expect(transactionController.state.transactions).toMatchObject([ @@ -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, @@ -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]); @@ -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, @@ -929,6 +936,7 @@ describe('TransactionController Integration', () => { buildEthEstimateGasRequestMock(ACCOUNT_MOCK, ACCOUNT_2_MOCK), buildEthGasPriceRequestMock(), buildEthGetTransactionCountRequestMock(ACCOUNT_MOCK), + buildEthGetTransactionCountRequestMock(ACCOUNT_MOCK), buildEthSendRawTransactionRequestMock( '0x02e2050101018252089408f137f335ea1b8f193b8f6ea92561a60d23a2118080c0808080', '0x1', @@ -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]); @@ -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, @@ -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, @@ -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, diff --git a/yarn.lock b/yarn.lock index 4a0966e2cdf..60892e2f7ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -3948,7 +3948,7 @@ __metadata: "@metamask/keyring-api": "npm:^8.0.1" "@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"