Skip to content

Commit

Permalink
feat: add tx_pool checker for mempool test
Browse files Browse the repository at this point in the history
- Requires adding accessors to the private tx_pools; these should not be
used outside of our own tests.

- Didn't add a standalone tx_pool checker, can't think of a reason to
  test the pool without the queue (but the reverse is sensible
  somewhat).

- New tester will soon be used to test multi-nonce

commit-id:ba871431
  • Loading branch information
Gilad Chase committed Jul 9, 2024
1 parent af91bff commit 6b28204
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl Mempool {

Ok(())
}

#[cfg(test)]
pub(crate) fn _tx_pool(&self) -> &TransactionPool {
&self.tx_pool
}
}

/// Provides a lightweight representation of a transaction for mempool usage (e.g., excluding
Expand Down
17 changes: 17 additions & 0 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use assert_matches::assert_matches;
use itertools::{enumerate, zip_eq};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -52,6 +54,21 @@ fn mempool() -> Mempool {
Mempool::empty()
}

// TODO(Ayelet): replace with MempoolState checker.
#[track_caller]
fn _check_mempool_state_eq(
mempool: &Mempool,
expected_txs: &[ThinTransaction],
expected_queue: &[ThinTransaction],
) {
check_mempool_queue_eq(mempool, expected_queue);

let expected_txs: HashMap<_, _> =
expected_txs.iter().cloned().map(|tx| (tx.tx_hash, tx)).collect();

assert_eq!(mempool._tx_pool()._tx_pool(), &expected_txs);
}

// Asserts that the transactions in the mempool are in ascending order as per the expected
// transactions.
#[track_caller]
Expand Down
5 changes: 5 additions & 0 deletions crates/mempool/src/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ impl TransactionPool {
) -> Option<&TransactionReference> {
self.txs_by_account.get(address, nonce)
}

#[cfg(test)]
pub(crate) fn _tx_pool(&self) -> &HashMap<TransactionHash, ThinTransaction> {
&self.tx_pool
}
}

#[derive(Debug, Default)]
Expand Down

0 comments on commit 6b28204

Please sign in to comment.