reth_engine_tree/
test_utils.rs1use alloy_primitives::B256;
2use reth_chainspec::ChainSpec;
3use reth_ethereum_primitives::BlockBody;
4use reth_network_p2p::test_utils::TestFullBlockClient;
5use reth_primitives_traits::SealedHeader;
6use reth_provider::test_utils::{
7 create_test_provider_factory_with_chain_spec, MockNodeTypesWithDB,
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}
21
22impl TestPipelineBuilder {
23 pub const fn new() -> Self {
25 Self { pipeline_exec_outputs: VecDeque::new() }
26 }
27
28 pub fn with_pipeline_exec_outputs(
30 mut self,
31 pipeline_exec_outputs: VecDeque<Result<ExecOutput, StageError>>,
32 ) -> Self {
33 self.pipeline_exec_outputs = pipeline_exec_outputs;
34 self
35 }
36
37 #[deprecated(
39 note = "no-op: executor results are not used and will be removed in a future release"
40 )]
41 pub fn with_executor_results(
42 self,
43 executor_results: Vec<reth_provider::ExecutionOutcome>,
44 ) -> Self {
45 let _ = executor_results;
46 self
47 }
48
49 pub fn build(self, chain_spec: Arc<ChainSpec>) -> Pipeline<MockNodeTypesWithDB> {
51 reth_tracing::init_test_tracing();
52
53 let (tip_tx, _tip_rx) = watch::channel(B256::default());
55 let pipeline = Pipeline::<MockNodeTypesWithDB>::builder()
56 .add_stages(TestStages::new(self.pipeline_exec_outputs, Default::default()))
57 .with_tip_sender(tip_tx);
58
59 let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec);
60
61 let static_file_producer =
62 StaticFileProducer::new(provider_factory.clone(), PruneModes::default());
63
64 pipeline.build(provider_factory, static_file_producer)
65 }
66}
67
68pub fn insert_headers_into_client(
71 client: &TestFullBlockClient,
72 genesis_header: SealedHeader,
73 range: Range<usize>,
74) {
75 let mut sealed_header = genesis_header;
76 let body = BlockBody::default();
77 for _ in range {
78 let (mut header, hash) = sealed_header.split();
79 header.parent_hash = hash;
81 header.number += 1;
82 header.timestamp += 1;
83 sealed_header = SealedHeader::seal_slow(header);
84 client.insert(sealed_header.clone(), body.clone());
85 }
86}