From 1dc88a3b7eaec6078188256e554ba4feb26ec2e9 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 27 Oct 2024 15:12:07 +0100 Subject: [PATCH] fix: include withdrawals root in response (#9208) --- crates/anvil/src/eth/backend/mem/mod.rs | 6 ++--- crates/anvil/tests/it/anvil.rs | 29 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index 34d37d666d444..73adaa97f3fd7 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -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, @@ -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, @@ -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); diff --git a/crates/anvil/tests/it/anvil.rs b/crates/anvil/tests/it/anvil.rs index 50e27c57aa57c..5a952da6b2b49 100644 --- a/crates/anvil/tests/it/anvil.rs +++ b/crates/anvil/tests/it/anvil.rs @@ -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() { @@ -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()); +}