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

fix(executor): Don't generate a diff when running tests #967

Merged
merged 1 commit into from
Jan 28, 2025
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
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ reqwest = "0.12.12"
async-trait = "0.1.85"
linked_list_allocator = "0.10.5"
rstest = "0.24.0"
tempfile = "3.15.0"

# General
sha2 = { version = "0.10.8", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ alloy-rpc-client.workspace = true
alloy-transport.workspace = true
alloy-transport-http.workspace = true
kona-host.workspace = true
tempfile.workspace = true
7 changes: 4 additions & 3 deletions crates/executor/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,17 @@ mod test {

#[rstest]
#[case::small_block(22884230)]
#[case::small_block_2(22880574)]
#[case::small_block_3(22887258)]
#[case::small_block_2(22884231)]
#[case::small_block_3(22880574)]
#[case::small_block_4(22887258)]
#[case::medium_block(22886464)]
#[case::medium_block_2(22886311)]
#[case::medium_block_3(22880944)]
#[tokio::test]
async fn test_statelessly_execute_block(#[case] block_number: u64) {
let fixture_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("testdata")
.join(format!("block-{block_number}"));
.join(format!("block-{block_number}.tar.gz"));

run_test_fixture(fixture_dir).await;
}
Expand Down
34 changes: 30 additions & 4 deletions crates/executor/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use maili_genesis::RollupConfig;
use maili_registry::ROLLUP_CONFIGS;
use op_alloy_rpc_types_engine::OpPayloadAttributes;
use serde::{Deserialize, Serialize};
use std::{path::PathBuf, sync::Arc};
use std::{env::temp_dir, path::PathBuf, sync::Arc};
use tokio::{fs, runtime::Handle, sync::Mutex};

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -154,7 +154,21 @@ impl ExecutorTestFixtureCreator {
produced_header, executing_header.inner,
"Produced header does not match the expected header"
);
fs::write(fixture_path, serde_json::to_vec(&fixture).unwrap()).await.unwrap();
fs::write(fixture_path.as_path(), serde_json::to_vec(&fixture).unwrap()).await.unwrap();

// Tar the fixture.
let data_dir = fixture_path.parent().unwrap();
tokio::process::Command::new("tar")
.arg("-czf")
.arg(data_dir.with_extension("tar.gz").file_name().unwrap())
.arg(data_dir.file_name().unwrap())
.current_dir(data_dir.parent().unwrap())
.output()
.await
.expect("Failed to tar fixture");

// Remove the leftover directory.
fs::remove_dir_all(data_dir).await.expect("Failed to remove temporary directory");
}
}

Expand Down Expand Up @@ -301,10 +315,22 @@ impl TrieDBProvider for DiskTrieNodeProvider {
/// Executes a [ExecutorTestFixture] stored at the passed `fixture_path` and asserts that the
/// produced block hash matches the expected block hash.
pub(crate) async fn run_test_fixture(fixture_path: PathBuf) {
let kv_store = DiskKeyValueStore::new(fixture_path.join("kv"));
// First, untar the fixture.
let mut fixture_dir = tempfile::tempdir().expect("Failed to create temporary directory");
let untar = tokio::process::Command::new("tar")
.arg("-xvf")
.arg(fixture_path.as_path())
.arg("-C")
.arg(fixture_dir.path())
.arg("--strip-components=1")
.output()
.await
.expect("Failed to untar fixture");

let kv_store = DiskKeyValueStore::new(fixture_dir.path().join("kv"));
let provider = DiskTrieNodeProvider::new(kv_store);
let fixture: ExecutorTestFixture =
serde_json::from_slice(&fs::read(fixture_path.join("fixture.json")).await.unwrap())
serde_json::from_slice(&fs::read(fixture_dir.path().join("fixture.json")).await.unwrap())
.expect("Failed to deserialize fixture");

let mut executor =
Expand Down
Binary file not shown.
1 change: 0 additions & 1 deletion crates/executor/testdata/block-22880574/fixture.json

This file was deleted.

Binary file not shown.
Empty file.
1 change: 0 additions & 1 deletion crates/executor/testdata/block-22880574/kv/CURRENT

This file was deleted.

1 change: 0 additions & 1 deletion crates/executor/testdata/block-22880574/kv/IDENTITY

This file was deleted.

Empty file.
Empty file.
Loading