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 9, 2025
1 parent 8f9b3c3 commit 39f94fd
Show file tree
Hide file tree
Showing 3 changed files with 28 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
21 changes: 21 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,24 @@ 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]);
}

#[rstest]
fn has_tx_from_address(mut mempool: Mempool) {
let address = "0x64";

// Check that has_tx_from_address returns true after add_tx.
let add_tx_args = add_tx_input!(address: address);
add_tx(&mut mempool, &add_tx_args);
assert!(mempool.has_tx_from_address(contract_address!(address)));

// Check that has_tx_from_address returns true after get_txs.
let _txs = mempool.get_txs(1).unwrap();
assert!(mempool.has_tx_from_address(contract_address!(address)));

// Check that has_tx_from_address returns true after commit_block.
// 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.
let nonces = [(address, 1)];
commit_block(&mut mempool, nonces, []);
assert!(mempool.has_tx_from_address(contract_address!(address)));
}

0 comments on commit 39f94fd

Please sign in to comment.