Skip to content

Commit

Permalink
test: checkpoint kurtosis devnet deployment + test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOsiris committed Dec 26, 2024
1 parent 5268032 commit 8700edd
Show file tree
Hide file tree
Showing 15 changed files with 925 additions and 986 deletions.
1,275 changes: 538 additions & 737 deletions world-chain-builder/Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions world-chain-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/worldcoin/world-chain/"
[workspace]
resolver = "2"
members = [
"crates/assertor",
"crates/tests",
"crates/toolkit",
"crates/world/node",
"crates/world/bin",
Expand Down Expand Up @@ -109,7 +109,8 @@ alloy-rpc-types-debug = "0.8.0"
alloy-signer = { version = "0.7.3", default-features = false }
alloy-signer-local = { version = "0.7.3", default-features = false }
alloy-sol-types = "0.8.15"

alloy-provider = { version = "0.7.3", default-features = false }
alloy-transport = { version = "0.7.3", default-features = false }

# revm
revm = { version = "18.0.0", features = ["std"], default-features = false }
Expand Down Expand Up @@ -145,3 +146,4 @@ rand = { version = "0.8", features = ["small_rng"] }
reqwest = { version = "0.12", default-features = false }
bon = "3.3.0"
rayon = "1.10.0"
tracing-subscriber = { version = "0.3.18" }
19 changes: 0 additions & 19 deletions world-chain-builder/crates/assertor/Cargo.toml

This file was deleted.

218 changes: 0 additions & 218 deletions world-chain-builder/crates/assertor/src/main.rs

This file was deleted.

34 changes: 34 additions & 0 deletions world-chain-builder/crates/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "tests"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
# world
world-chain-builder-pool = { workspace = true, features = ["test"] }
world-chain-builder-node = {workspace = true, features = ["test"] }

# alloy
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-transport.workspace = true
alloy-network.workspace = true
alloy-rpc-types-eth.workspace = true

# async
tokio = { workspace = true, features = ["full"] }
futures.workspace = true

# third-party
serde_json.workspace = true
serde.workspace = true
eyre.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"]}
tracing.workspace = true

[lints]
workspace = true
Empty file.
97 changes: 97 additions & 0 deletions world-chain-builder/crates/tests/src/cases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use std::sync::Arc;

use crate::fixtures::PBHFixture;
use alloy_primitives::Bytes;
use alloy_provider::Provider;
use alloy_transport::Transport;
use eyre::eyre::Result;
use futures::stream;
use serde::{Deserialize, Serialize};

const PBH_FIXTURE: &str = include_str!("../../../../devnet/fixtures/fixture.json");

const CONCURRENCY_LIMIT: usize = 50;

/// Asserts that the world-chain-builder payload is built correctly with a set of PBH transactions.
pub async fn assert_build<T, P>(builder_provider: Arc<P>) -> Result<()>
where
T: Transport + Clone,
P: Provider<T>,
{
let fixture = serde_json::from_str::<PBHFixture>(PBH_FIXTURE)?;
let num_transactions = fixture.fixture.len();
let half = num_transactions / 2;
let builder_provider_clone = builder_provider.clone();
stream::iter(fixture.fixture.iter().enumerate())
.map(Ok)
.try_for_each_concurrent(CONCURRENCY_LIMIT, move |(index, transaction)| {
let builder_provider = builder_provider_clone.clone();
async move {
let tx = if index < half {
// First half, use eth_sendRawTransaction
builder_provider.send_raw_transaction(transaction).await?
} else {
// Second half, use eth_sendRawTransactionConditional
let rlp_hex = hex::encode_prefixed(transaction);
let tx_hash = builder_provider
.client()
.request(
"eth_sendRawTransactionConditional",
(rlp_hex, ConditionalOptions::default()),
)
.await?;
PendingTransactionBuilder::new(builder_provider.root().clone(), tx_hash)
};
let hash = *tx.tx_hash();
let receipt = tx.get_receipt().await;
assert!(receipt.is_ok());
debug!(
receipt = ?receipt.unwrap(),
hash = ?hash,
index = index,
"Transaction Receipt Received"
);
Ok::<(), eyre::Report>(())
}
})
.await?;
Ok(())
}

/// Asserts that the chain continues to advance in the case when the world-chain-builder service is MIA.
pub async fn assert_fallback<T, P>(sequencer_provider: P) -> Result<()>
where
T: Transport + Clone,
P: Provider<T>,
{
run_command(
"kurtosis",
&[
"service",
"stop",
"world-chain",
"wc-admin-world-chain-builder",
],
)?;
sleep(Duration::from_secs(5)).await;

// Grab the latest block number
let block_number = sequencer_provider.get_block_number().await?;
let retries = 3;
let mut tries = 0;
loop {
// Assert the chain has progressed
let new_block_number = sequencer_provider.get_block_number().await?;
if new_block_number > block_number {
break;
}

if tries >= retries {
panic!("Chain did not progress after {} retries", retries);
}

sleep(Duration::from_secs(2)).await;
tries += 1;
}
Ok(())
}
Loading

0 comments on commit 8700edd

Please sign in to comment.