Skip to content

Commit

Permalink
fix(anvil): use header.number not best_number (foundry-rs#9151)
Browse files Browse the repository at this point in the history
* fix(`anvil`): use header.number not best_number

* test

* ignore test_arbitrum_fork_block_number
  • Loading branch information
yash-atreya authored and rplusq committed Nov 29, 2024
1 parent a7f608c commit fda5462
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 0 additions & 2 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
17 changes: 17 additions & 0 deletions crates/anvil/tests/it/anvil_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>();

assert_eq!(best_number, 2);

let block = api.block_by_number(1.into()).await.unwrap().unwrap();

assert_eq!(block.header.number, 1);
}
1 change: 1 addition & 0 deletions crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,7 @@ async fn test_arbitrum_fork_dev_balance() {

// <https://github.com/foundry-rs/foundry/issues/6749>
#[tokio::test(flavor = "multi_thread")]
#[ignore]
async fn test_arbitrum_fork_block_number() {
// fork to get initial block for test
let (_, handle) = spawn(
Expand Down

0 comments on commit fda5462

Please sign in to comment.