Skip to content

Commit

Permalink
test(mempool): refactor test_add_tx_with_duplicate_tx to use mempool …
Browse files Browse the repository at this point in the history
…state
  • Loading branch information
ayeletstarkware committed Jul 18, 2024
1 parent 6b70786 commit c0cfaa7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Default for MempoolState<PartialState> {
}

impl MempoolState<PartialState> {
fn _with_pool<P>(pool_txs: P) -> Self
fn with_pool<P>(pool_txs: P) -> Self
where
P: IntoIterator<Item = ThinTransaction>,
{
Expand Down Expand Up @@ -298,17 +298,20 @@ fn test_new_with_duplicate_tx() {

#[rstest]
fn test_add_tx_with_duplicate_tx(mut mempool: Mempool) {
// Setup
let input = add_tx_input!(tip: 50, tx_hash: Felt::ONE);
let same_input = input.clone();
let duplicate_input = input.clone();

// Test: assert that the duplicate tx is not added to the mempool.
add_tx(&mut mempool, &input);

assert_matches!(
mempool.add_tx(same_input.clone()),
mempool.add_tx(duplicate_input),
Err(MempoolError::DuplicateTransaction { .. })
);
// Assert that the original tx remains in the pool after the failed attempt.
assert_eq_mempool_queue(&mempool, &[same_input.tx])

// Assert: the original tx remains in Mempool after the failed attempt.
let expected_mempool_state = MempoolState::with_pool([input.tx]);
expected_mempool_state.assert_eq_pool_state(&mempool);
}

#[rstest]
Expand Down

0 comments on commit c0cfaa7

Please sign in to comment.