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
12 changes: 0 additions & 12 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/flashblocks/benches/pending_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use alloy_rpc_types_engine::PayloadId;
use base_reth_flashblocks::{
Flashblock, FlashblocksAPI, FlashblocksReceiver, FlashblocksState, Metadata,
};
use base_reth_test_utils::{accounts::TestAccounts, harness::TestHarness, node::LocalNodeProvider};
use base_reth_test_utils::{LocalNodeProvider, TestAccounts, TestHarness};
use criterion::{BatchSize, Criterion, Throughput, criterion_group, criterion_main};
use op_alloy_consensus::OpDepositReceipt;
use reth::{
Expand Down Expand Up @@ -122,7 +122,7 @@ fn pending_state_benches(c: &mut Criterion) {
async fn build_pending_state(input: BenchInput) {
let state = FlashblocksState::new(input.provider, 5);
state.start();
state.on_canonical_block_received(&input.canonical_block);
state.on_canonical_block_received(input.canonical_block);

for flashblock in input.flashblocks {
state.on_flashblock_received(flashblock);
Expand Down
10 changes: 4 additions & 6 deletions crates/flashblocks/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use base_reth_flashblocks::{
Flashblock, FlashblocksAPI, FlashblocksState, Metadata, PendingBlocksAPI,
};
use base_reth_test_utils::{
accounts::TestAccounts,
fixtures::{BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH},
flashblocks_harness::FlashblocksHarness,
node::LocalNodeProvider,
FlashblocksHarness, L1_BLOCK_INFO_DEPOSIT_TX, L1_BLOCK_INFO_DEPOSIT_TX_HASH, LocalNodeProvider,
TestAccounts,
};
use op_alloy_consensus::OpDepositReceipt;
use op_alloy_network::BlockResponse;
Expand Down Expand Up @@ -227,11 +225,11 @@ impl<'a> FlashblockBuilder<'a> {
fn new_base(harness: &'a TestHarness) -> Self {
Self {
canonical_block_number: None,
transactions: vec![BLOCK_INFO_TXN.clone()],
transactions: vec![L1_BLOCK_INFO_DEPOSIT_TX.clone()],
receipts: {
let mut receipts = alloy_primitives::map::HashMap::default();
receipts.insert(
BLOCK_INFO_TXN_HASH,
L1_BLOCK_INFO_DEPOSIT_TX_HASH,
OpReceipt::Deposit(OpDepositReceipt {
inner: Receipt {
status: true.into(),
Expand Down
9 changes: 4 additions & 5 deletions crates/rpc/tests/eth_call_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ use alloy_rpc_types_engine::PayloadId;
use alloy_sol_types::{SolConstructor, SolValue};
use base_reth_flashblocks::{Flashblock, Metadata};
use base_reth_test_utils::{
contracts::{MockERC20, TransparentUpgradeableProxy},
fixtures::{BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH},
flashblocks_harness::FlashblocksHarness,
FlashblocksHarness, L1_BLOCK_INFO_DEPOSIT_TX, L1_BLOCK_INFO_DEPOSIT_TX_HASH, MockERC20,
TransparentUpgradeableProxy,
};
use eyre::Result;
use op_alloy_consensus::OpDepositReceipt;
Expand Down Expand Up @@ -112,15 +111,15 @@ impl Erc20TestSetup {
}),
diff: ExecutionPayloadFlashblockDeltaV1 {
blob_gas_used: Some(0),
transactions: vec![BLOCK_INFO_TXN],
transactions: vec![L1_BLOCK_INFO_DEPOSIT_TX],
..Default::default()
},
metadata: Metadata {
block_number: 1,
receipts: {
let mut receipts = HashMap::default();
receipts.insert(
BLOCK_INFO_TXN_HASH,
L1_BLOCK_INFO_DEPOSIT_TX_HASH,
OpReceipt::Deposit(OpDepositReceipt {
inner: Receipt {
status: true.into(),
Expand Down
8 changes: 3 additions & 5 deletions crates/rpc/tests/flashblocks_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use alloy_rpc_types_engine::PayloadId;
use alloy_rpc_types_eth::{TransactionInput, error::EthRpcErrorCode};
use base_reth_flashblocks::{Flashblock, Metadata};
use base_reth_test_utils::{
contracts::DoubleCounter,
fixtures::{BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH},
flashblocks_harness::FlashblocksHarness,
DoubleCounter, FlashblocksHarness, L1_BLOCK_INFO_DEPOSIT_TX, L1_BLOCK_INFO_DEPOSIT_TX_HASH,
};
use eyre::Result;
use futures_util::{SinkExt, StreamExt};
Expand Down Expand Up @@ -115,15 +113,15 @@ impl TestSetup {
}),
diff: ExecutionPayloadFlashblockDeltaV1 {
blob_gas_used: Some(0),
transactions: vec![BLOCK_INFO_TXN],
transactions: vec![L1_BLOCK_INFO_DEPOSIT_TX],
..Default::default()
},
metadata: Metadata {
block_number: 1,
receipts: {
let mut receipts = HashMap::default();
receipts.insert(
BLOCK_INFO_TXN_HASH,
L1_BLOCK_INFO_DEPOSIT_TX_HASH,
OpReceipt::Deposit(OpDepositReceipt {
inner: Receipt {
status: true.into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/tests/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloy_eips::Encodable2718;
use alloy_genesis::GenesisAccount;
use alloy_primitives::{Address, B256, Bytes, U256, keccak256};
use base_reth_rpc::meter_bundle;
use base_reth_test_utils::fixtures::create_provider_factory;
use base_reth_test_utils::create_provider_factory;
use eyre::Context;
use op_alloy_consensus::OpTxEnvelope;
use rand::{SeedableRng, rngs::StdRng};
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/tests/meter_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloy_eips::Encodable2718;
use alloy_primitives::{Bytes, U256, address, b256, bytes};
use alloy_rpc_client::RpcClient;
use base_reth_rpc::{MeterBundleResponse, MeteringApiImpl, MeteringApiServer};
use base_reth_test_utils::{fixtures::load_genesis, tracing::init_silenced_tracing};
use base_reth_test_utils::{init_silenced_tracing, load_genesis};
use op_alloy_consensus::OpTxEnvelope;
use reth::{
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
Expand Down
18 changes: 0 additions & 18 deletions crates/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ base-reth-rpc.workspace = true
reth.workspace = true
reth-optimism-node.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-cli.workspace = true
reth-optimism-primitives.workspace = true
reth-optimism-rpc = { workspace = true, features = ["client"] }
reth-provider.workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-db.workspace = true
reth-db-common.workspace = true
reth-testing-utils.workspace = true
reth-e2e-test-utils.workspace = true
reth-node-core.workspace = true
reth-exex.workspace = true
Expand All @@ -45,40 +41,30 @@ alloy-contract.workspace = true
alloy-eips.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-consensus.workspace = true
alloy-provider.workspace = true
alloy-rpc-client.workspace = true
alloy-serde.workspace = true
alloy-signer = "1.0"
alloy-signer-local = "1.1.0"

# op-alloy
op-alloy-rpc-types.workspace = true
op-alloy-rpc-types-engine.workspace = true
op-alloy-network.workspace = true
op-alloy-consensus.workspace = true

# rollup-boost
rollup-boost.workspace = true

# tokio
tokio.workspace = true
tokio-stream.workspace = true
tokio-util = { version = "0.7", features = ["compat"] }

# async
futures.workspace = true
futures-util.workspace = true

# rpc
jsonrpsee.workspace = true

# misc
derive_more = { workspace = true, features = ["deref"] }
tracing.workspace = true
tracing-subscriber.workspace = true
serde.workspace = true
serde_json.workspace = true
eyre.workspace = true
once_cell.workspace = true
Expand All @@ -88,8 +74,4 @@ chrono.workspace = true
# tower for middleware
tower = "0.5"


[dev-dependencies]

[package.metadata.cargo-udeps.ignore]
normal = ["reth-optimism-cli"]
74 changes: 42 additions & 32 deletions crates/test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ This crate provides reusable testing utilities for integration tests across the

## Quick Start

```rust
use base_reth_test_utils::harness::TestHarness;
```rust,ignore
use base_reth_test_utils::TestHarness;

#[tokio::test]
async fn test_example() -> eyre::Result<()> {
Expand All @@ -38,7 +38,7 @@ async fn test_example() -> eyre::Result<()> {

The framework follows a three-layer architecture:

```
```text
┌─────────────────────────────────────┐
│ TestHarness │ ← Orchestration layer (tests use this)
│ - Coordinates node + engine │
Expand Down Expand Up @@ -67,8 +67,8 @@ The framework follows a three-layer architecture:

The main entry point for integration tests that only need canonical chain control. Combines node, engine, and accounts into a single interface.

```rust
use base_reth_test_utils::harness::TestHarness;
```rust,ignore
use base_reth_test_utils::TestHarness;
use alloy_primitives::Bytes;

#[tokio::test]
Expand Down Expand Up @@ -116,8 +116,8 @@ async fn test_harness() -> eyre::Result<()> {

In-process Optimism node with Base Sepolia configuration.

```rust
use base_reth_test_utils::node::LocalNode;
```rust,ignore
use base_reth_test_utils::{LocalNode, default_launcher};

#[tokio::test]
async fn test_node() -> eyre::Result<()> {
Expand All @@ -139,8 +139,8 @@ async fn test_node() -> eyre::Result<()> {

For flashblocks-enabled nodes, use `FlashblocksLocalNode`:

```rust
use base_reth_test_utils::node::FlashblocksLocalNode;
```rust,ignore
use base_reth_test_utils::FlashblocksLocalNode;

let node = FlashblocksLocalNode::new().await?;
let pending_state = node.flashblocks_state();
Expand All @@ -153,8 +153,8 @@ node.send_flashblock(flashblock).await?;

Type-safe Engine API client wrapping raw CL operations.

```rust
use base_reth_test_utils::engine::EngineApi;
```rust,ignore
use base_reth_test_utils::EngineApi;
use alloy_primitives::B256;
use op_alloy_rpc_types_engine::OpPayloadAttributes;

Expand All @@ -178,9 +178,8 @@ let status = engine.new_payload(payload, vec![], parent_root, requests).await?;

Hardcoded test accounts with deterministic addresses (Anvil-compatible).

```rust
use base_reth_test_utils::accounts::TestAccounts;
use base_reth_test_utils::harness::TestHarness;
```rust,ignore
use base_reth_test_utils::{TestAccounts, TestHarness};

let accounts = TestAccounts::new();

Expand Down Expand Up @@ -210,8 +209,8 @@ Each account includes:

Use `FlashblocksHarness` when you need `send_flashblock` and access to the in-memory pending state.

```rust
use base_reth_test_utils::flashblocks_harness::FlashblocksHarness;
```rust,ignore
use base_reth_test_utils::FlashblocksHarness;

#[tokio::test]
async fn test_flashblocks() -> eyre::Result<()> {
Expand All @@ -232,28 +231,39 @@ Test flashblocks delivery without WebSocket connections by constructing payloads

## Configuration Constants

Key constants defined in `harness.rs`:

```rust
const BLOCK_TIME_SECONDS: u64 = 2; // Base L2 block time
const GAS_LIMIT: u64 = 200_000_000; // Default gas limit
const NODE_STARTUP_DELAY_MS: u64 = 500; // IPC endpoint initialization
const BLOCK_BUILD_DELAY_MS: u64 = 100; // Payload construction wait
Key constants are exported from the crate root:

```rust,ignore
use base_reth_test_utils::{
BASE_CHAIN_ID, // Chain ID for Base Sepolia (84532)
BLOCK_TIME_SECONDS, // Base L2 block time (2 seconds)
GAS_LIMIT, // Default gas limit (200M)
NODE_STARTUP_DELAY_MS, // IPC endpoint initialization (500ms)
BLOCK_BUILD_DELAY_MS, // Payload construction wait (100ms)
L1_BLOCK_INFO_DEPOSIT_TX, // Pre-captured L1 block info deposit
L1_BLOCK_INFO_DEPOSIT_TX_HASH,
DEFAULT_JWT_SECRET, // All-zeros JWT for local testing
};
```

## File Structure

```
```text
test-utils/
├── src/
│ ├── lib.rs # Public API and re-exports
│ ├── accounts.rs # Test account definitions
│ ├── node.rs # LocalNode (EL wrapper)
│ ├── engine.rs # EngineApi (CL wrapper)
│ ├── lib.rs # Public API and re-exports
│ ├── accounts.rs # Test account definitions
│ ├── constants.rs # Shared constants (chain ID, timing, etc.)
│ ├── contracts.rs # Solidity contract bindings
│ ├── engine.rs # EngineApi (CL wrapper)
│ ├── fixtures.rs # Genesis loading, provider factories
│ ├── flashblocks_harness.rs # FlashblocksHarness + helpers
│ ├── harness.rs # TestHarness (orchestration)
│ └── flashblocks_harness.rs # FlashblocksHarness + helpers
│ ├── node.rs # LocalNode (EL wrapper)
│ └── tracing.rs # Tracing initialization helpers
├── assets/
│ └── genesis.json # Base Sepolia genesis
│ └── genesis.json # Base Sepolia genesis
├── contracts/ # Solidity sources + compiled artifacts
└── Cargo.toml
```

Expand All @@ -268,8 +278,8 @@ base-reth-test-utils.workspace = true

Import in tests:

```rust
use base_reth_test_utils::harness::TestHarness;
```rust,ignore
use base_reth_test_utils::TestHarness;

#[tokio::test]
async fn my_test() -> eyre::Result<()> {
Expand Down
Loading