From dbf5d52b75129576ca45fa8c8c94ac07bb0cf732 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Fri, 1 Nov 2024 08:32:39 +0200 Subject: [PATCH 1/2] fix(anvil): on anvil_mine jump to next timestamp before mine new block --- crates/anvil/src/eth/api.rs | 4 ++-- crates/anvil/tests/it/anvil_api.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/anvil/src/eth/api.rs b/crates/anvil/src/eth/api.rs index 20ac92234f27..81990d75558b 100644 --- a/crates/anvil/src/eth/api.rs +++ b/crates/anvil/src/eth/api.rs @@ -1697,12 +1697,12 @@ impl EthApi { // mine all the blocks for _ in 0..blocks.to::() { - self.mine_one().await; - // If we have an interval, jump forwards in time to the "next" timestamp if let Some(interval) = interval { self.backend.time().increase_time(interval); } + + self.mine_one().await; } Ok(()) diff --git a/crates/anvil/tests/it/anvil_api.rs b/crates/anvil/tests/it/anvil_api.rs index da5372c7edb3..ef41f66ef080 100644 --- a/crates/anvil/tests/it/anvil_api.rs +++ b/crates/anvil/tests/it/anvil_api.rs @@ -1009,3 +1009,21 @@ async fn test_mine_blks_with_same_timestamp() { // timestamps should be equal assert_eq!(blks, vec![init_timestamp; 4]); } + +// +#[tokio::test(flavor = "multi_thread")] +async fn test_mine_first_block_with_interval() { + let (api, handle) = spawn(NodeConfig::test()).await; + let provider = handle.http_provider(); + let init_blk = provider.get_block(BlockId::latest(), false.into()).await.unwrap().unwrap(); + let init_timestamp = init_blk.header.timestamp; + + // Mine 2 blocks with interval of 60. + let _ = api.anvil_mine(Some(U256::from(2)), Some(U256::from(60))).await; + + let first_block = api.block_by_number(1.into()).await.unwrap().unwrap(); + assert_eq!(first_block.header.timestamp, init_timestamp + 60); + + let second_block = api.block_by_number(2.into()).await.unwrap().unwrap(); + assert_eq!(second_block.header.timestamp, init_timestamp + 120); +} From fa52cf32beb31dd2ddc9debc6cbfb313aa2d35c6 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Fri, 1 Nov 2024 08:50:47 +0200 Subject: [PATCH 2/2] Fix unrelated clippy, simplify test --- crates/anvil/tests/it/anvil_api.rs | 8 ++++---- crates/cast/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/anvil/tests/it/anvil_api.rs b/crates/anvil/tests/it/anvil_api.rs index ef41f66ef080..ce78d72ca59a 100644 --- a/crates/anvil/tests/it/anvil_api.rs +++ b/crates/anvil/tests/it/anvil_api.rs @@ -1013,10 +1013,10 @@ async fn test_mine_blks_with_same_timestamp() { // #[tokio::test(flavor = "multi_thread")] async fn test_mine_first_block_with_interval() { - let (api, handle) = spawn(NodeConfig::test()).await; - let provider = handle.http_provider(); - let init_blk = provider.get_block(BlockId::latest(), false.into()).await.unwrap().unwrap(); - let init_timestamp = init_blk.header.timestamp; + let (api, _) = spawn(NodeConfig::test()).await; + + let init_block = api.block_by_number(0.into()).await.unwrap().unwrap(); + let init_timestamp = init_block.header.timestamp; // Mine 2 blocks with interval of 60. let _ = api.anvil_mine(Some(U256::from(2)), Some(U256::from(60))).await; diff --git a/crates/cast/src/lib.rs b/crates/cast/src/lib.rs index 97624c12ab64..bfa33c6e93f8 100644 --- a/crates/cast/src/lib.rs +++ b/crates/cast/src/lib.rs @@ -128,7 +128,7 @@ where /// # Ok(()) /// # } /// ``` - pub async fn call<'a>( + pub async fn call( &self, req: &WithOtherFields, func: Option<&Function>,