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: ensure prevrandao is set on reset fork #6488

Merged
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
5 changes: 3 additions & 2 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,12 @@ impl Backend {
timestamp: fork_block.timestamp.to_alloy(),
gas_limit: fork_block.gas_limit.to_alloy(),
difficulty: fork_block.difficulty.to_alloy(),
prevrandao: fork_block.mix_hash.map(|h| h.to_alloy()),
// ensures prevrandao is set
prevrandao: Some(fork_block.mix_hash.map(|h| h.to_alloy()).unwrap_or_default()),
// Keep previous `coinbase` and `basefee` value
coinbase: env.block.coinbase,
basefee: env.block.basefee,
..Default::default()
..env.block.clone()
};

self.time.reset((env.block.timestamp.to_ethers()).as_u64());
Expand Down
32 changes: 32 additions & 0 deletions crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,35 @@ async fn can_override_fork_chain_id() {
let chain_id = provider.get_chainid().await.unwrap();
assert_eq!(chain_id.as_u64(), chain_id_override);
}

// <https://github.com/foundry-rs/foundry/issues/6485>
#[tokio::test(flavor = "multi_thread")]
async fn test_fork_reset_moonbeam() {
crate::init_tracing();
let (api, handle) = spawn(
fork_config()
.with_eth_rpc_url(Some("https://rpc.api.moonbeam.network".to_string()))
.with_fork_block_number(None::<u64>),
)
.await;
let provider = handle.http_provider();

let accounts: Vec<_> = handle.dev_wallets().collect();
let from = accounts[0].address();

let tx = TransactionRequest::new().to(Address::random()).value(1337u64).from(from);
let tx = provider.send_transaction(tx, None).await.unwrap().await.unwrap().unwrap();
assert_eq!(tx.status, Some(1u64.into()));

// reset to check timestamp works after resetting
api.anvil_reset(Some(Forking {
json_rpc_url: Some("https://rpc.api.moonbeam.network".to_string()),
block_number: None,
}))
.await
.unwrap();

let tx = TransactionRequest::new().to(Address::random()).value(1337u64).from(from);
let tx = provider.send_transaction(tx, None).await.unwrap().await.unwrap().unwrap();
assert_eq!(tx.status, Some(1u64.into()));
}