Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable jest/expect-expect */

import { Common } from '@ethereumjs/common';
import {
ChainId,
NetworkType,
Expand All @@ -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';
Expand Down Expand Up @@ -1402,7 +1400,9 @@ describe('TransactionController', () => {

describe('stopTransaction', () => {
it('rejects result promise', async () => {
const controller = newController();
const controller = newController({
network: MOCK_LINEA_GOERLI_NETWORK,
Comment thread
matthewwalsh0 marked this conversation as resolved.
Outdated
});

const { result, transactionMeta } = await controller.addTransaction({
from: ACCOUNT_MOCK,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
84 changes: 42 additions & 42 deletions packages/transaction-controller/src/TransactionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,6 @@ export class TransactionController extends BaseController<
};
}

prepareUnsignedEthTx(txParams: Record<string, unknown>): TypedTransaction {
return TransactionFactory.fromTxData(txParams, {
common: this.getCommonConfiguration(),
freeze: false,
});
}

/**
* Creates approvals for all unapproved transactions persisted.
*/
Expand All @@ -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<ChainConfig> = {
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 `<tx.id>:finished` hub event.
Expand Down Expand Up @@ -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<string, unknown>,
): 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<ChainConfig> = {
name,
chainId: parseInt(chainId, 16),
networkId: networkId === null ? NaN : parseInt(networkId, undefined),
defaultHardfork: HARDFORK,
};

return Common.custom(customChainParams);
}
}

export default TransactionController;