Files
reth/crates/transaction-pool/src/test_utils/mod.rs
Thomas Coratger 7c17c6e469 add doc_markdown clippy lint (#8552)
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
2024-06-03 13:21:45 +00:00

93 lines
2.5 KiB
Rust

//! Internal helpers for testing.
use crate::{blobstore::InMemoryBlobStore, noop::MockTransactionValidator, Pool, PoolConfig};
use std::ops::Deref;
mod gen;
pub use gen::*;
mod mock;
pub use mock::*;
mod pool;
/// A [Pool] used for testing
pub type TestPool =
Pool<MockTransactionValidator<MockTransaction>, MockOrdering, InMemoryBlobStore>;
/// Structure encapsulating a [`TestPool`] used for testing
#[derive(Debug, Clone)]
pub struct TestPoolBuilder(TestPool);
impl Default for TestPoolBuilder {
fn default() -> Self {
Self(Pool::new(
MockTransactionValidator::default(),
MockOrdering::default(),
InMemoryBlobStore::default(),
Default::default(),
))
}
}
impl TestPoolBuilder {
/// Returns a new [`TestPoolBuilder`] with a custom validator used for testing purposes
pub fn with_validator(self, validator: MockTransactionValidator<MockTransaction>) -> Self {
Self(Pool::new(
validator,
MockOrdering::default(),
self.pool.blob_store().clone(),
self.pool.config().clone(),
))
}
/// Returns a new [`TestPoolBuilder`] with a custom ordering used for testing purposes
pub fn with_ordering(self, ordering: MockOrdering) -> Self {
Self(Pool::new(
self.pool.validator().clone(),
ordering,
self.pool.blob_store().clone(),
self.pool.config().clone(),
))
}
/// Returns a new [`TestPoolBuilder`] with a custom blob store used for testing purposes
pub fn with_blob_store(self, blob_store: InMemoryBlobStore) -> Self {
Self(Pool::new(
self.pool.validator().clone(),
MockOrdering::default(),
blob_store,
self.pool.config().clone(),
))
}
/// Returns a new [`TestPoolBuilder`] with a custom configuration used for testing purposes
pub fn with_config(self, config: PoolConfig) -> Self {
Self(Pool::new(
self.pool.validator().clone(),
MockOrdering::default(),
self.pool.blob_store().clone(),
config,
))
}
}
impl From<TestPoolBuilder> for TestPool {
fn from(wrapper: TestPoolBuilder) -> Self {
wrapper.0
}
}
impl Deref for TestPoolBuilder {
type Target = TestPool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
/// Returns a new [Pool] with default field values used for testing purposes
pub fn testing_pool() -> TestPool {
TestPoolBuilder::default().into()
}