Skip to content

Commit 683bf5f

Browse files
Himessrefcell
andauthored
refactor: consolidate test fixtures into test-utils crate (#260)
* refactor: consolidate test fixtures into test-utils crate - Add fixtures module to test-utils with shared test data - Move BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH constants to fixtures - Move load_genesis() and create_provider_factory() to fixtures - Update flashblocks and rpc tests to use test-utils fixtures - Remove duplicate genesis.json files from flashblocks and rpc - Remove duplicate common modules from test directories Closes #244 * fix(ci): style fix --------- Co-authored-by: refcell <abigger87@gmail.com>
1 parent c40a155 commit 683bf5f

File tree

9 files changed

+28
-237
lines changed

9 files changed

+28
-237
lines changed

crates/flashblocks/tests/assets/genesis.json

Lines changed: 0 additions & 106 deletions
This file was deleted.

crates/flashblocks/tests/common/mod.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

crates/flashblocks/tests/state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Integration tests that stress Flashblocks state handling.
22
3-
mod common;
4-
53
use std::{sync::Arc, time::Duration};
64

75
use alloy_consensus::{Receipt, Transaction};
@@ -12,9 +10,11 @@ use base_reth_flashblocks::{
1210
Flashblock, FlashblocksAPI, FlashblocksState, Metadata, PendingBlocksAPI,
1311
};
1412
use base_reth_test_utils::{
15-
accounts::TestAccounts, flashblocks_harness::FlashblocksHarness, node::LocalNodeProvider,
13+
accounts::TestAccounts,
14+
fixtures::{BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH},
15+
flashblocks_harness::FlashblocksHarness,
16+
node::LocalNodeProvider,
1617
};
17-
use common::{BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH};
1818
use op_alloy_consensus::OpDepositReceipt;
1919
use op_alloy_network::BlockResponse;
2020
use reth::{

crates/rpc/tests/common/genesis.json

Lines changed: 0 additions & 100 deletions
This file was deleted.

crates/rpc/tests/flashblocks_rpc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Integration tests covering the Flashblocks RPC surface area.
22
3-
mod common;
4-
53
use std::str::FromStr;
64

75
use alloy_consensus::{Receipt, Transaction};
@@ -16,8 +14,10 @@ use alloy_rpc_types_engine::PayloadId;
1614
use alloy_rpc_types_eth::{TransactionInput, error::EthRpcErrorCode};
1715
use alloy_sol_macro::sol;
1816
use base_reth_flashblocks::{Flashblock, Metadata};
19-
use base_reth_test_utils::flashblocks_harness::FlashblocksHarness;
20-
use common::{BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH};
17+
use base_reth_test_utils::{
18+
fixtures::{BLOCK_INFO_TXN, BLOCK_INFO_TXN_HASH},
19+
flashblocks_harness::FlashblocksHarness,
20+
};
2121
use eyre::Result;
2222
use futures_util::{SinkExt, StreamExt};
2323
use op_alloy_consensus::OpDepositReceipt;

crates/rpc/tests/meter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Integration tests covering the Metering logic surface area.
2-
mod common;
2+
33
use std::sync::Arc;
44

55
use alloy_consensus::crypto::secp256k1::public_key_to_address;
66
use alloy_eips::Encodable2718;
77
use alloy_genesis::GenesisAccount;
88
use alloy_primitives::{Address, B256, Bytes, U256, keccak256};
99
use base_reth_rpc::meter_bundle;
10-
use common::create_provider_factory;
10+
use base_reth_test_utils::fixtures::create_provider_factory;
1111
use eyre::Context;
1212
use op_alloy_consensus::OpTxEnvelope;
1313
use rand::{SeedableRng, rngs::StdRng};

crates/rpc/tests/meter_rpc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
//! Integration tests covering the Metering RPC surface area.
2-
mod common;
2+
33
use std::{any::Any, net::SocketAddr, sync::Arc};
44

55
use alloy_eips::Encodable2718;
66
use alloy_primitives::{Bytes, U256, address, b256, bytes};
77
use alloy_rpc_client::RpcClient;
88
use base_reth_rpc::{MeterBundleResponse, MeteringApiImpl, MeteringApiServer};
9-
use base_reth_test_utils::tracing::init_silenced_tracing;
10-
use common::load_genesis;
9+
use base_reth_test_utils::{fixtures::load_genesis, tracing::init_silenced_tracing};
1110
use op_alloy_consensus::OpTxEnvelope;
1211
use reth::{
1312
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(dead_code)]
1+
//! Shared fixtures and test data reused by integration tests across the Base codebase.
22
33
use std::sync::Arc;
44

@@ -11,15 +11,23 @@ use reth_db::{
1111
test_utils::{ERROR_DB_CREATION, TempDatabase, create_test_static_files_dir, tempdir_path},
1212
};
1313
use reth_provider::{ProviderFactory, providers::StaticFileProvider};
14-
use serde_json;
1514

16-
pub(crate) const BLOCK_INFO_TXN: Bytes = bytes!(
15+
/// Sample L1 block info transaction used in tests.
16+
pub const BLOCK_INFO_TXN: Bytes = bytes!(
1717
"0x7ef90104a06c0c775b6b492bab9d7e81abdf27f77cafb698551226455a82f559e0f93fea3794deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b8b0098999be000008dd00101c1200000000000000020000000068869d6300000000015f277f000000000000000000000000000000000000000000000000000000000d42ac290000000000000000000000000000000000000000000000000000000000000001abf52777e63959936b1bf633a2a643f0da38d63deffe49452fed1bf8a44975d50000000000000000000000005050f69a9786f081509234f1a7f4684b5e5b76c9000000000000000000000000"
1818
);
19-
pub(crate) const BLOCK_INFO_TXN_HASH: B256 =
19+
20+
/// Hash of the sample L1 block info transaction.
21+
pub const BLOCK_INFO_TXN_HASH: B256 =
2022
b256!("0xba56c8b0deb460ff070f8fca8e2ee01e51a3db27841cc862fdd94cc1a47662b6");
2123

22-
pub(crate) fn create_provider_factory<N: NodeTypes>(
24+
/// Loads the shared test genesis configuration.
25+
pub fn load_genesis() -> Genesis {
26+
serde_json::from_str(include_str!("../assets/genesis.json")).unwrap()
27+
}
28+
29+
/// Creates a provider factory for tests with the given chain spec.
30+
pub fn create_provider_factory<N: NodeTypes>(
2331
chain_spec: Arc<N::ChainSpec>,
2432
) -> ProviderFactory<NodeTypesWithDBAdapter<N, Arc<TempDatabase<DatabaseEnv>>>> {
2533
let (static_dir, _) = create_test_static_files_dir();
@@ -31,10 +39,7 @@ pub(crate) fn create_provider_factory<N: NodeTypes>(
3139
)
3240
}
3341

34-
pub(crate) fn load_genesis() -> Genesis {
35-
serde_json::from_str(include_str!("genesis.json")).unwrap()
36-
}
37-
42+
/// Creates a temporary test database.
3843
fn create_test_db() -> Arc<TempDatabase<DatabaseEnv>> {
3944
let path = tempdir_path();
4045
let emsg = format!("{ERROR_DB_CREATION}: {path:?}");

crates/test-utils/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
pub mod accounts;
66
/// Ergonomic wrapper around the Engine API clients used by the harness.
77
pub mod engine;
8+
/// Shared fixtures and test data reused by integration tests.
9+
pub mod fixtures;
810
/// Flashblocks-aware harness helpers.
911
pub mod flashblocks_harness;
1012
/// High-level façade for interacting with a local Base node.

0 commit comments

Comments
 (0)