Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(anvil): on anvil_mine jump to next timestamp before mine new block #9241

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1697,12 +1697,12 @@ impl EthApi {

// mine all the blocks
for _ in 0..blocks.to::<u64>() {
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(())
Expand Down
18 changes: 18 additions & 0 deletions crates/anvil/tests/it/anvil_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,3 +1009,21 @@ async fn test_mine_blks_with_same_timestamp() {
// timestamps should be equal
assert_eq!(blks, vec![init_timestamp; 4]);
}

// <https://github.com/foundry-rs/foundry/issues/8962>
#[tokio::test(flavor = "multi_thread")]
async fn test_mine_first_block_with_interval() {
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;

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);
}
2 changes: 1 addition & 1 deletion crates/cast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
/// # Ok(())
/// # }
/// ```
pub async fn call<'a>(
pub async fn call(
&self,
req: &WithOtherFields<TransactionRequest>,
func: Option<&Function>,
Expand Down
Loading