Skip to content

Commit

Permalink
feat(levm): move levm EF tests to cmd/ef_tests dir (#1172)
Browse files Browse the repository at this point in the history
**Motivation**

We need `ethereum_rust` as a dependency for running the EF tests,
specifically for the post-state validation. If we import it inside the
crate `levm`, we have a circular dependency as `ethereum_rust` also
imports `levm`.

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->

- Move `ethereum_rust` EF tests to `cmd/ef_tests/ethereum_rust`.
- Update `ethereum_rust` Makefile targets that run the EF tests
according to the previous change
- Move `levm` EF tests to `cmd/ef_tests/levm`.
- Update `ethereum_rust` Makefile targets that run the EF tests to skip
`levm` EF tests run (this will be done in the crate `levm`)
- Update `levm` Makefile targets that run the EF tests according to the
changes above.
  • Loading branch information
ilitteri authored Nov 14, 2024
1 parent b804aa2 commit 0e12f1a
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

cmd/ef_tests/vectors
cmd/ef_tests/ethereum_rust/vectors
cmd/ef_tests/levm/vectors

# Repos checked out by make target
hive/
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ members = [
"crates/storage/trie",
"crates/common/rlp",
"cmd/ethereum_rust",
"cmd/ef_tests",
"cmd/ef_tests/ethereum_rust",
"cmd/ef_tests/levm",
"cmd/ethereum_rust_l2",
"crates/vm/levm",
"crates/vm/levm/bench/revm_comparison",
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ lint: ## 🧹 Linter check

SPECTEST_VERSION := v3.0.0
SPECTEST_ARTIFACT := tests_$(SPECTEST_VERSION).tar.gz
SPECTEST_VECTORS_DIR := cmd/ef_tests/vectors
SPECTEST_VECTORS_DIR := cmd/ef_tests/ethereum_rust/vectors

CRATE ?= *
test: $(SPECTEST_VECTORS_DIR) ## 🧪 Run each crate's tests
cargo test -p '$(CRATE)' --workspace --exclude ethereum_rust-prover -- --skip test_contract_compilation --skip testito
cargo test -p '$(CRATE)' --workspace --exclude ethereum_rust-prover --exclude ethereum_rust-levm --exclude ef_tests-levm -- --skip test_contract_compilation --skip testito

clean: clean-vectors ## 🧹 Remove build artifacts
cargo clean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ef_tests"
name = "ef_tests-ethereum_rust"
version.workspace = true
edition.workspace = true

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use ef_tests::test_runner::{parse_test_file, run_ef_test};
use ef_tests_ethereum_rust::test_runner::{parse_test_file, run_ef_test};

fn parse_and_execute(path: &Path) -> datatest_stable::Result<()> {
let tests = parse_test_file(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use ef_tests::test_runner::{parse_test_file, run_ef_test};
use ef_tests_ethereum_rust::test_runner::{parse_test_file, run_ef_test};

fn parse_and_execute(path: &Path) -> datatest_stable::Result<()> {
let tests = parse_test_file(path);
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions cmd/ef_tests/levm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "ef_tests-levm"
version.workspace = true
edition.workspace = true

[dependencies]
ethereum_rust-blockchain.workspace = true
ethereum_rust-core.workspace = true
ethereum_rust-storage.workspace = true
ethereum_rust-rlp.workspace = true
ethereum_rust-levm = { path = "../../../crates/vm/levm" }
serde.workspace = true
serde_json.workspace = true
bytes.workspace = true
hex.workspace = true
keccak-hash = "0.11.0"
colored = "2.1.0"
spinoff = "0.8.0"

[dev-dependencies]
hex = "0.4.3"

[lib]
path = "./ef_tests.rs"

[[test]]
name = "test"
harness = false
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ef::test::EFTest;
use crate::types::EFTest;
use bytes::Bytes;
use ethereum_rust_core::U256;
use serde::Deserialize;
Expand Down
4 changes: 4 additions & 0 deletions cmd/ef_tests/levm/ef_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod deserialize;
mod report;
pub mod runner;
mod types;
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Note: I use this to do not affect the EF tests logic with this side effects
// The cost to add this would be to return a Result<(), InternalError> in EFTestsReport methods
#![allow(clippy::arithmetic_side_effects)]

use colored::Colorize;
use std::fmt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![allow(clippy::unwrap_used)]

use crate::ef::{report::EFTestsReport, test::EFTest};
use crate::{report::EFTestsReport, types::EFTest};
use ethereum_rust_core::{H256, U256};
use ethereum_rust_levm::{
db::{Cache, Db},
Expand All @@ -15,7 +13,7 @@ use std::{error::Error, 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("tests/ef/tests/GeneralStateTests");
let ef_general_state_tests_path = cargo_manifest_dir.join("vectors/GeneralStateTests");
let mut spinner = Spinner::new(Dots, report.to_string(), 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())?
Expand Down Expand Up @@ -54,7 +52,6 @@ pub fn run_ef_tests() -> Result<EFTestsReport, Box<dyn Error>> {
}

pub fn run_ef_test(test: EFTest, report: &mut EFTestsReport) -> Result<(), Box<dyn Error>> {
dbg!(&test.name);
let mut evm = prepare_vm(&test, report)?;
ensure_pre_state(&evm, &test, report)?;
let execution_result = evm.transact();
Expand Down
6 changes: 6 additions & 0 deletions cmd/ef_tests/levm/tests/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use ef_tests_levm::runner;

fn main() {
let report = runner::run_ef_tests().unwrap();
println!("{report}");
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ef::deserialize::{
use crate::deserialize::{
deserialize_ef_post_value_indexes, deserialize_hex_bytes, deserialize_hex_bytes_vec,
deserialize_u256_optional_safe, deserialize_u256_safe, deserialize_u256_valued_hashmap_safe,
deserialize_u256_vec_safe,
Expand Down
14 changes: 7 additions & 7 deletions crates/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ edition = "2021"
[dependencies]
ethereum_rust-core = { path = "../common", default-features = false }
ethereum_rust-storage = { path = "../storage/store", default-features = false }
ethereum_rust_levm = { path = "./levm", optional = true }
ethereum_rust-levm = { path = "./levm", optional = true }
ethereum_rust-trie = { path = "../storage/trie", default-features = false }
ethereum_rust-rlp = { path = "../common/rlp", default-features = false }
revm = { version = "14.0.3", features = [
"serde",
"std",
"serde-json",
"optional_no_base_fee",
"optional_block_gas_limit",
"serde",
"std",
"serde-json",
"optional_no_base_fee",
"optional_block_gas_limit",
], default-features = false }

# These dependencies must be kept up to date with the corresponding revm version, otherwise errors may pop up because of trait implementation mismatches
Expand Down Expand Up @@ -43,7 +43,7 @@ l2 = []
c-kzg = ["revm/c-kzg"]
blst = ["revm/blst"]
libmdbx = ["ethereum_rust-storage/default", "ethereum_rust-core/libmdbx"]
levm = ["ethereum_rust_levm"]
levm = ["ethereum_rust-levm"]

[profile.test]
opt-level = 3
2 changes: 1 addition & 1 deletion crates/vm/levm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ethereum_rust_levm"
name = "ethereum_rust-levm"
version.workspace = true
edition.workspace = true

Expand Down
7 changes: 4 additions & 3 deletions crates/vm/levm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ help: ## 📚 Show help for each of the Makefile recipes
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

test: ## 🧪 Runs all tests except Ethereum tests
cargo test -p ethereum_rust_levm
cargo test -p ethereum_rust-levm

lint: ## 🧹 Linter check
cargo clippy --all-targets --all-features -- -D warnings
Expand All @@ -18,7 +18,7 @@ fmt: ## 📄 Runs rustfmt

SPECTEST_VERSION := v14.1
SPECTEST_ARTIFACT := tests_$(SPECTEST_VERSION).tar.gz
SPECTEST_VECTORS_DIR := tests/ef/tests
SPECTEST_VECTORS_DIR := ../../../cmd/ef_tests/levm/vectors

$(SPECTEST_ARTIFACT):
rm -f tests_*.tar.gz # Delete older versions
Expand All @@ -32,7 +32,8 @@ $(SPECTEST_VECTORS_DIR): $(SPECTEST_ARTIFACT)
download-ef-tests: $(SPECTEST_VECTORS_DIR) ## 📥 Download EF Tests

run-ef-tests: ## 🏃‍♂️ Run EF Tests
cargo test ef::testito -- --ignored
cd ../../../ && \
cargo test -p ef_tests-levm --tests test

clean-ef-tests: ## 🗑️ Clean test vectors
rm -rf $(SPECTEST_VECTORS_DIR)
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/levm/bench/revm_comparison/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "revm_comparison"
path = "src/lib.rs"

[dependencies]
ethereum_rust_levm = { path = "../../" }
ethereum_rust-levm = { path = "../../" }
hex = "0.4.3"
revm = "9.0.0"
bytes = "1.8.0"
Expand Down
13 changes: 0 additions & 13 deletions crates/vm/levm/tests/ef/mod.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/vm/levm/tests/lib.rs

This file was deleted.

0 comments on commit 0e12f1a

Please sign in to comment.