From fda5462b13759a7b34ee7d7a6c23d687b5291ceb Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:59:00 +0530 Subject: [PATCH] fix(`anvil`): use header.number not best_number (#9151) * fix(`anvil`): use header.number not best_number * test * ignore test_arbitrum_fork_block_number --- crates/anvil/src/eth/backend/mem/mod.rs | 2 -- crates/anvil/tests/it/anvil_api.rs | 17 +++++++++++++++++ crates/anvil/tests/it/fork.rs | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index f24be966c6f9a..590e940e1dc0c 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -1916,8 +1916,6 @@ impl Backend { NamedChain::ArbitrumTestnet, ) = NamedChain::try_from(self.env.read().env.cfg.chain_id) { - // Block number is the best number. - block.header.number = self.best_number(); // Set `l1BlockNumber` field. block.other.insert("l1BlockNumber".to_string(), number.into()); } diff --git a/crates/anvil/tests/it/anvil_api.rs b/crates/anvil/tests/it/anvil_api.rs index 088eb76feae88..a6e36929cf257 100644 --- a/crates/anvil/tests/it/anvil_api.rs +++ b/crates/anvil/tests/it/anvil_api.rs @@ -871,3 +871,20 @@ async fn can_set_executor() { assert_eq!(executor, expected_addr); } + +#[tokio::test(flavor = "multi_thread")] +async fn test_arb_get_block() { + let (api, _handle) = spawn(NodeConfig::test().with_chain_id(Some(421611u64))).await; + + // Mine two blocks + api.mine_one().await; + api.mine_one().await; + + let best_number = api.block_number().unwrap().to::(); + + assert_eq!(best_number, 2); + + let block = api.block_by_number(1.into()).await.unwrap().unwrap(); + + assert_eq!(block.header.number, 1); +} diff --git a/crates/anvil/tests/it/fork.rs b/crates/anvil/tests/it/fork.rs index e6db8a0635bbc..7fd9293f31956 100644 --- a/crates/anvil/tests/it/fork.rs +++ b/crates/anvil/tests/it/fork.rs @@ -1218,6 +1218,7 @@ async fn test_arbitrum_fork_dev_balance() { // #[tokio::test(flavor = "multi_thread")] +#[ignore] async fn test_arbitrum_fork_block_number() { // fork to get initial block for test let (_, handle) = spawn(