Skip to content

Commit eaa45ab

Browse files
fgimenezklkvr
andauthored
test: complete mine block test in e2e testsuite (#14849)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
1 parent 4ed2337 commit eaa45ab

File tree

12 files changed

+490
-258
lines changed

12 files changed

+490
-258
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/e2e-test-utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ reth-network-peers.workspace = true
3333
reth-engine-local.workspace = true
3434
reth-tasks.workspace = true
3535
reth-primitives.workspace = true
36+
reth-node-ethereum.workspace = true
37+
reth-primitives-traits.workspace = true
38+
reth-rpc-builder.workspace = true
3639

3740
revm.workspace = true
3841

crates/e2e-test-utils/src/lib.rs

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//! Utilities for end-to-end tests.
22
33
use node::NodeTestContext;
4-
use reth_chainspec::EthChainSpec;
4+
use reth_chainspec::{ChainSpec, EthChainSpec};
55
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
66
use reth_engine_local::LocalPayloadAttributesBuilder;
77
use reth_network_api::test_utils::PeersHandleProvider;
88
use reth_node_builder::{
99
components::NodeComponentsBuilder,
1010
rpc::{EngineValidatorAddOn, RethRpcAddOns},
1111
EngineNodeLauncher, FullNodeTypesAdapter, Node, NodeAdapter, NodeBuilder, NodeComponents,
12-
NodeConfig, NodeHandle, NodeTypesWithDBAdapter, NodeTypesWithEngine, PayloadAttributesBuilder,
13-
PayloadTypes,
12+
NodeConfig, NodeHandle, NodePrimitives, NodeTypesWithDBAdapter, NodeTypesWithEngine,
13+
PayloadAttributesBuilder, PayloadTypes,
1414
};
1515
use reth_node_core::args::{DiscoveryArgs, NetworkArgs, RpcServerArgs};
1616
use reth_provider::providers::{BlockchainProvider, NodeTypesForProvider};
@@ -44,7 +44,7 @@ pub async fn setup<N>(
4444
num_nodes: usize,
4545
chain_spec: Arc<N::ChainSpec>,
4646
is_dev: bool,
47-
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Copy + 'static,
47+
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Send + Sync + Copy + 'static,
4848
) -> eyre::Result<(Vec<NodeHelperType<N>>, TaskManager, Wallet)>
4949
where
5050
N: Default + Node<TmpNodeAdapter<N>> + NodeTypesForProvider + NodeTypesWithEngine,
@@ -108,29 +108,16 @@ pub async fn setup_engine<N>(
108108
num_nodes: usize,
109109
chain_spec: Arc<N::ChainSpec>,
110110
is_dev: bool,
111-
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Copy + 'static,
111+
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Send + Sync + Copy + 'static,
112112
) -> eyre::Result<(
113113
Vec<NodeHelperType<N, BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>>>,
114114
TaskManager,
115115
Wallet,
116116
)>
117117
where
118-
N: Default
119-
+ Node<TmpNodeAdapter<N, BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>>>
120-
+ NodeTypesWithEngine
121-
+ NodeTypesForProvider,
122-
N::ComponentsBuilder: NodeComponentsBuilder<
123-
TmpNodeAdapter<N, BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>>,
124-
Components: NodeComponents<
125-
TmpNodeAdapter<N, BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>>,
126-
Network: PeersHandleProvider,
127-
>,
128-
>,
129-
N::AddOns: RethRpcAddOns<Adapter<N, BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>>>
130-
+ EngineValidatorAddOn<Adapter<N, BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>>>,
131-
LocalPayloadAttributesBuilder<N::ChainSpec>: PayloadAttributesBuilder<
132-
<<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
133-
>,
118+
N: NodeBuilderHelper,
119+
LocalPayloadAttributesBuilder<N::ChainSpec>:
120+
PayloadAttributesBuilder<<N::Engine as PayloadTypes>::PayloadAttributes>,
134121
{
135122
let tasks = TaskManager::current();
136123
let exec = tasks.executor();
@@ -214,3 +201,74 @@ pub type Adapter<N, Provider = BlockchainProvider<NodeTypesWithDBAdapter<N, TmpD
214201
/// Type alias for a type of `NodeHelper`
215202
pub type NodeHelperType<N, Provider = BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>> =
216203
NodeTestContext<Adapter<N, Provider>, <N as Node<TmpNodeAdapter<N, Provider>>>::AddOns>;
204+
205+
/// Helper trait to simplify bounds when calling setup functions.
206+
pub trait NodeBuilderHelper
207+
where
208+
Self: Default
209+
+ NodeTypesForProvider
210+
+ NodeTypesWithEngine<
211+
Engine: PayloadTypes<
212+
PayloadBuilderAttributes: From<reth_payload_builder::EthPayloadBuilderAttributes>,
213+
>,
214+
> + Node<
215+
TmpNodeAdapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
216+
Primitives: NodePrimitives<
217+
BlockHeader = alloy_consensus::Header,
218+
BlockBody = alloy_consensus::BlockBody<
219+
<Self::Primitives as NodePrimitives>::SignedTx,
220+
>,
221+
>,
222+
ComponentsBuilder: NodeComponentsBuilder<
223+
TmpNodeAdapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
224+
Components: NodeComponents<
225+
TmpNodeAdapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
226+
Network: PeersHandleProvider,
227+
>,
228+
>,
229+
AddOns: RethRpcAddOns<
230+
Adapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
231+
> + EngineValidatorAddOn<
232+
Adapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
233+
>,
234+
ChainSpec: From<ChainSpec> + Clone,
235+
>,
236+
LocalPayloadAttributesBuilder<Self::ChainSpec>:
237+
PayloadAttributesBuilder<<Self::Engine as PayloadTypes>::PayloadAttributes>,
238+
{
239+
}
240+
241+
impl<T> NodeBuilderHelper for T
242+
where
243+
Self: Default
244+
+ NodeTypesForProvider
245+
+ NodeTypesWithEngine<
246+
Engine: PayloadTypes<
247+
PayloadBuilderAttributes: From<reth_payload_builder::EthPayloadBuilderAttributes>,
248+
>,
249+
> + Node<
250+
TmpNodeAdapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
251+
Primitives: NodePrimitives<
252+
BlockHeader = alloy_consensus::Header,
253+
BlockBody = alloy_consensus::BlockBody<
254+
<Self::Primitives as NodePrimitives>::SignedTx,
255+
>,
256+
>,
257+
ComponentsBuilder: NodeComponentsBuilder<
258+
TmpNodeAdapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
259+
Components: NodeComponents<
260+
TmpNodeAdapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
261+
Network: PeersHandleProvider,
262+
>,
263+
>,
264+
AddOns: RethRpcAddOns<
265+
Adapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
266+
> + EngineValidatorAddOn<
267+
Adapter<Self, BlockchainProvider<NodeTypesWithDBAdapter<Self, TmpDB>>>,
268+
>,
269+
ChainSpec: From<ChainSpec> + Clone,
270+
>,
271+
LocalPayloadAttributesBuilder<Self::ChainSpec>:
272+
PayloadAttributesBuilder<<Self::Engine as PayloadTypes>::PayloadAttributes>,
273+
{
274+
}

crates/e2e-test-utils/src/node.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use alloy_rpc_types_engine::ForkchoiceState;
66
use alloy_rpc_types_eth::BlockNumberOrTag;
77
use eyre::Ok;
88
use futures_util::Future;
9+
use jsonrpsee::http_client::{transport::HttpBackend, HttpClient};
910
use reth_chainspec::EthereumHardforks;
1011
use reth_network_api::test_utils::PeersHandleProvider;
1112
use reth_node_api::{
@@ -20,6 +21,7 @@ use reth_provider::{
2021
StageCheckpointReader,
2122
};
2223
use reth_rpc_eth_api::helpers::{EthApiSpec, EthTransactions, TraceExt};
24+
use reth_rpc_layer::AuthClientService;
2325
use reth_stages_types::StageId;
2426
use std::pin::Pin;
2527
use tokio_stream::StreamExt;
@@ -55,7 +57,7 @@ where
5557
/// Creates a new test node
5658
pub async fn new(
5759
node: FullNode<Node, AddOns>,
58-
attributes_generator: impl Fn(u64) -> Engine::PayloadBuilderAttributes + 'static,
60+
attributes_generator: impl Fn(u64) -> Engine::PayloadBuilderAttributes + Send + Sync + 'static,
5961
) -> eyre::Result<Self> {
6062
Ok(Self {
6163
inner: node.clone(),
@@ -293,4 +295,14 @@ where
293295
let addr = self.inner.rpc_server_handle().http_local_addr().unwrap();
294296
format!("http://{}", addr).parse().unwrap()
295297
}
298+
299+
/// Returns an RPC client.
300+
pub fn rpc_client(&self) -> Option<HttpClient> {
301+
self.inner.rpc_server_handle().http_client()
302+
}
303+
304+
/// Returns an Engine API client.
305+
pub fn engine_api_client(&self) -> HttpClient<AuthClientService<HttpBackend>> {
306+
self.inner.auth_server_handle().http_client()
307+
}
296308
}

crates/e2e-test-utils/src/payload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ pub struct PayloadTestContext<T: PayloadTypes> {
1212
payload_builder: PayloadBuilderHandle<T>,
1313
pub timestamp: u64,
1414
#[debug(skip)]
15-
attributes_generator: Box<dyn Fn(u64) -> T::PayloadBuilderAttributes>,
15+
attributes_generator: Box<dyn Fn(u64) -> T::PayloadBuilderAttributes + Send + Sync>,
1616
}
1717

1818
impl<T: PayloadTypes> PayloadTestContext<T> {
1919
/// Creates a new payload helper
2020
pub async fn new(
2121
payload_builder: PayloadBuilderHandle<T>,
22-
attributes_generator: impl Fn(u64) -> T::PayloadBuilderAttributes + 'static,
22+
attributes_generator: impl Fn(u64) -> T::PayloadBuilderAttributes + Send + Sync + 'static,
2323
) -> eyre::Result<Self> {
2424
let payload_events = payload_builder.subscribe().await?;
2525
let payload_event_stream = payload_events.into_stream();

0 commit comments

Comments
 (0)