mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
e2e-test: add workspace lint (#9882)
This commit is contained in:
@ -7,6 +7,8 @@ license.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
reth.workspace = true
|
||||
|
||||
@ -17,6 +17,7 @@ use reth_rpc_layer::AuthClientService;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// Helper for engine api operations
|
||||
#[derive(Debug)]
|
||||
pub struct EngineApiTestContext<E> {
|
||||
pub canonical_stream: CanonStateNotificationStream,
|
||||
pub engine_api_client: HttpClient<AuthClientService<HttpBackend>>,
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
//! Utilities for end-to-end tests.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use node::NodeTestContext;
|
||||
@ -110,5 +112,5 @@ type Adapter<N> = NodeAdapter<
|
||||
>>::Components,
|
||||
>;
|
||||
|
||||
/// Type alias for a type of NodeHelper
|
||||
/// Type alias for a type of `NodeHelper`
|
||||
pub type NodeHelperType<N, AO> = NodeTestContext<Adapter<N>, AO>;
|
||||
|
||||
@ -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<NetworkEvent>,
|
||||
network: NetworkHandle,
|
||||
|
||||
@ -24,15 +24,21 @@ use crate::{
|
||||
};
|
||||
|
||||
/// An helper struct to handle node actions
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct NodeTestContext<Node, AddOns>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
AddOns: NodeAddOns<Node>,
|
||||
{
|
||||
/// The core structure representing the full node.
|
||||
pub inner: FullNode<Node, AddOns>,
|
||||
/// Context for testing payload-related features.
|
||||
pub payload: PayloadTestContext<Node::Engine>,
|
||||
/// Context for testing network functionalities.
|
||||
pub network: NetworkTestContext,
|
||||
/// Context for testing the Engine API.
|
||||
pub engine_api: EngineApiTestContext<Node::Engine>,
|
||||
/// Context for testing RPC features.
|
||||
pub rpc: RpcTestContext<Node, AddOns::EthApi>,
|
||||
}
|
||||
|
||||
@ -59,7 +65,7 @@ where
|
||||
}
|
||||
|
||||
/// Establish a connection to the node
|
||||
pub async fn connect(&mut self, node: &mut NodeTestContext<Node, AddOns>) {
|
||||
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;
|
||||
|
||||
@ -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<E: EngineTypes> {
|
||||
pub payload_event_stream: BroadcastStream<Events<E>>,
|
||||
payload_builder: PayloadBuilderHandle<E>,
|
||||
|
||||
@ -9,6 +9,7 @@ use reth::{
|
||||
};
|
||||
use reth_primitives::{Bytes, B256};
|
||||
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct RpcTestContext<Node: FullNodeComponents, EthApi> {
|
||||
pub inner: RpcRegistry<Node, EthApi>,
|
||||
}
|
||||
@ -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<B256, EthApi::Error> {
|
||||
pub async fn inject_tx(&self, raw_tx: Bytes) -> Result<B256, EthApi::Error> {
|
||||
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<TxEnvelope> {
|
||||
pub async fn envelope_by_hash(&self, hash: B256) -> eyre::Result<TxEnvelope> {
|
||||
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())
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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<String>,
|
||||
@ -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<PrivateKeySigner> {
|
||||
let builder = MnemonicBuilder::<English>::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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user