diff --git a/crates/starknet_mempool/src/mempool_test.rs b/crates/starknet_mempool/src/mempool_test.rs index 95fd7d9d266..0f1b8eb5bcd 100644 --- a/crates/starknet_mempool/src/mempool_test.rs +++ b/crates/starknet_mempool/src/mempool_test.rs @@ -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(); diff --git a/crates/starknet_mempool/src/test_utils.rs b/crates/starknet_mempool/src/test_utils.rs index abdecfcae4a..221c198ed22 100644 --- a/crates/starknet_mempool/src/test_utils.rs +++ b/crates/starknet_mempool/src/test_utils.rs @@ -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] diff --git a/crates/starknet_mempool/tests/flow_test.rs b/crates/starknet_mempool/tests/flow_test.rs index 298dc1159a2..4f52e4e1669 100644 --- a/crates/starknet_mempool/tests/flow_test.rs +++ b/crates/starknet_mempool/tests/flow_test.rs @@ -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))); +}