From 0d452047bb1dddf6992ae1ee792e02add028d121 Mon Sep 17 00:00:00 2001 From: Arnon Hod Date: Tue, 14 Jan 2025 17:42:25 +0200 Subject: [PATCH] chore(starknet_mempool): rename has_tx_from_address to contains_tx_from (#3298) --- crates/starknet_mempool/src/communication.rs | 11 ++++------- crates/starknet_mempool/src/mempool.rs | 2 +- crates/starknet_mempool/src/mempool_test.rs | 4 ++-- crates/starknet_mempool/tests/flow_test.rs | 9 +++++---- crates/starknet_mempool_types/src/communication.rs | 14 +++++++------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/crates/starknet_mempool/src/communication.rs b/crates/starknet_mempool/src/communication.rs index ac0808f906..04b88d6c69 100644 --- a/crates/starknet_mempool/src/communication.rs +++ b/crates/starknet_mempool/src/communication.rs @@ -100,11 +100,8 @@ impl MempoolCommunicationWrapper { self.mempool.get_txs(n_txs) } - pub(crate) fn has_tx_from_address( - &self, - account_address: ContractAddress, - ) -> MempoolResult { - Ok(self.mempool.has_tx_from_address(account_address)) + pub(crate) fn contains_tx_from(&self, account_address: ContractAddress) -> MempoolResult { + Ok(self.mempool.contains_tx_from(account_address)) } } @@ -121,8 +118,8 @@ impl ComponentRequestHandler for MempoolCommuni MempoolRequest::GetTransactions(n_txs) => { MempoolResponse::GetTransactions(self.get_txs(n_txs)) } - MempoolRequest::DeployAccountExists(account_address) => { - MempoolResponse::DeployAccountExists(self.has_tx_from_address(account_address)) + MempoolRequest::ContainsTransactionFrom(account_address) => { + MempoolResponse::ContainsTransactionFrom(self.contains_tx_from(account_address)) } } } diff --git a/crates/starknet_mempool/src/mempool.rs b/crates/starknet_mempool/src/mempool.rs index 59d2e2407e..0e2e534d12 100644 --- a/crates/starknet_mempool/src/mempool.rs +++ b/crates/starknet_mempool/src/mempool.rs @@ -286,7 +286,7 @@ impl Mempool { Ok(()) } - pub fn has_tx_from_address(&self, account_address: ContractAddress) -> bool { + pub fn contains_tx_from(&self, account_address: ContractAddress) -> bool { self.state.get(account_address).is_some() } diff --git a/crates/starknet_mempool/src/mempool_test.rs b/crates/starknet_mempool/src/mempool_test.rs index 452ea8cce5..ff35605df1 100644 --- a/crates/starknet_mempool/src/mempool_test.rs +++ b/crates/starknet_mempool/src/mempool_test.rs @@ -256,7 +256,7 @@ fn mempool() -> Mempool { MempoolContentBuilder::new().build_into_mempool() } -/// Used for the has_tx_from_address tests. +/// Used for the contains_tx_from tests. fn deployer_address() -> ContractAddress { ContractAddress::from(100_u32) } @@ -927,5 +927,5 @@ fn test_rejected_tx_deleted_from_mempool(mut mempool: Mempool) { fn tx_from_address_exists(#[case] state: MempoolState, #[case] expected_result: bool) { let mempool = MempoolContentBuilder::new().with_state(state).build_into_mempool(); - assert_eq!(mempool.has_tx_from_address(deployer_address()), expected_result); + assert_eq!(mempool.contains_tx_from(deployer_address()), expected_result); } diff --git a/crates/starknet_mempool/tests/flow_test.rs b/crates/starknet_mempool/tests/flow_test.rs index 24b2ae1cbc..8df805924d 100644 --- a/crates/starknet_mempool/tests/flow_test.rs +++ b/crates/starknet_mempool/tests/flow_test.rs @@ -307,23 +307,24 @@ fn test_update_gas_price_threshold(mut mempool: Mempool) { 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 +/// Test that the API function [Mempool::contains_tx_from] 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); + let account_address = contract_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))); + assert!(mempool.contains_tx_from(account_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))); + assert!(mempool.contains_tx_from(account_address)); // Test. let nonces = [(address, 1)]; @@ -331,5 +332,5 @@ fn mempool_state_retains_address_across_api_calls(mut mempool: Mempool) { // 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))); + assert!(mempool.contains_tx_from(account_address)); } diff --git a/crates/starknet_mempool_types/src/communication.rs b/crates/starknet_mempool_types/src/communication.rs index 445269c238..9161e1dfd1 100644 --- a/crates/starknet_mempool_types/src/communication.rs +++ b/crates/starknet_mempool_types/src/communication.rs @@ -46,7 +46,7 @@ pub trait MempoolClient: Send + Sync { async fn add_tx(&self, args: AddTransactionArgsWrapper) -> MempoolClientResult<()>; async fn commit_block(&self, args: CommitBlockArgs) -> MempoolClientResult<()>; async fn get_txs(&self, n_txs: usize) -> MempoolClientResult>; - async fn has_tx_from_address( + async fn contains_tx_from( &self, contract_address: ContractAddress, ) -> MempoolClientResult; @@ -57,7 +57,7 @@ pub enum MempoolRequest { AddTransaction(AddTransactionArgsWrapper), CommitBlock(CommitBlockArgs), GetTransactions(usize), - DeployAccountExists(ContractAddress), + ContainsTransactionFrom(ContractAddress), } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -65,7 +65,7 @@ pub enum MempoolResponse { AddTransaction(MempoolResult<()>), CommitBlock(MempoolResult<()>), GetTransactions(MempoolResult>), - DeployAccountExists(MempoolResult), + ContainsTransactionFrom(MempoolResult), } #[derive(Clone, Debug, Error)] @@ -114,14 +114,14 @@ where ) } - async fn has_tx_from_address( + async fn contains_tx_from( &self, - contract_address: ContractAddress, + account_address: ContractAddress, ) -> MempoolClientResult { - let request = MempoolRequest::DeployAccountExists(contract_address); + let request = MempoolRequest::ContainsTransactionFrom(account_address); handle_all_response_variants!( MempoolResponse, - DeployAccountExists, + ContainsTransactionFrom, MempoolClientError, MempoolError, Direct