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

refactor(levm): ef test runner #1206

Merged
merged 22 commits into from
Nov 25, 2024
Merged
Changes from 1 commit
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
76 changes: 47 additions & 29 deletions cmd/ef_tests/levm/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,67 @@ use ethereum_rust_storage::AccountUpdate;
use ethereum_rust_vm::db::StoreWrapper;
use keccak_hash::keccak;
use spinoff::{spinners::Dots, Color, Spinner};
use std::{collections::HashMap, error::Error, sync::Arc};
use std::{collections::HashMap, error::Error, fs::DirEntry, sync::Arc};

pub fn run_ef_tests() -> Result<EFTestsReport, Box<dyn Error>> {
let mut report = EFTestsReport::default();
let cargo_manifest_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let ef_general_state_tests_path = cargo_manifest_dir.join("vectors/GeneralStateTests");
let mut spinner = Spinner::new(Dots, report.progress(), Color::Cyan);
for test_dir in std::fs::read_dir(ef_general_state_tests_path)?.flatten() {
for test in std::fs::read_dir(test_dir.path())?
.flatten()
.filter(|entry| {
entry
.path()
.extension()
.map(|ext| ext == "json")
.unwrap_or(false)
})
{
// TODO: Figure out what to do with overflowed value: 0x10000000000000000000000000000000000000000000000000000000000000001.
// Deserialization fails because the value is too big for U256.
if test
.path()
.file_name()
.is_some_and(|name| name == "ValueOverflowParis.json")
{
continue;
}
let test_result = run_ef_test(
serde_json::from_reader(std::fs::File::open(test.path())?)?,
&mut report,
);
if test_result.is_err() {
continue;
}
}
spinner.update_text(report.progress());
run_ef_test_dir(test_dir, &mut report, &mut spinner)?;
}
spinner.success(&report.progress());
let mut spinner = Spinner::new(Dots, "Loading report...".to_owned(), Color::Cyan);
spinner.success(&report.to_string());
Ok(report)
}

fn run_ef_test_dir(
test_dir: DirEntry,
report: &mut EFTestsReport,
spinner: &mut Spinner,
) -> Result<(), Box<dyn Error>> {
if test_dir
.path()
.file_name()
.is_some_and(|name| name == "VMTests")
{
for sub_test_dir in std::fs::read_dir(test_dir.path())?.flatten() {
run_ef_test_dir(sub_test_dir, report, spinner)?;
}
}
for test in std::fs::read_dir(test_dir.path())?
.flatten()
.filter(|entry| {
entry
.path()
.extension()
.map(|ext| ext == "json")
.unwrap_or(false)
})
{
// TODO: Figure out what to do with overflowed value: 0x10000000000000000000000000000000000000000000000000000000000000001.
// Deserialization fails because the value is too big for U256.
if test
.path()
.file_name()
.is_some_and(|name| name == "ValueOverflowParis.json")
{
continue;
}
let test_result = run_ef_test(
serde_json::from_reader(std::fs::File::open(test.path())?)?,
report,
);
if test_result.is_err() {
continue;
}
}
spinner.update_text(report.progress());
Ok(())
}

pub fn run_ef_test_tx(
tx_id: usize,
test: &EFTest,
Expand Down
Loading