Skip to content

Commit

Permalink
feat - adds testing scripts for ethereum//tests and execution spec te…
Browse files Browse the repository at this point in the history
…sts (#37)

* regular dependency upgrade

* rewards contract call not made to fail if contract not deployed

* testing setup

* fmt etc

* added tests for eels

* downloads the folders

* new job for spec tests

* updated cargo.lock

* removed consensus and upgraded to newer

* rebase and bugfixes

* feature to exclude time consuming tests (but not enabled)

* cleanup

* regular dependency upgrade

* testing setup

* updated cargo.lock

* removed consensus and upgraded to newer

* lock

* fmt

* debug
  • Loading branch information
debjit-bw authored Dec 5, 2024
1 parent cdf984c commit d37780b
Show file tree
Hide file tree
Showing 16 changed files with 1,268 additions and 15 deletions.
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/
25 changes: 13 additions & 12 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: 1 addition & 2 deletions scripts/chiado_genesis_alloc.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
"registrar": "0x6000000000000000000000000000000000000000"
},
"eip1559collector": "0x1559000000000000000000000000000000000000",
"depositContractAddress":
"0x566b8783a28a46dc8d88ebf712303938985e121e"
"depositContractAddress": "0x566b8783a28a46dc8d88ebf712303938985e121e"
},
"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

0 comments on commit d37780b

Please sign in to comment.