diff --git a/crates/e2e-test-utils/Cargo.toml b/crates/e2e-test-utils/Cargo.toml index 2136327ac1..7bdbfd885e 100644 --- a/crates/e2e-test-utils/Cargo.toml +++ b/crates/e2e-test-utils/Cargo.toml @@ -7,6 +7,8 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[lints] +workspace = true [dependencies] reth.workspace = true diff --git a/crates/e2e-test-utils/src/engine_api.rs b/crates/e2e-test-utils/src/engine_api.rs index d66bd6135a..728e5764ed 100644 --- a/crates/e2e-test-utils/src/engine_api.rs +++ b/crates/e2e-test-utils/src/engine_api.rs @@ -17,6 +17,7 @@ use reth_rpc_layer::AuthClientService; use std::marker::PhantomData; /// Helper for engine api operations +#[derive(Debug)] pub struct EngineApiTestContext { pub canonical_stream: CanonStateNotificationStream, pub engine_api_client: HttpClient>, diff --git a/crates/e2e-test-utils/src/lib.rs b/crates/e2e-test-utils/src/lib.rs index 5cc6850106..a32fded660 100644 --- a/crates/e2e-test-utils/src/lib.rs +++ b/crates/e2e-test-utils/src/lib.rs @@ -1,3 +1,5 @@ +//! Utilities for end-to-end tests. + use std::sync::Arc; use node::NodeTestContext; @@ -110,5 +112,5 @@ type Adapter = NodeAdapter< >>::Components, >; -/// Type alias for a type of NodeHelper +/// Type alias for a type of `NodeHelper` pub type NodeHelperType = NodeTestContext, AO>; diff --git a/crates/e2e-test-utils/src/network.rs b/crates/e2e-test-utils/src/network.rs index e5791afd76..0570722999 100644 --- a/crates/e2e-test-utils/src/network.rs +++ b/crates/e2e-test-utils/src/network.rs @@ -8,6 +8,7 @@ use reth_tokio_util::EventStream; use reth_tracing::tracing::info; /// Helper for network operations +#[derive(Debug)] pub struct NetworkTestContext { network_events: EventStream, network: NetworkHandle, diff --git a/crates/e2e-test-utils/src/node.rs b/crates/e2e-test-utils/src/node.rs index 05d0a5f978..e985255bbb 100644 --- a/crates/e2e-test-utils/src/node.rs +++ b/crates/e2e-test-utils/src/node.rs @@ -24,15 +24,21 @@ use crate::{ }; /// An helper struct to handle node actions +#[allow(missing_debug_implementations)] pub struct NodeTestContext where Node: FullNodeComponents, AddOns: NodeAddOns, { + /// The core structure representing the full node. pub inner: FullNode, + /// Context for testing payload-related features. pub payload: PayloadTestContext, + /// Context for testing network functionalities. pub network: NetworkTestContext, + /// Context for testing the Engine API. pub engine_api: EngineApiTestContext, + /// Context for testing RPC features. pub rpc: RpcTestContext, } @@ -59,7 +65,7 @@ where } /// Establish a connection to the node - pub async fn connect(&mut self, node: &mut NodeTestContext) { + pub async fn connect(&mut self, node: &mut Self) { self.network.add_peer(node.network.record()).await; node.network.next_session_established().await; self.network.next_session_established().await; @@ -182,14 +188,16 @@ where assert_eq!(latest_block.hash_slow(), expected_block_hash); break } - if wait_finish_checkpoint { - panic!("Finish checkpoint matches, but could not fetch block."); - } + assert!( + !wait_finish_checkpoint, + "Finish checkpoint matches, but could not fetch block." + ); } } Ok(()) } + /// Waits for the node to unwind to the given block number pub async fn wait_unwind(&self, number: BlockNumber) -> eyre::Result<()> { loop { tokio::time::sleep(std::time::Duration::from_millis(10)).await; diff --git a/crates/e2e-test-utils/src/payload.rs b/crates/e2e-test-utils/src/payload.rs index c29eccef92..150c5a5ca6 100644 --- a/crates/e2e-test-utils/src/payload.rs +++ b/crates/e2e-test-utils/src/payload.rs @@ -4,6 +4,7 @@ use reth_payload_builder::{Events, PayloadBuilderHandle, PayloadId}; use tokio_stream::wrappers::BroadcastStream; /// Helper for payload operations +#[derive(Debug)] pub struct PayloadTestContext { pub payload_event_stream: BroadcastStream>, payload_builder: PayloadBuilderHandle, diff --git a/crates/e2e-test-utils/src/rpc.rs b/crates/e2e-test-utils/src/rpc.rs index 77f4b27e21..b301889507 100644 --- a/crates/e2e-test-utils/src/rpc.rs +++ b/crates/e2e-test-utils/src/rpc.rs @@ -9,6 +9,7 @@ use reth::{ }; use reth_primitives::{Bytes, B256}; +#[allow(missing_debug_implementations)] pub struct RpcTestContext { pub inner: RpcRegistry, } @@ -18,13 +19,13 @@ where EthApi: EthApiSpec + EthTransactions + TraceExt, { /// Injects a raw transaction into the node tx pool via RPC server - pub async fn inject_tx(&mut self, raw_tx: Bytes) -> Result { + pub async fn inject_tx(&self, raw_tx: Bytes) -> Result { let eth_api = self.inner.eth_api(); eth_api.send_raw_transaction(raw_tx).await } /// Retrieves a transaction envelope by its hash - pub async fn envelope_by_hash(&mut self, hash: B256) -> eyre::Result { + pub async fn envelope_by_hash(&self, hash: B256) -> eyre::Result { let tx = self.inner.debug_api().raw_transaction(hash).await?.unwrap(); let tx = tx.to_vec(); Ok(TxEnvelope::decode_2718(&mut tx.as_ref()).unwrap()) diff --git a/crates/e2e-test-utils/src/transaction.rs b/crates/e2e-test-utils/src/transaction.rs index 0719c7733e..e2c6a019b3 100644 --- a/crates/e2e-test-utils/src/transaction.rs +++ b/crates/e2e-test-utils/src/transaction.rs @@ -10,6 +10,8 @@ use reth_primitives::{hex, Address, Bytes, U256}; use reth_primitives::B256; +/// Helper for transaction operations +#[derive(Debug)] pub struct TransactionTestContext; impl TransactionTestContext { @@ -43,7 +45,7 @@ impl TransactionTestContext { Ok(signed) } - /// Signs an arbitrary TransactionRequest using the provided wallet + /// Signs an arbitrary [`TransactionRequest`] using the provided wallet pub async fn sign_tx(wallet: PrivateKeySigner, tx: TransactionRequest) -> TxEnvelope { let signer = EthereumWallet::from(wallet); tx.build(&signer).await.unwrap() @@ -59,6 +61,7 @@ impl TransactionTestContext { Ok(signed.encoded_2718().into()) } + /// Creates and encodes an Optimism L1 block information transaction. pub async fn optimism_l1_block_info_tx( chain_id: u64, wallet: PrivateKeySigner, diff --git a/crates/e2e-test-utils/src/wallet.rs b/crates/e2e-test-utils/src/wallet.rs index d24ee2d3f0..c69a9d3fdf 100644 --- a/crates/e2e-test-utils/src/wallet.rs +++ b/crates/e2e-test-utils/src/wallet.rs @@ -2,9 +2,13 @@ use alloy_signer::Signer; use alloy_signer_local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}; /// One of the accounts of the genesis allocations. +#[derive(Debug)] pub struct Wallet { + /// The signer pub inner: PrivateKeySigner, + /// The nonce pub inner_nonce: u64, + /// The chain id pub chain_id: u64, amount: usize, derivation_path: Option, @@ -18,7 +22,7 @@ impl Wallet { } /// Sets chain id - pub fn with_chain_id(mut self, chain_id: u64) -> Self { + pub const fn with_chain_id(mut self, chain_id: u64) -> Self { self.chain_id = chain_id; self } @@ -27,6 +31,7 @@ impl Wallet { self.derivation_path.as_deref().unwrap_or("m/44'/60'/0'/0/") } + /// Generates a list of wallets pub fn gen(&self) -> Vec { let builder = MnemonicBuilder::::default().phrase(TEST_MNEMONIC); @@ -48,6 +53,6 @@ const TEST_MNEMONIC: &str = "test test test test test test test test test test t impl Default for Wallet { fn default() -> Self { - Wallet::new(1) + Self::new(1) } }