diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index e597c13e34..f452477844 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -1,6 +1,4 @@ /* eslint-disable jest/expect-expect */ - -import { Common } from '@ethereumjs/common'; import { ChainId, NetworkType, @@ -23,7 +21,7 @@ import type { TransactionControllerMessenger, TransactionConfig, } from './TransactionController'; -import { TransactionController, HARDFORK } from './TransactionController'; +import { TransactionController } from './TransactionController'; import type { TransactionMeta } from './types'; import { WalletDevice, TransactionStatus } from './types'; import { ESTIMATE_GAS_ERROR } from './utils'; @@ -1402,7 +1400,9 @@ describe('TransactionController', () => { describe('stopTransaction', () => { it('rejects result promise', async () => { - const controller = newController(); + const controller = newController({ + network: MOCK_LINEA_GOERLI_NETWORK, + }); const { result, transactionMeta } = await controller.addTransaction({ from: ACCOUNT_MOCK, @@ -1432,7 +1432,9 @@ describe('TransactionController', () => { describe('speedUpTransaction', () => { it('creates additional transaction with increased gas', async () => { - const controller = newController(); + const controller = newController({ + network: MOCK_LINEA_MAINNET_NETWORK, + }); const { transactionMeta } = await controller.addTransaction({ from: ACCOUNT_MOCK, @@ -1498,53 +1500,6 @@ describe('TransactionController', () => { }); }); - describe('getCommonConfiguration', () => { - it('should get the common network configuration for mainnet', async () => { - const controller = new TransactionController({ - getNetworkState: () => MOCK_MAINNET_NETWORK.state, - onNetworkStateChange: MOCK_MAINNET_NETWORK.subscribe, - provider: MOCK_MAINNET_NETWORK.provider, - blockTracker: MOCK_MAINNET_NETWORK.blockTracker, - messenger: messengerMock, - }); - - const config = await controller.getCommonConfiguration(); - expect(config).toStrictEqual( - new Common({ chain: 'mainnet', hardfork: HARDFORK }), - ); - }); - - it.each([ - ['linea-mainnet', MOCK_LINEA_MAINNET_NETWORK, 59144], - ['linea-goerli', MOCK_LINEA_GOERLI_NETWORK, 59140], - ])( - 'should get a custom network configuration for %s', - async ( - _, - { state, subscribe, provider, blockTracker }: MockNetwork, - chainId: number, - ) => { - const controller = new TransactionController({ - getNetworkState: () => state, - onNetworkStateChange: subscribe, - provider, - blockTracker, - messenger: messengerMock, - }); - - const config = controller.getCommonConfiguration(); - expect(config).toStrictEqual( - Common.custom({ - name: undefined, - chainId, - networkId: chainId, - defaultHardfork: HARDFORK, - }), - ); - }, - ); - }); - describe('initApprovals', () => { it('creates approvals for all unapproved transaction', async () => { const transaction = { diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index 51f018a268..c860083c1a 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -393,13 +393,6 @@ export class TransactionController extends BaseController< }; } - prepareUnsignedEthTx(txParams: Record): TypedTransaction { - return TransactionFactory.fromTxData(txParams, { - common: this.getCommonConfiguration(), - freeze: false, - }); - } - /** * Creates approvals for all unapproved transactions persisted. */ @@ -421,40 +414,6 @@ export class TransactionController extends BaseController< } } - /** - * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for - * specifying which chain, network, hardfork and EIPs to support for - * a transaction. By referencing this configuration, and analyzing the fields - * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718 - * transaction type to use. - * - * @returns {Common} common configuration object - */ - - getCommonConfiguration(): Common { - const { - networkId, - providerConfig: { type: chain, chainId, nickname: name }, - } = this.getNetworkState(); - - if ( - chain !== RPC && - chain !== NetworkType['linea-goerli'] && - chain !== NetworkType['linea-mainnet'] - ) { - return new Common({ chain, hardfork: HARDFORK }); - } - - const customChainParams: Partial = { - name, - chainId: parseInt(chainId, 16), - networkId: networkId === null ? NaN : parseInt(networkId, undefined), - defaultHardfork: HARDFORK, - }; - - return Common.custom(customChainParams); - } - /** * Attempts to cancel a transaction based on its ID by setting its status to "rejected" * and emitting a `:finished` hub event. @@ -1289,9 +1248,50 @@ export class TransactionController extends BaseController< } { const { networkId, providerConfig } = this.getNetworkState(); const chainId = providerConfig?.chainId; - return { networkId, chainId }; } + + private prepareUnsignedEthTx( + txParams: Record, + ): TypedTransaction { + return TransactionFactory.fromTxData(txParams, { + common: this.getCommonConfiguration(), + freeze: false, + }); + } + + /** + * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for + * specifying which chain, network, hardfork and EIPs to support for + * a transaction. By referencing this configuration, and analyzing the fields + * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718 + * transaction type to use. + * + * @returns common configuration object + */ + private getCommonConfiguration(): Common { + const { + networkId, + providerConfig: { type: chain, chainId, nickname: name }, + } = this.getNetworkState(); + + if ( + chain !== RPC && + chain !== NetworkType['linea-goerli'] && + chain !== NetworkType['linea-mainnet'] + ) { + return new Common({ chain, hardfork: HARDFORK }); + } + + const customChainParams: Partial = { + name, + chainId: parseInt(chainId, 16), + networkId: networkId === null ? NaN : parseInt(networkId, undefined), + defaultHardfork: HARDFORK, + }; + + return Common.custom(customChainParams); + } } export default TransactionController;