From 5511419b0b7350cc9083f915afef6eea49584da4 Mon Sep 17 00:00:00 2001 From: Meshi Peled <141231558+meship-starkware@users.noreply.github.com> Date: Mon, 29 Jul 2024 08:42:28 +0300 Subject: [PATCH] refactor(execution): change get fee token blance in state api to get &self and not &mut self (#134) --- crates/blockifier/src/state/state_api.rs | 2 +- .../src/transaction/execution_flavors_test.rs | 28 ++++++------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/crates/blockifier/src/state/state_api.rs b/crates/blockifier/src/state/state_api.rs index 38096fdcd8..5d3c308e2f 100644 --- a/crates/blockifier/src/state/state_api.rs +++ b/crates/blockifier/src/state/state_api.rs @@ -52,7 +52,7 @@ pub trait StateReader { // TODO(Dori, 1/9/2023): NEW_TOKEN_SUPPORT Determine fee token address based on tx version, // once v3 is introduced. fn get_fee_token_balance( - &mut self, + &self, contract_address: ContractAddress, fee_token_address: ContractAddress, ) -> Result<(Felt, Felt), StateError> { diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index 82cb6e9f47..5bc4acecd6 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -83,7 +83,7 @@ fn create_flavors_test_state( /// Returns the new balance. fn check_balance( current_balance: Felt, - state: &mut CachedState, + state: &CachedState, account_address: ContractAddress, chain_info: &ChainInfo, fee_type: &FeeType, @@ -469,7 +469,7 @@ fn test_simulate_validate_charge_fee_mid_execution( ); let current_balance = check_balance( current_balance, - &mut state, + &state, account_address, &block_context.chain_info, &fee_type, @@ -518,14 +518,8 @@ fn test_simulate_validate_charge_fee_mid_execution( // charged final fee is shown in actual_fee. if charge_fee { limited_fee } else { unlimited_fee }, ); - let current_balance = check_balance( - current_balance, - &mut state, - account_address, - chain_info, - &fee_type, - charge_fee, - ); + let current_balance = + check_balance(current_balance, &state, account_address, chain_info, &fee_type, charge_fee); // Third scenario: only limit is block bounds. Expect resources consumed to be identical, // whether or not `charge_fee` is true. @@ -564,7 +558,7 @@ fn test_simulate_validate_charge_fee_mid_execution( block_limit_fee, block_limit_fee, ); - check_balance(current_balance, &mut state, account_address, chain_info, &fee_type, charge_fee); + check_balance(current_balance, &state, account_address, chain_info, &fee_type, charge_fee); } #[rstest] @@ -652,14 +646,8 @@ fn test_simulate_validate_charge_fee_post_execution( if charge_fee { just_not_enough_fee_bound } else { unlimited_fee }, if charge_fee { revert_fee } else { unlimited_fee }, ); - let current_balance = check_balance( - current_balance, - &mut state, - account_address, - chain_info, - &fee_type, - charge_fee, - ); + let current_balance = + check_balance(current_balance, &state, account_address, chain_info, &fee_type, charge_fee); // Second scenario: balance too low. // Execute a transfer, and make sure we get the expected result. @@ -724,7 +712,7 @@ fn test_simulate_validate_charge_fee_post_execution( ); check_balance( current_balance, - &mut state, + &state, account_address, chain_info, &fee_type,