From 0e12f1a7e57ed16b0ac7fcd0481ea4016e0eb26d Mon Sep 17 00:00:00 2001 From: Ivan Litteri <67517699+ilitteri@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:38:57 -0300 Subject: [PATCH] feat(levm): move `levm` EF tests to `cmd/ef_tests` dir (#1172) **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** - 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. --- .gitignore | 3 +- Cargo.toml | 3 +- Makefile | 4 +-- cmd/ef_tests/{ => ethereum_rust}/Cargo.toml | 2 +- cmd/ef_tests/{ => ethereum_rust}/ef_tests.rs | 0 cmd/ef_tests/{ => ethereum_rust}/network.rs | 0 .../{ => ethereum_rust}/test_runner.rs | 0 .../{ => ethereum_rust}/tests/cancun.rs | 2 +- .../{ => ethereum_rust}/tests/shanghai.rs | 2 +- cmd/ef_tests/{ => ethereum_rust}/types.rs | 0 cmd/ef_tests/levm/Cargo.toml | 28 +++++++++++++++++++ .../ef => cmd/ef_tests/levm}/deserialize.rs | 2 +- cmd/ef_tests/levm/ef_tests.rs | 4 +++ .../tests/ef => cmd/ef_tests/levm}/report.rs | 1 - .../tests/ef => cmd/ef_tests/levm}/runner.rs | 7 ++--- cmd/ef_tests/levm/tests/test.rs | 6 ++++ .../ef/test.rs => cmd/ef_tests/levm/types.rs | 2 +- crates/vm/Cargo.toml | 14 +++++----- crates/vm/levm/Cargo.toml | 2 +- crates/vm/levm/Makefile | 7 +++-- .../vm/levm/bench/revm_comparison/Cargo.toml | 2 +- crates/vm/levm/tests/ef/mod.rs | 13 --------- crates/vm/levm/tests/lib.rs | 2 -- 23 files changed, 64 insertions(+), 42 deletions(-) rename cmd/ef_tests/{ => ethereum_rust}/Cargo.toml (94%) rename cmd/ef_tests/{ => ethereum_rust}/ef_tests.rs (100%) rename cmd/ef_tests/{ => ethereum_rust}/network.rs (100%) rename cmd/ef_tests/{ => ethereum_rust}/test_runner.rs (100%) rename cmd/ef_tests/{ => ethereum_rust}/tests/cancun.rs (91%) rename cmd/ef_tests/{ => ethereum_rust}/tests/shanghai.rs (88%) rename cmd/ef_tests/{ => ethereum_rust}/types.rs (100%) create mode 100644 cmd/ef_tests/levm/Cargo.toml rename {crates/vm/levm/tests/ef => cmd/ef_tests/levm}/deserialize.rs (99%) create mode 100644 cmd/ef_tests/levm/ef_tests.rs rename {crates/vm/levm/tests/ef => cmd/ef_tests/levm}/report.rs (97%) rename {crates/vm/levm/tests/ef => cmd/ef_tests/levm}/runner.rs (97%) create mode 100644 cmd/ef_tests/levm/tests/test.rs rename crates/vm/levm/tests/ef/test.rs => cmd/ef_tests/levm/types.rs (99%) delete mode 100644 crates/vm/levm/tests/ef/mod.rs delete mode 100644 crates/vm/levm/tests/lib.rs diff --git a/.gitignore b/.gitignore index a596bad39..cbdf31f53 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/Cargo.toml b/Cargo.toml index ab1b5cb26..446ea3fa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/Makefile b/Makefile index 68ef1d9bc..63cd3c479 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cmd/ef_tests/Cargo.toml b/cmd/ef_tests/ethereum_rust/Cargo.toml similarity index 94% rename from cmd/ef_tests/Cargo.toml rename to cmd/ef_tests/ethereum_rust/Cargo.toml index 1895ce82e..abd9c11c4 100644 --- a/cmd/ef_tests/Cargo.toml +++ b/cmd/ef_tests/ethereum_rust/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ef_tests" +name = "ef_tests-ethereum_rust" version.workspace = true edition.workspace = true diff --git a/cmd/ef_tests/ef_tests.rs b/cmd/ef_tests/ethereum_rust/ef_tests.rs similarity index 100% rename from cmd/ef_tests/ef_tests.rs rename to cmd/ef_tests/ethereum_rust/ef_tests.rs diff --git a/cmd/ef_tests/network.rs b/cmd/ef_tests/ethereum_rust/network.rs similarity index 100% rename from cmd/ef_tests/network.rs rename to cmd/ef_tests/ethereum_rust/network.rs diff --git a/cmd/ef_tests/test_runner.rs b/cmd/ef_tests/ethereum_rust/test_runner.rs similarity index 100% rename from cmd/ef_tests/test_runner.rs rename to cmd/ef_tests/ethereum_rust/test_runner.rs diff --git a/cmd/ef_tests/tests/cancun.rs b/cmd/ef_tests/ethereum_rust/tests/cancun.rs similarity index 91% rename from cmd/ef_tests/tests/cancun.rs rename to cmd/ef_tests/ethereum_rust/tests/cancun.rs index c80ba7e17..4ed4ad94d 100644 --- a/cmd/ef_tests/tests/cancun.rs +++ b/cmd/ef_tests/ethereum_rust/tests/cancun.rs @@ -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); diff --git a/cmd/ef_tests/tests/shanghai.rs b/cmd/ef_tests/ethereum_rust/tests/shanghai.rs similarity index 88% rename from cmd/ef_tests/tests/shanghai.rs rename to cmd/ef_tests/ethereum_rust/tests/shanghai.rs index 900191b5e..d3689f939 100644 --- a/cmd/ef_tests/tests/shanghai.rs +++ b/cmd/ef_tests/ethereum_rust/tests/shanghai.rs @@ -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); diff --git a/cmd/ef_tests/types.rs b/cmd/ef_tests/ethereum_rust/types.rs similarity index 100% rename from cmd/ef_tests/types.rs rename to cmd/ef_tests/ethereum_rust/types.rs diff --git a/cmd/ef_tests/levm/Cargo.toml b/cmd/ef_tests/levm/Cargo.toml new file mode 100644 index 000000000..c9589dbb8 --- /dev/null +++ b/cmd/ef_tests/levm/Cargo.toml @@ -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 diff --git a/crates/vm/levm/tests/ef/deserialize.rs b/cmd/ef_tests/levm/deserialize.rs similarity index 99% rename from crates/vm/levm/tests/ef/deserialize.rs rename to cmd/ef_tests/levm/deserialize.rs index 6f872e8da..ca731bacb 100644 --- a/crates/vm/levm/tests/ef/deserialize.rs +++ b/cmd/ef_tests/levm/deserialize.rs @@ -1,4 +1,4 @@ -use crate::ef::test::EFTest; +use crate::types::EFTest; use bytes::Bytes; use ethereum_rust_core::U256; use serde::Deserialize; diff --git a/cmd/ef_tests/levm/ef_tests.rs b/cmd/ef_tests/levm/ef_tests.rs new file mode 100644 index 000000000..f117e2a37 --- /dev/null +++ b/cmd/ef_tests/levm/ef_tests.rs @@ -0,0 +1,4 @@ +mod deserialize; +mod report; +pub mod runner; +mod types; diff --git a/crates/vm/levm/tests/ef/report.rs b/cmd/ef_tests/levm/report.rs similarity index 97% rename from crates/vm/levm/tests/ef/report.rs rename to cmd/ef_tests/levm/report.rs index 3069f90cf..e34b4aa3d 100644 --- a/crates/vm/levm/tests/ef/report.rs +++ b/cmd/ef_tests/levm/report.rs @@ -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; diff --git a/crates/vm/levm/tests/ef/runner.rs b/cmd/ef_tests/levm/runner.rs similarity index 97% rename from crates/vm/levm/tests/ef/runner.rs rename to cmd/ef_tests/levm/runner.rs index cef9fa246..0ef441ea7 100644 --- a/crates/vm/levm/tests/ef/runner.rs +++ b/cmd/ef_tests/levm/runner.rs @@ -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}, @@ -15,7 +13,7 @@ use std::{error::Error, sync::Arc}; pub fn run_ef_tests() -> Result> { 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())? @@ -54,7 +52,6 @@ pub fn run_ef_tests() -> Result> { } pub fn run_ef_test(test: EFTest, report: &mut EFTestsReport) -> Result<(), Box> { - dbg!(&test.name); let mut evm = prepare_vm(&test, report)?; ensure_pre_state(&evm, &test, report)?; let execution_result = evm.transact(); diff --git a/cmd/ef_tests/levm/tests/test.rs b/cmd/ef_tests/levm/tests/test.rs new file mode 100644 index 000000000..e726edb91 --- /dev/null +++ b/cmd/ef_tests/levm/tests/test.rs @@ -0,0 +1,6 @@ +use ef_tests_levm::runner; + +fn main() { + let report = runner::run_ef_tests().unwrap(); + println!("{report}"); +} diff --git a/crates/vm/levm/tests/ef/test.rs b/cmd/ef_tests/levm/types.rs similarity index 99% rename from crates/vm/levm/tests/ef/test.rs rename to cmd/ef_tests/levm/types.rs index eee3882db..c003c33b9 100644 --- a/crates/vm/levm/tests/ef/test.rs +++ b/cmd/ef_tests/levm/types.rs @@ -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, diff --git a/crates/vm/Cargo.toml b/crates/vm/Cargo.toml index a6433297b..616712a43 100644 --- a/crates/vm/Cargo.toml +++ b/crates/vm/Cargo.toml @@ -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 @@ -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 diff --git a/crates/vm/levm/Cargo.toml b/crates/vm/levm/Cargo.toml index 8c6cd951a..2d0400fa6 100644 --- a/crates/vm/levm/Cargo.toml +++ b/crates/vm/levm/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ethereum_rust_levm" +name = "ethereum_rust-levm" version.workspace = true edition.workspace = true diff --git a/crates/vm/levm/Makefile b/crates/vm/levm/Makefile index c3c6eac9c..316dd74a1 100644 --- a/crates/vm/levm/Makefile +++ b/crates/vm/levm/Makefile @@ -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 @@ -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 @@ -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) diff --git a/crates/vm/levm/bench/revm_comparison/Cargo.toml b/crates/vm/levm/bench/revm_comparison/Cargo.toml index 6c1c1e2a6..a97b97b81 100644 --- a/crates/vm/levm/bench/revm_comparison/Cargo.toml +++ b/crates/vm/levm/bench/revm_comparison/Cargo.toml @@ -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" diff --git a/crates/vm/levm/tests/ef/mod.rs b/crates/vm/levm/tests/ef/mod.rs deleted file mode 100644 index 9de0c0234..000000000 --- a/crates/vm/levm/tests/ef/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![allow(clippy::unwrap_used)] - -mod deserialize; -mod report; -mod runner; -mod test; - -#[test] -#[ignore] -fn testito() { - let report = runner::run_ef_tests().unwrap(); - println!("{report}"); -} diff --git a/crates/vm/levm/tests/lib.rs b/crates/vm/levm/tests/lib.rs deleted file mode 100644 index 2ad8b400f..000000000 --- a/crates/vm/levm/tests/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod ef; -pub mod tests;