Skip to content

Commit

Permalink
test(mempool): remove genertic type from mempool content (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeletstarkware committed Aug 29, 2024
1 parent 4b87196 commit ac2838a
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@ use crate::transaction_queue::TransactionQueue;

/// Represents the internal content of the mempool.
/// Enables customized (and potentially inconsistent) creation for unit testing.
#[derive(Debug)]
struct MempoolContent<T> {
#[derive(Debug, Default)]
struct MempoolContent {
tx_pool: Option<TransactionPool>,
tx_queue: Option<TransactionQueue>,
account_nonces: Option<AccountToNonce>,
// Artificially use generic type, for the compiler.
_phantom: std::marker::PhantomData<T>,
}

#[derive(Debug)]
struct PartialContent;

impl MempoolContent<PartialContent> {
impl MempoolContent {
fn with_pool_and_queue<P, Q>(pool_txs: P, queue_txs: Q) -> Self
where
P: IntoIterator<Item = Transaction>,
Expand All @@ -47,46 +42,27 @@ impl MempoolContent<PartialContent> {
Self {
tx_pool: Some(pool_txs.into_iter().collect()),
tx_queue: Some(queue_txs.into_iter().collect()),
account_nonces: None,
_phantom: std::marker::PhantomData,
..Self::default()
}
}

fn with_pool<P>(pool_txs: P) -> Self
where
P: IntoIterator<Item = Transaction>,
{
Self {
tx_pool: Some(pool_txs.into_iter().collect()),
tx_queue: None,
account_nonces: None,
_phantom: std::marker::PhantomData,
}
Self { tx_pool: Some(pool_txs.into_iter().collect()), ..Self::default() }
}

fn with_queue<Q>(queue_txs: Q) -> Self
where
Q: IntoIterator<Item = TransactionReference>,
{
Self {
tx_queue: Some(queue_txs.into_iter().collect()),
tx_pool: None,
account_nonces: None,
_phantom: std::marker::PhantomData,
}
Self { tx_queue: Some(queue_txs.into_iter().collect()), ..Self::default() }
}

fn _with_account_nonces(account_nonce_pairs: Vec<(ContractAddress, Nonce)>) -> Self {
Self {
tx_pool: None,
tx_queue: None,
account_nonces: Some(account_nonce_pairs.into_iter().collect()),
_phantom: std::marker::PhantomData,
}
Self { account_nonces: Some(account_nonce_pairs.into_iter().collect()), ..Self::default() }
}
}

impl<T> MempoolContent<T> {
fn assert_eq_pool_and_queue_content(&self, mempool: &Mempool) {
self.assert_eq_pool_content(mempool);
self.assert_eq_queue_content(mempool);
Expand All @@ -105,9 +81,9 @@ impl<T> MempoolContent<T> {
}
}

impl<T> From<MempoolContent<T>> for Mempool {
fn from(mempool_content: MempoolContent<T>) -> Mempool {
let MempoolContent { tx_pool, tx_queue, account_nonces, _phantom: _ } = mempool_content;
impl From<MempoolContent> for Mempool {
fn from(mempool_content: MempoolContent) -> Mempool {
let MempoolContent { tx_pool, tx_queue, account_nonces } = mempool_content;
Mempool {
tx_pool: tx_pool.unwrap_or_default(),
tx_queue: tx_queue.unwrap_or_default(),
Expand Down

0 comments on commit ac2838a

Please sign in to comment.