From 232db3d9db049f6feb94595edc8588fed6c8848e Mon Sep 17 00:00:00 2001 From: Ayelet Zilber <138376632+ayeletstarkware@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:18:31 +0300 Subject: [PATCH] test(mempool): refactor test_tip_priority_over_tx_hash to use mempool state (#446) --- 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 c71195c8..a6af1fa9 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -60,7 +60,7 @@ impl MempoolState { } } - fn _with_queue(queue_txs: Q) -> Self + fn with_queue(queue_txs: Q) -> Self where Q: IntoIterator, { @@ -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]