Skip to main content

reth_transaction_pool/test_utils/
mod.rs

1//! Internal helpers for testing.
2
3use crate::{blobstore::InMemoryBlobStore, noop::MockTransactionValidator, Pool, PoolConfig};
4use std::ops::Deref;
5
6mod tx_gen;
7pub use tx_gen::*;
8
9mod mock;
10pub use mock::*;
11
12mod okvalidator;
13pub use okvalidator::*;
14
15/// A [Pool] used for testing
16pub type TestPool =
17    Pool<MockTransactionValidator<MockTransaction>, MockOrdering, InMemoryBlobStore>;
18
19/// Structure encapsulating a [`TestPool`] used for testing
20#[derive(Debug, Clone)]
21pub struct TestPoolBuilder(TestPool);
22
23impl Default for TestPoolBuilder {
24    fn default() -> Self {
25        Self(Pool::new(
26            MockTransactionValidator::default(),
27            MockOrdering::default(),
28            InMemoryBlobStore::default(),
29            Default::default(),
30        ))
31    }
32}
33
34impl TestPoolBuilder {
35    /// Returns a new [`TestPoolBuilder`] with a custom validator used for testing purposes
36    pub fn with_validator(self, validator: MockTransactionValidator<MockTransaction>) -> Self {
37        Self(Pool::new(
38            validator,
39            MockOrdering::default(),
40            self.pool.blob_store().clone(),
41            self.pool.config().clone(),
42        ))
43    }
44
45    /// Returns a new [`TestPoolBuilder`] with a custom ordering used for testing purposes
46    pub fn with_ordering(self, ordering: MockOrdering) -> Self {
47        Self(Pool::new(
48            self.pool.validator().clone(),
49            ordering,
50            self.pool.blob_store().clone(),
51            self.pool.config().clone(),
52        ))
53    }
54
55    /// Returns a new [`TestPoolBuilder`] with a custom blob store used for testing purposes
56    pub fn with_blob_store(self, blob_store: InMemoryBlobStore) -> Self {
57        Self(Pool::new(
58            self.pool.validator().clone(),
59            MockOrdering::default(),
60            blob_store,
61            self.pool.config().clone(),
62        ))
63    }
64
65    /// Returns a new [`TestPoolBuilder`] with a custom configuration used for testing purposes
66    pub fn with_config(self, config: PoolConfig) -> Self {
67        Self(Pool::new(
68            self.pool.validator().clone(),
69            MockOrdering::default(),
70            self.pool.blob_store().clone(),
71            config,
72        ))
73    }
74}
75
76impl From<TestPoolBuilder> for TestPool {
77    fn from(wrapper: TestPoolBuilder) -> Self {
78        wrapper.0
79    }
80}
81
82impl Deref for TestPoolBuilder {
83    type Target = TestPool;
84
85    fn deref(&self) -> &Self::Target {
86        &self.0
87    }
88}
89
90/// Returns a new [Pool] with default field values used for testing purposes
91pub fn testing_pool() -> TestPool {
92    TestPoolBuilder::default().into()
93}