Skip to content

Commit

Permalink
test(mempool): refactor test_tip_priority_over_tx_hash to use mempool…
Browse files Browse the repository at this point in the history
… state (#446)
  • Loading branch information
ayeletstarkware authored Jul 25, 2024
1 parent a19df01 commit 232db3d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl MempoolState<PartialState> {
}
}

fn _with_queue<Q>(queue_txs: Q) -> Self
fn with_queue<Q>(queue_txs: Q) -> Self
where
Q: IntoIterator<Item = TransactionReference>,
{
Expand Down Expand Up @@ -347,15 +347,25 @@ fn test_add_tx_with_identical_tip_succeeds(mut mempool: Mempool) {

#[rstest]
fn test_tip_priority_over_tx_hash(mut mempool: Mempool) {
// Setup.
let input_big_tip_small_hash = add_tx_input!(tip: 2, tx_hash: Felt::ONE);

// Create a transaction with identical tip, it should be allowed through since the priority
// queue tie-breaks identical tips by other tx-unique identifiers (for example tx hash).
let input_small_tip_big_hash = add_tx_input!(tip: 1, tx_hash: Felt::TWO, sender_address: "0x1");

// Test.
add_tx(&mut mempool, &input_big_tip_small_hash);
add_tx(&mut mempool, &input_small_tip_big_hash);
assert_eq_mempool_queue(&mempool, &[input_big_tip_small_hash.tx, input_small_tip_big_hash.tx])

// Assert: ensure that the transaction with the higher tip is prioritized higher.
let expected_queue_txs = [
TransactionReference::new(&input_big_tip_small_hash.tx),
TransactionReference::new(&input_small_tip_big_hash.tx),
];
let expected_mempool_state = MempoolState::with_queue(expected_queue_txs);

expected_mempool_state.assert_eq_queue_state(&mempool);
}

#[rstest]
Expand Down

0 comments on commit 232db3d

Please sign in to comment.