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