Skip to content

Commit

Permalink
test(starknet_mempool): impl test to verify get_txs returns txs sorte…
Browse files Browse the repository at this point in the history
…d by secondary priority on tie (#2728)

Co-Authored-By: Mohammad Nassar <mohammad@starkware.co>
  • Loading branch information
ayeletstarkware and MohammadNassar1 authored Dec 18, 2024
1 parent 52de796 commit 9edbbf5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/starknet_mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn mempool() -> Mempool {
#[case::test_get_exactly_all_eligible_txs(3)]
#[case::test_get_more_than_all_eligible_txs(5)]
#[case::test_get_less_than_all_eligible_txs(2)]
fn test_get_txs_returns_by_priority_order(#[case] n_requested_txs: usize) {
fn test_get_txs_returns_by_priority(#[case] n_requested_txs: usize) {
// Setup.
let tx_tip_20 = tx!(tx_hash: 1, address: "0x0", tip: 20);
let tx_tip_30 = tx!(tx_hash: 2, address: "0x1", tip: 30);
Expand Down Expand Up @@ -248,6 +248,21 @@ fn test_get_txs_returns_by_priority_order(#[case] n_requested_txs: usize) {
expected_mempool_content.assert_eq(&mempool);
}

#[rstest]
fn test_get_txs_returns_by_secondary_priority_on_tie() {
// Setup.
let tx_tip_10_hash_9 = tx!(tx_hash: 9, address: "0x2", tip: 10);
let tx_tip_10_hash_15 = tx!(tx_hash: 15, address: "0x0", tip: 10);

let mut mempool = MempoolContentBuilder::new()
.with_pool([&tx_tip_10_hash_9, &tx_tip_10_hash_15].map(|tx| tx.clone()))
.with_priority_queue([&tx_tip_10_hash_9, &tx_tip_10_hash_15].map(TransactionReference::new))
.build_into_mempool();

// Test and assert.
get_txs_and_assert_expected(&mut mempool, 2, &[tx_tip_10_hash_15, tx_tip_10_hash_9]);
}

#[rstest]
fn test_get_txs_does_not_return_pending_txs() {
// Setup.
Expand Down

0 comments on commit 9edbbf5

Please sign in to comment.