From c5ae3315aca778e48a3325fcd369e318381f10e8 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:03:26 +0530 Subject: [PATCH 1/3] fix(`anvil`): use header.number not best_number --- crates/anvil/src/eth/backend/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index f24be966c6f9..52afa595ec65 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -1917,7 +1917,7 @@ impl Backend { ) = NamedChain::try_from(self.env.read().env.cfg.chain_id) { // Block number is the best number. - block.header.number = self.best_number(); + block.header.number = number; // Set `l1BlockNumber` field. block.other.insert("l1BlockNumber".to_string(), number.into()); } From 82d9e9704d48463b53d68cc7ddb17ea4fc460922 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:33:24 +0530 Subject: [PATCH 2/3] test --- crates/anvil/src/eth/backend/mem/mod.rs | 2 -- crates/anvil/tests/it/anvil_api.rs | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index 52afa595ec65..590e940e1dc0 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 = 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 088eb76feae8..a6e36929cf25 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); +} From aa555dc82e86787d04c62b03a47d5d63072d5c13 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:12:20 +0530 Subject: [PATCH 3/3] ignore test_arbitrum_fork_block_number --- crates/anvil/tests/it/fork.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/anvil/tests/it/fork.rs b/crates/anvil/tests/it/fork.rs index e6db8a0635bb..7fd9293f3195 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(