Skip to content

Commit 4b4da4a

Browse files
committed
fix: correctly set txtype when setting up TxEnv
1 parent 031e060 commit 4b4da4a

File tree

2 files changed

+28
-4
lines changed
  • crates

2 files changed

+28
-4
lines changed

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ use alloy_consensus::{
4242
Account, BlockHeader, EnvKzgSettings, Header, Receipt, ReceiptWithBloom, Signed,
4343
Transaction as TransactionTrait, TxEnvelope,
4444
};
45-
use alloy_eips::{eip1559::BaseFeeParams, eip4844::MAX_BLOBS_PER_BLOCK};
45+
use alloy_eips::{
46+
eip1559::BaseFeeParams,
47+
eip2718::{
48+
EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID,
49+
LEGACY_TX_TYPE_ID,
50+
},
51+
eip4844::MAX_BLOBS_PER_BLOCK,
52+
};
4653
use alloy_evm::{eth::EthEvmContext, Database, Evm};
4754
use alloy_network::{
4855
AnyHeader, AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction, AnyTxEnvelope, AnyTxType,
@@ -1410,13 +1417,29 @@ impl Backend {
14101417
authorization_list,
14111418
nonce,
14121419
sidecar: _,
1413-
chain_id: _,
1420+
chain_id,
14141421
transaction_type,
1422+
max_fee_per_gas,
1423+
max_priority_fee_per_gas,
14151424
.. // Rest of the gas fees related fields are taken from `fee_details`
14161425
},
14171426
other,
14181427
} = request;
14191428

1429+
let tx_type = transaction_type.unwrap_or_else(|| {
1430+
if authorization_list.is_some() {
1431+
EIP7702_TX_TYPE_ID
1432+
} else if blob_versioned_hashes.is_some() {
1433+
EIP4844_TX_TYPE_ID
1434+
} else if max_fee_per_gas.is_some() || max_priority_fee_per_gas.is_some() {
1435+
EIP1559_TX_TYPE_ID
1436+
} else if access_list.is_some() {
1437+
EIP2930_TX_TYPE_ID
1438+
} else {
1439+
LEGACY_TX_TYPE_ID
1440+
}
1441+
});
1442+
14201443
let FeeDetails {
14211444
gas_price,
14221445
max_fee_per_gas,
@@ -1463,10 +1486,10 @@ impl Backend {
14631486
Some(addr) => TxKind::Call(*addr),
14641487
None => TxKind::Create,
14651488
},
1466-
tx_type: transaction_type.unwrap_or_default(),
1489+
tx_type,
14671490
value: value.unwrap_or_default(),
14681491
data: input.into_input().unwrap_or_default(),
1469-
chain_id: None,
1492+
chain_id: Some(chain_id.unwrap_or(self.env.read().evm_env.cfg_env.chain_id)),
14701493
access_list: access_list.unwrap_or_default(),
14711494
blob_hashes,
14721495
authorization_list: authorization_list.unwrap_or_default(),

crates/evm/evm/src/executors/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ impl Executor {
438438
) -> eyre::Result<RawCallResult> {
439439
let mut env = self.build_test_env(from, to.into(), calldata, value);
440440
env.tx.authorization_list = authorization_list;
441+
env.tx.tx_type = 4;
441442
self.call_with_env(env)
442443
}
443444

0 commit comments

Comments
 (0)