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

Add snapshot_data.rs #455

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
34 changes: 34 additions & 0 deletions crates/pevm/tests/snapshot_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Test if snapshotted mainnet data is correct

use alloy_primitives::B256;
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types_eth::{BlockNumberOrTag, BlockTransactionsKind};
use std::collections::BTreeMap;
use std::fs::File;

#[tokio::test]
async fn snapshotted_mainnet_block_hashes() {
let file = File::open("../../data/block_hashes.bincode").unwrap();
let block_hashes = bincode::deserialize_from::<_, BTreeMap<u64, B256>>(file).unwrap();

let rpc_url = match std::env::var("ETHEREUM_RPC_URL") {
// The empty check is for GitHub Actions where the variable is set with an empty string when unset!?
Ok(value) if !value.is_empty() => value.parse().unwrap(),
_ => reqwest::Url::parse("https://eth.public-rpc.com").unwrap(),
};

let provider = ProviderBuilder::new().on_http(rpc_url);

for (block_number, snapshotted_hash) in block_hashes {
let block = provider
.get_block_by_number(
BlockNumberOrTag::Number(block_number),
BlockTransactionsKind::Hashes,
)
.await
.unwrap()
.unwrap();

assert_eq!(snapshotted_hash, block.header.hash);
}
}
Loading