reth_engine_tree/
test_utils.rs1use alloy_primitives::B256;
2use reth_chainspec::ChainSpec;
3use reth_network_p2p::test_utils::TestFullBlockClient;
4use reth_primitives::{BlockBody, SealedHeader};
5use reth_provider::{
6 test_utils::{create_test_provider_factory_with_chain_spec, MockNodeTypesWithDB},
7 ExecutionOutcome,
8};
9use reth_prune_types::PruneModes;
10use reth_stages::{test_utils::TestStages, ExecOutput, StageError};
11use reth_stages_api::Pipeline;
12use reth_static_file::StaticFileProducer;
13use std::{collections::VecDeque, ops::Range, sync::Arc};
14use tokio::sync::watch;
15
16#[derive(Default, Debug)]
18pub struct TestPipelineBuilder {
19 pipeline_exec_outputs: VecDeque<Result<ExecOutput, StageError>>,
20 executor_results: Vec<ExecutionOutcome>,
21}
22
23impl TestPipelineBuilder {
24 pub const fn new() -> Self {
26 Self { pipeline_exec_outputs: VecDeque::new(), executor_results: Vec::new() }
27 }
28
29 pub fn with_pipeline_exec_outputs(
31 mut self,
32 pipeline_exec_outputs: VecDeque<Result<ExecOutput, StageError>>,
33 ) -> Self {
34 self.pipeline_exec_outputs = pipeline_exec_outputs;
35 self
36 }
37
38 #[allow(dead_code)]
40 pub fn with_executor_results(mut self, executor_results: Vec<ExecutionOutcome>) -> Self {
41 self.executor_results = executor_results;
42 self
43 }
44
45 pub fn build(self, chain_spec: Arc<ChainSpec>) -> Pipeline<MockNodeTypesWithDB> {
47 reth_tracing::init_test_tracing();
48
49 let (tip_tx, _tip_rx) = watch::channel(B256::default());
51 let pipeline = Pipeline::<MockNodeTypesWithDB>::builder()
52 .add_stages(TestStages::new(self.pipeline_exec_outputs, Default::default()))
53 .with_tip_sender(tip_tx);
54
55 let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec);
56
57 let static_file_producer =
58 StaticFileProducer::new(provider_factory.clone(), PruneModes::default());
59
60 pipeline.build(provider_factory, static_file_producer)
61 }
62}
63
64pub fn insert_headers_into_client(
67 client: &TestFullBlockClient,
68 genesis_header: SealedHeader,
69 range: Range<usize>,
70) {
71 let mut sealed_header = genesis_header;
72 let body = BlockBody::default();
73 for _ in range {
74 let (mut header, hash) = sealed_header.split();
75 header.parent_hash = hash;
77 header.number += 1;
78 header.timestamp += 1;
79 sealed_header = SealedHeader::seal(header);
80 client.insert(sealed_header.clone(), body.clone());
81 }
82}