Skip to content

Commit

Permalink
test(starknet_mempool): add case for has_tx_from_address
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Jan 12, 2025
1 parent 4a2851f commit 897120d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 0 additions & 1 deletion crates/starknet_mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ fn test_rejected_tx_deleted_from_mempool(mut mempool: Mempool) {
expected_mempool_content.assert_eq(&mempool);
}

// TODO(Arni): Add positive flow.
#[rstest]
fn has_tx_from_address_negative_flow() {
let mempool = MempoolContentBuilder::new().build_into_mempool();
Expand Down
7 changes: 7 additions & 0 deletions crates/starknet_mempool/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ macro_rules! add_tx_input {
max_l2_gas_price: $max_l2_gas_price
)
};
(address: $address:expr) => {
add_tx_input!(
tx_hash: 0,
address: $address,
tip: 0
)
};
}

#[track_caller]
Expand Down
27 changes: 27 additions & 0 deletions crates/starknet_mempool/tests/flow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,30 @@ fn test_update_gas_price_threshold(mut mempool: Mempool) {
mempool.update_gas_price_threshold(GasPrice(10));
get_txs_and_assert_expected(&mut mempool, 2, &[input_gas_price_20.tx]);
}

/// Test that the API function [Mempool::has_tx_from_address] behaves as expected under various
/// conditions.
#[rstest]
fn mempool_state_retains_address_across_api_calls(mut mempool: Mempool) {
// Setup.
let address = "0x1";
let input_address_1 = add_tx_input!(address: address);

// Test.
add_tx(&mut mempool, &input_address_1);
// Assert: Mempool state includes the address of the added transaction.
assert!(mempool.has_tx_from_address(contract_address!(address)));

// Test.
mempool.get_txs(1).unwrap();
// Assert: The Mempool state still contains the address, even after it was sent to the batcher.
assert!(mempool.has_tx_from_address(contract_address!(address)));

// Test.
let nonces = [(address, 1)];
commit_block(&mut mempool, nonces, []);
// Assert: Mempool state still contains the address, even though the transaction was committed.
// Note that in the future, the Mempool's state may be periodically cleared from records of old
// committed transactions. Mirroring this behavior may require a modification of this test.
assert!(mempool.has_tx_from_address(contract_address!(address)));
}

0 comments on commit 897120d

Please sign in to comment.