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

Testing setup #36

Merged
merged 12 commits into from
Dec 4, 2024
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
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ jobs:
- run: cargo check --all-targets
- run: cargo clippy -- --deny warnings

spec-tests:
name: Spec tests
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust || 'stable' }}
targets: ${{ matrix.target }}
- name: Downloading ethereum/tests
run: git clone https://github.com/ethereum/tests ethereum-tests
- name: Downloading EELS fixtures released at Cancun
run: curl -LO https://github.com/ethereum/execution-spec-tests/releases/download/v2.1.1/fixtures.tar.gz && tar -xzf fixtures.tar.gz
- name: Test specs (EELS and ethereum/tests)
run: cargo test --features testing

tests:
name: Tests ${{ matrix.name }}
needs: [style]
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
ethereum-tests/
fixtures/
1 change: 1 addition & 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 @@ -21,6 +21,7 @@ reth-ethereum-consensus = { git = "https://github.com/paradigmxyz/reth", rev = "
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", rev = "8f61af0136e1a20119832925081c341ae89b93f0" }
reth-chain-state = { git = "https://github.com/paradigmxyz/reth", rev = "8f61af0136e1a20119832925081c341ae89b93f0" }
reth-consensus = { git = "https://github.com/paradigmxyz/reth", rev = "8f61af0136e1a20119832925081c341ae89b93f0" }
reth-cli = { git = "https://github.com/paradigmxyz/reth", rev = "8f61af0136e1a20119832925081c341ae89b93f0" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", rev = "8f61af0136e1a20119832925081c341ae89b93f0" }
# reth-auto-seal-consensus = { git = "https://github.com/paradigmxyz/reth", rev = "8f61af0136e1a20119832925081c341ae89b93f0" }
reth-prune-types = { git = "https://github.com/paradigmxyz/reth", rev = "8f61af0136e1a20119832925081c341ae89b93f0" }
Expand Down Expand Up @@ -80,4 +81,5 @@ libc = "0.2"
[features]
default = ["jemalloc"]
jemalloc = ["dep:tikv-jemallocator"]

testing = []
failing-tests = []
3 changes: 2 additions & 1 deletion scripts/chiado_genesis_alloc.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
},
"registrar": "0x6000000000000000000000000000000000000000"
},
"eip1559collector": "0x1559000000000000000000000000000000000000"
"eip1559collector": "0x1559000000000000000000000000000000000000",
"depositContractAddress": "0xbabe2bed00000000000000000000000000000003"
},
"baseFeePerGas": "0x3b9aca00",
"difficulty": "0x01",
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod evm_config;
pub mod execute;
mod gnosis;
mod payload_builder;
mod testing;

#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
#[command(next_help_heading = "Gnosis")]
Expand Down
18 changes: 18 additions & 0 deletions src/testing/assert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Various assertion helpers.

use crate::testing::Error;
use std::fmt::Debug;

/// A helper like `assert_eq!` that instead returns `Err(Error::Assertion)` on failure.
pub fn assert_equal<T>(left: T, right: T, msg: &str) -> Result<(), Error>
where
T: PartialEq + Debug,
{
if left == right {
Ok(())
} else {
Err(Error::Assertion(format!(
"{msg}\n left `{left:?}`,\n right `{right:?}`"
)))
}
}
42 changes: 42 additions & 0 deletions src/testing/case.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! Test case definitions

use crate::testing::result::{CaseResult, Error};
use std::{
fmt::Debug,
path::{Path, PathBuf},
};

/// A single test case, capable of loading a JSON description of itself and running it.
///
/// See <https://ethereum-tests.readthedocs.io/> for test specs.
pub trait Case: Debug + Sync + Sized {
/// A description of the test.
fn description(&self) -> String {
"no description".to_string()
}

/// Load the test from the given file path.
///
/// The file can be assumed to be a valid EF test case as described on <https://ethereum-tests.readthedocs.io/>.
fn load(path: &Path) -> Result<Self, Error>;

/// Run the test.
fn run(&self) -> Result<(), Error>;
}

/// A container for multiple test cases.
#[derive(Debug)]
pub struct Cases<T> {
/// The contained test cases and the path to each test.
pub test_cases: Vec<(PathBuf, T)>,
}

impl<T: Case> Cases<T> {
/// Run the contained test cases.
pub fn run(&self) -> Vec<CaseResult> {
self.test_cases
.iter()
.map(|(path, case)| CaseResult::new(path, case, case.run()))
.collect()
}
}
Loading
Loading