Skip to content
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
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ publish = false
[workspace]
resolver = "3"
members = [
"bin/morph-statetest",
"bin/morph-reth",
"crates/chainspec",
"crates/consensus",
Expand Down Expand Up @@ -180,6 +181,7 @@ alloy-network = { version = "2.0.4", default-features = false }
alloy-primitives = { version = "1.5.6", default-features = false }
alloy-provider = { version = "2.0.4", default-features = false }
alloy-rlp = "0.3.13"
alloy-trie = "0.9.5"
alloy-rpc-types-engine = "2.0.4"
alloy-rpc-types-eth = { version = "2.0.4" }
alloy-serde = "2.0.4"
Expand All @@ -190,6 +192,7 @@ alloy-transport = "2.0.4"
alloy-chains = { version = "0.2.33", default-features = false }
crossbeam-channel = "0.5.13"
revm-primitives = { version = "23.0.0", default-features = false }
revm-statetest-types = { version = "17.0.1", default-features = false }
arbitrary = { version = "1.3", features = ["derive"] }
async-lock = "3.4.1"
async-trait = "0.1"
Expand Down Expand Up @@ -237,4 +240,3 @@ criterion = "0.7.0"
test-case = "3"
pyroscope = "0.5.8"
pyroscope_pprofrs = "0.2.10"

26 changes: 26 additions & 0 deletions bin/morph-statetest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "morph-statetest"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true

[dependencies]
alloy-evm.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
alloy-trie.workspace = true
clap.workspace = true
eyre.workspace = true
morph-chainspec.workspace = true
morph-evm.workspace = true
morph-revm.workspace = true
revm = { workspace = true, features = ["tracer"] }
revm-statetest-types.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true

[lints]
workspace = true
85 changes: 85 additions & 0 deletions bin/morph-statetest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
pub mod runner;
pub mod schema;

#[cfg(test)]
mod tests {
use crate::{runner::run_suite_str, schema::MorphTestSuite};
use alloy_primitives::B256;

const MINIMAL_SUITE: &str = r#"{
"minimal_transfer": {
"env": {
"currentCoinbase": "0x0000000000000000000000000000000000000000",
"currentDifficulty": "0x0",
"currentGasLimit": "0x989680",
"currentNumber": "0x1",
"currentTimestamp": "0x1",
"currentBaseFee": "0x1"
},
"pre": {
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0xde0b6b3a7640000",
"nonce": "0x0",
"code": "0x",
"storage": {}
}
},
"transaction": {
"nonce": "0x0",
"gasPrice": "0x1",
"gasLimit": ["0x5208"],
"to": "0x0000000000000000000000000000000000000001",
"value": ["0x1"],
"data": ["0x"],
"secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"feeTokenID": "0x0",
"feeLimit": "0x0",
"version": "0x0",
"reference": "0x0000000000000000000000000000000000000000000000000000000000000000",
"memo": "0x"
},
"post": {
"Jade": [
{
"indexes": { "data": 0, "gas": 0, "value": 0 },
"hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logs": "0x0000000000000000000000000000000000000000000000000000000000000000",
"expectException": null
}
]
}
}
}"#;

#[test]
fn preserves_morph_fork_names() {
let suite: MorphTestSuite = serde_json::from_str(MINIMAL_SUITE).unwrap();
let unit = suite.0.get("minimal_transfer").unwrap();

assert!(unit.post.contains_key("Jade"));
}

#[test]
fn accepts_hex_string_transaction_type() {
let suite_json = MINIMAL_SUITE.replace(
r#""transaction": {
"nonce": "0x0","#,
r#""transaction": {
"type": "0x7f",
"nonce": "0x0","#,
);
let suite: MorphTestSuite = serde_json::from_str(&suite_json).unwrap();
let unit = suite.0.get("minimal_transfer").unwrap();

assert_eq!(unit.transaction.tx_type, Some(0x7f));
}

#[test]
fn executes_minimal_transfer_and_returns_actual_roots() {
let outcomes = run_suite_str(MINIMAL_SUITE).unwrap();

assert_eq!(outcomes.len(), 1);
assert_eq!(outcomes[0].fork, "Jade");
assert_ne!(outcomes[0].state_root, B256::ZERO);
}
}
63 changes: 63 additions & 0 deletions bin/morph-statetest/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use clap::Parser;
use morph_statetest::runner::{RunnerOptions, run_path};
use std::{
fs,
path::{Path, PathBuf},
};

#[derive(Debug, Parser)]
#[command(about = "Execute Ethereum statetest JSON fixtures with Morph EVM semantics")]
struct Cli {
/// JSON file or directory containing statetest fixtures.
path: PathBuf,
/// Emit EIP-3155 execution trace events to stderr.
#[arg(long)]
trace: bool,
/// Validate post-state roots from the fixture and exit non-zero on mismatch.
#[arg(long)]
validate: bool,
}

fn main() -> eyre::Result<()> {
let cli = Cli::parse();
let paths = collect_json_files(&cli.path)?;
if paths.is_empty() {
eyre::bail!("no JSON statetest files found at {}", cli.path.display());
}

let options = RunnerOptions {
trace: cli.trace,
validate: cli.validate,
};
for path in paths {
for outcome in run_path(&path, options)? {
println!("{}", serde_json::to_string(&outcome)?);
}
}

Ok(())
}

fn collect_json_files(path: &Path) -> eyre::Result<Vec<PathBuf>> {
if path.is_file() {
return Ok(
match path.extension().and_then(|extension| extension.to_str()) {
Some("json") => vec![path.to_path_buf()],
_ => Vec::new(),
},
);
}

let mut paths = Vec::new();
for entry in fs::read_dir(path)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
paths.extend(collect_json_files(&path)?);
} else if path.extension().and_then(|extension| extension.to_str()) == Some("json") {
paths.push(path);
}
}
paths.sort();
Ok(paths)
}
Loading