Skip to content

Commit

Permalink
fix: include withdrawals root in response (foundry-rs#9208)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and rplusq committed Nov 29, 2024
1 parent fea1be9 commit 1dc88a3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ impl Backend {
mix_hash,
nonce,
base_fee_per_gas,
withdrawals_root: _,
withdrawals_root,
blob_gas_used,
excess_blob_gas,
parent_beacon_block_root,
Expand All @@ -1906,7 +1906,7 @@ impl Backend {
mix_hash: Some(mix_hash),
nonce: Some(nonce),
base_fee_per_gas,
withdrawals_root: None,
withdrawals_root,
blob_gas_used,
excess_blob_gas,
parent_beacon_block_root,
Expand All @@ -1917,7 +1917,7 @@ impl Backend {
transactions.into_iter().map(|tx| tx.hash()).collect(),
),
uncles: vec![],
withdrawals: None,
withdrawals: withdrawals_root.map(|_| Default::default()),
};

let mut block = WithOtherFields::new(block);
Expand Down
29 changes: 28 additions & 1 deletion crates/anvil/tests/it/anvil.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! tests for anvil specific logic
use alloy_consensus::EMPTY_ROOT_HASH;
use alloy_eips::BlockNumberOrTag;
use alloy_primitives::Address;
use alloy_provider::Provider;
use anvil::{spawn, NodeConfig};
use anvil::{spawn, EthereumHardfork, NodeConfig};

#[tokio::test(flavor = "multi_thread")]
async fn test_can_change_mining_mode() {
Expand Down Expand Up @@ -88,3 +89,29 @@ async fn test_can_handle_large_timestamp() {
let block = api.block_by_number(BlockNumberOrTag::Latest).await.unwrap().unwrap();
assert_eq!(block.header.timestamp, num);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_shanghai_fields() {
let (api, _handle) =
spawn(NodeConfig::test().with_hardfork(Some(EthereumHardfork::Shanghai.into()))).await;
api.mine_one().await;

let block = api.block_by_number(BlockNumberOrTag::Latest).await.unwrap().unwrap();
assert_eq!(block.header.withdrawals_root, Some(EMPTY_ROOT_HASH));
assert_eq!(block.withdrawals, Some(Default::default()));
assert!(block.header.blob_gas_used.is_none());
assert!(block.header.excess_blob_gas.is_none());
}

#[tokio::test(flavor = "multi_thread")]
async fn test_cancun_fields() {
let (api, _handle) =
spawn(NodeConfig::test().with_hardfork(Some(EthereumHardfork::Cancun.into()))).await;
api.mine_one().await;

let block = api.block_by_number(BlockNumberOrTag::Latest).await.unwrap().unwrap();
assert_eq!(block.header.withdrawals_root, Some(EMPTY_ROOT_HASH));
assert_eq!(block.withdrawals, Some(Default::default()));
assert!(block.header.blob_gas_used.is_some());
assert!(block.header.excess_blob_gas.is_some());
}

0 comments on commit 1dc88a3

Please sign in to comment.