From d91ace90799ee0cd48a943abd26abaac9541ef82 Mon Sep 17 00:00:00 2001 From: Ayelet Zilber Date: Thu, 11 Jul 2024 12:35:03 +0300 Subject: [PATCH] test(mempool): refactor test_tip_priority_over_tx_hash to use mempool state --- crates/mempool/src/mempool_test.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index e22b5b3f..d29c338d 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -53,7 +53,7 @@ impl MempoolState { Self { tx_pool: Some(pool_txs.into_iter().collect()), ..Default::default() } } - fn _with_queue(queue_txs: Q) -> Self + fn with_queue(queue_txs: Q) -> Self where Q: IntoIterator, { @@ -339,15 +339,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]