From 5baaa91f01815f2a7f6382506064f5a1e5831192 Mon Sep 17 00:00:00 2001 From: Aviv Greenburg Date: Thu, 5 Dec 2024 13:06:28 +0200 Subject: [PATCH] chore(blockifier): remove declare.rs deploy_account.rs invoke.rs from blockifier --- .../blockifier/transaction_executor_test.rs | 12 +++--- .../src/concurrency/versioned_state_test.rs | 6 +-- .../src/concurrency/worker_logic_test.rs | 4 +- crates/blockifier/src/test_utils.rs | 3 -- crates/blockifier/src/test_utils/declare.rs | 11 ------ .../src/test_utils/deploy_account.rs | 14 ------- crates/blockifier/src/test_utils/invoke.rs | 8 ---- .../src/test_utils/transfers_generator.rs | 4 +- .../transaction/account_transactions_test.rs | 13 +++---- .../src/transaction/execution_flavors_test.rs | 26 ++++++------- .../blockifier/src/transaction/test_utils.rs | 27 ++++++------- .../src/transaction/transactions_test.rs | 38 +++++++++---------- .../src/starknet_api_test_utils.rs | 4 +- .../src/sequencer_consensus_context_test.rs | 9 ++--- crates/starknet_api/src/test_utils/declare.rs | 11 ++++-- .../src/test_utils/deploy_account.rs | 10 +++-- crates/starknet_api/src/test_utils/invoke.rs | 10 +++-- crates/starknet_batcher/src/test_utils.rs | 6 +-- .../src/transaction_provider_test.rs | 15 ++------ .../stateful_transaction_validator_test.rs | 11 +++--- crates/starknet_mempool/src/test_utils.rs | 5 +-- 21 files changed, 103 insertions(+), 144 deletions(-) delete mode 100644 crates/blockifier/src/test_utils/declare.rs delete mode 100644 crates/blockifier/src/test_utils/deploy_account.rs delete mode 100644 crates/blockifier/src/test_utils/invoke.rs diff --git a/crates/blockifier/src/blockifier/transaction_executor_test.rs b/crates/blockifier/src/blockifier/transaction_executor_test.rs index ab894901e5e..a641efe3d4e 100644 --- a/crates/blockifier/src/blockifier/transaction_executor_test.rs +++ b/crates/blockifier/src/blockifier/transaction_executor_test.rs @@ -1,6 +1,9 @@ use assert_matches::assert_matches; use pretty_assertions::assert_eq; use rstest::rstest; +use starknet_api::test_utils::declare::executable_declare_tx; +use starknet_api::test_utils::deploy_account::executable_deploy_account_tx; +use starknet_api::test_utils::invoke::executable_invoke_tx; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::fields::Fee; use starknet_api::transaction::TransactionVersion; @@ -18,10 +21,7 @@ use crate::context::BlockContext; use crate::state::cached_state::CachedState; use crate::state::state_api::StateReader; use crate::test_utils::contracts::FeatureContract; -use crate::test_utils::declare::declare_tx; -use crate::test_utils::deploy_account::deploy_account_tx; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::invoke::invoke_tx; use crate::test_utils::l1_handler::l1handler_tx; use crate::test_utils::{ create_calldata, @@ -121,7 +121,7 @@ fn test_declare( let declared_contract = FeatureContract::Empty(cairo_version); let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 1)]); - let declare_tx = declare_tx( + let declare_tx = executable_declare_tx( declare_tx_args! { sender_address: account_contract.get_instance_address(0), class_hash: declared_contract.get_class_hash(), @@ -144,7 +144,7 @@ fn test_deploy_account( let account_contract = FeatureContract::AccountWithoutValidations(cairo_version); let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 0)]); - let deploy_account_tx = deploy_account_tx( + let deploy_account_tx = executable_deploy_account_tx( deploy_account_tx_args! { class_hash: account_contract.get_class_hash(), resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()), @@ -219,7 +219,7 @@ fn test_invoke( let calldata = create_calldata(test_contract.get_instance_address(0), entry_point_name, &entry_point_args); - let invoke_tx = invoke_tx(invoke_tx_args! { + let invoke_tx = executable_invoke_tx(invoke_tx_args! { sender_address: account_contract.get_instance_address(0), calldata, version, diff --git a/crates/blockifier/src/concurrency/versioned_state_test.rs b/crates/blockifier/src/concurrency/versioned_state_test.rs index f6c9e5b897f..6611904b59b 100644 --- a/crates/blockifier/src/concurrency/versioned_state_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_test.rs @@ -6,6 +6,7 @@ use assert_matches::assert_matches; use rstest::{fixture, rstest}; use starknet_api::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address}; use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress}; +use starknet_api::test_utils::deploy_account::executable_deploy_account_tx; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::fields::{ContractAddressSalt, ValidResourceBounds}; use starknet_api::{ @@ -40,7 +41,6 @@ use crate::state::cached_state::{ use crate::state::errors::StateError; use crate::state::state_api::{State, StateReader, UpdatableState}; use crate::test_utils::contracts::FeatureContract; -use crate::test_utils::deploy_account::deploy_account_tx; use crate::test_utils::dict_state_reader::DictStateReader; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE}; @@ -226,7 +226,7 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) { let mut state_2 = TransactionalState::create_transactional(&mut versioned_state_proxy_2); // Prepare transactions - let tx = deploy_account_tx( + let tx = executable_deploy_account_tx( deploy_account_tx_args! { class_hash: account_without_validation.get_class_hash(), resource_bounds: l1_resource_bounds( @@ -249,7 +249,7 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) { constructor_calldata: constructor_calldata.clone(), }; let nonce_manager = &mut NonceManager::default(); - let tx = deploy_account_tx(deploy_tx_args, nonce_manager); + let tx = executable_deploy_account_tx(deploy_tx_args, nonce_manager); let delpoy_account_tx_2 = AccountTransaction::new_for_sequencing(tx); let account_address = delpoy_account_tx_2.sender_address(); diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index 55a604223db..d9e92d7ad26 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -4,6 +4,7 @@ use std::sync::Mutex; use rstest::rstest; use starknet_api::abi::abi_utils::get_fee_token_var_address; use starknet_api::core::{ContractAddress, Nonce}; +use starknet_api::test_utils::declare::executable_declare_tx; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::constants::DEPLOY_CONTRACT_FUNCTION_ENTRY_POINT_NAME; use starknet_api::transaction::fields::{ContractAddressSalt, Fee, ValidResourceBounds}; @@ -23,7 +24,6 @@ use crate::fee::fee_utils::get_sequencer_balance_keys; use crate::state::cached_state::StateMaps; use crate::state::state_api::StateReader; use crate::test_utils::contracts::FeatureContract; -use crate::test_utils::declare::declare_tx; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{ create_calldata, @@ -549,7 +549,7 @@ fn test_deploy_before_declare( let test_class_hash = test_contract.get_class_hash(); let test_class_info = calculate_class_info_for_testing(test_contract.get_class()); let test_compiled_class_hash = test_contract.get_compiled_class_hash(); - let declare_tx = AccountTransaction::new_with_default_flags(declare_tx( + let declare_tx = AccountTransaction::new_with_default_flags(executable_declare_tx( declare_tx_args! { sender_address: account_address_0, resource_bounds: default_all_resource_bounds, diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index ddc79c9d53d..0949853591e 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -1,10 +1,7 @@ pub mod cairo_compile; pub mod contracts; -pub mod declare; -pub mod deploy_account; pub mod dict_state_reader; pub mod initial_test_state; -pub mod invoke; pub mod l1_handler; pub mod prices; pub mod struct_impls; diff --git a/crates/blockifier/src/test_utils/declare.rs b/crates/blockifier/src/test_utils/declare.rs deleted file mode 100644 index 5afe538b74b..00000000000 --- a/crates/blockifier/src/test_utils/declare.rs +++ /dev/null @@ -1,11 +0,0 @@ -use starknet_api::contract_class::ClassInfo; -use starknet_api::executable_transaction::AccountTransaction; -use starknet_api::test_utils::declare::{executable_declare_tx, DeclareTxArgs}; - -// TODO(AvivG): remove this func & file. -pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> AccountTransaction { - // TODO(AvivG): see into making 'executable_declare_tx' ret type AccountTransaction. - let declare_tx = executable_declare_tx(declare_tx_args, class_info); - - AccountTransaction::Declare(declare_tx) -} diff --git a/crates/blockifier/src/test_utils/deploy_account.rs b/crates/blockifier/src/test_utils/deploy_account.rs deleted file mode 100644 index 711759ae7fc..00000000000 --- a/crates/blockifier/src/test_utils/deploy_account.rs +++ /dev/null @@ -1,14 +0,0 @@ -use starknet_api::executable_transaction::AccountTransaction; -use starknet_api::test_utils::deploy_account::{executable_deploy_account_tx, DeployAccountTxArgs}; -use starknet_api::test_utils::NonceManager; - -// TODO(AvivG): remove this func & file. -pub fn deploy_account_tx( - deploy_tx_args: DeployAccountTxArgs, - nonce_manager: &mut NonceManager, -) -> AccountTransaction { - // TODO(AvivG): see into making 'executable_deploy_account_tx' ret type AccountTransaction. - let deploy_account_tx = executable_deploy_account_tx(deploy_tx_args, nonce_manager); - - AccountTransaction::DeployAccount(deploy_account_tx) -} diff --git a/crates/blockifier/src/test_utils/invoke.rs b/crates/blockifier/src/test_utils/invoke.rs deleted file mode 100644 index 21a0858d73b..00000000000 --- a/crates/blockifier/src/test_utils/invoke.rs +++ /dev/null @@ -1,8 +0,0 @@ -use starknet_api::executable_transaction::AccountTransaction; -use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; - -// TODO(AvivG): remove this func & file. -pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction { - // TODO(AvivG): see into making 'executable_invoke_tx' ret type AccountTransaction. - AccountTransaction::Invoke(executable_invoke_tx(invoke_args)) -} diff --git a/crates/blockifier/src/test_utils/transfers_generator.rs b/crates/blockifier/src/test_utils/transfers_generator.rs index f66cba4aca2..954caa75d0e 100644 --- a/crates/blockifier/src/test_utils/transfers_generator.rs +++ b/crates/blockifier/src/test_utils/transfers_generator.rs @@ -3,6 +3,7 @@ use rand::{Rng, SeedableRng}; use starknet_api::abi::abi_utils::selector_from_name; use starknet_api::core::ContractAddress; use starknet_api::executable_transaction::AccountTransaction as ApiExecutableTransaction; +use starknet_api::test_utils::invoke::executable_invoke_tx; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::constants::TRANSFER_ENTRY_POINT_NAME; use starknet_api::transaction::fields::Fee; @@ -16,7 +17,6 @@ use crate::context::{BlockContext, ChainInfo}; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::dict_state_reader::DictStateReader; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::invoke::invoke_tx; use crate::test_utils::{CairoVersion, BALANCE, MAX_FEE}; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::transaction_execution::Transaction; @@ -181,7 +181,7 @@ impl TransfersGenerator { felt!(0_u8) // Calldata: msb amount. ]; - invoke_tx(invoke_tx_args! { + executable_invoke_tx(invoke_tx_args! { max_fee: self.config.max_fee, sender_address, calldata: execute_calldata, diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 7d444de7d18..ef84d8fa776 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -20,7 +20,9 @@ use starknet_api::executable_transaction::{ use starknet_api::execution_resources::GasAmount; use starknet_api::hash::StarkHash; use starknet_api::state::StorageKey; -use starknet_api::test_utils::invoke::InvokeTxArgs; +use starknet_api::test_utils::declare::executable_declare_tx; +use starknet_api::test_utils::deploy_account::executable_deploy_account_tx; +use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::constants::TRANSFER_ENTRY_POINT_NAME; use starknet_api::transaction::fields::{ @@ -63,10 +65,7 @@ use crate::fee::gas_usage::estimate_minimal_gas_vector; use crate::state::cached_state::{StateChangesCount, StateChangesCountForFee, TransactionalState}; use crate::state::state_api::{State, StateReader}; use crate::test_utils::contracts::FeatureContract; -use crate::test_utils::declare::declare_tx; -use crate::test_utils::deploy_account::deploy_account_tx; use crate::test_utils::initial_test_state::{fund_account, test_state}; -use crate::test_utils::invoke::invoke_tx; use crate::test_utils::syscall::build_recurse_calldata; use crate::test_utils::{ create_calldata, @@ -194,7 +193,7 @@ fn test_fee_enforcement( ) { let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0); let state = &mut test_state(&block_context.chain_info, BALANCE, &[(account, 1)]); - let tx = deploy_account_tx( + let tx = executable_deploy_account_tx( deploy_account_tx_args! { class_hash: account.get_class_hash(), max_fee: Fee(if zero_bounds { 0 } else { MAX_FEE.0 }), @@ -454,7 +453,7 @@ fn test_max_fee_limit_validate( let class_info = calculate_class_info_for_testing(grindy_validate_account.get_class()); // Declare the grindy-validation account. - let tx = declare_tx( + let tx = executable_declare_tx( declare_tx_args! { class_hash: grindy_class_hash, sender_address: account_address, @@ -1756,7 +1755,7 @@ fn test_revert_in_execute( // Skip validate phase, as we want to test the revert in the execute phase. let validate = false; - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { resource_bounds: default_all_resource_bounds, ..tx_args }); diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index 084c4566b82..bdc60a05f1a 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -4,7 +4,7 @@ use rstest::rstest; use starknet_api::block::FeeType; use starknet_api::core::ContractAddress; use starknet_api::execution_resources::{GasAmount, GasVector}; -use starknet_api::test_utils::invoke::InvokeTxArgs; +use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::fields::{ Calldata, @@ -26,7 +26,6 @@ use crate::state::state_api::StateReader; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::dict_state_reader::DictStateReader; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::invoke::invoke_tx; use crate::test_utils::{ create_calldata, create_trivial_calldata, @@ -223,7 +222,8 @@ fn test_invalid_nonce_pre_validate( // First scenario: invalid nonce. Regardless of flags, should fail. let invalid_nonce = nonce!(7_u8); let account_nonce = state.get_nonce_at(account_address).unwrap(); - let tx = invoke_tx(invoke_tx_args! {nonce: invalid_nonce, ..pre_validation_base_args}); + let tx = + executable_invoke_tx(invoke_tx_args! {nonce: invalid_nonce, ..pre_validation_base_args}); let execution_flags = ExecutionFlags { only_query, charge_fee, validate }; let account_tx = AccountTransaction { tx, execution_flags }; let result = account_tx.execute(&mut state, &block_context); @@ -297,7 +297,7 @@ fn test_simulate_validate_pre_validate_with_charge_fee( // Second scenario: resource bounds greater than balance. let gas_price = block_context.block_info.gas_prices.l1_gas_price(&fee_type); let balance_over_gas_price = BALANCE.checked_div(gas_price).unwrap(); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee: Fee(BALANCE.0 + 1), resource_bounds: l1_resource_bounds( (balance_over_gas_price.0 + 10).into(), @@ -337,7 +337,7 @@ fn test_simulate_validate_pre_validate_with_charge_fee( // Third scenario: L1 gas price bound lower than the price on the block. if !is_deprecated { - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { resource_bounds: l1_resource_bounds(DEFAULT_L1_GAS_AMOUNT, (gas_price.get().0 - 1).into()), nonce: nonce_manager.next(account_address), @@ -380,7 +380,7 @@ fn test_simulate_validate_pre_validate_not_charge_fee( get_pre_validate_test_args(cairo_version, version); let account_address = pre_validation_base_args.sender_address; - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { nonce: nonce_manager.next(account_address), ..pre_validation_base_args.clone() }); @@ -402,7 +402,7 @@ fn test_simulate_validate_pre_validate_not_charge_fee( let (actual_gas_used, actual_fee) = gas_and_fee(base_gas, validate, &fee_type); macro_rules! execute_and_check_gas_and_fee { ($max_fee:expr, $resource_bounds:expr) => {{ - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee: $max_fee, resource_bounds: $resource_bounds, nonce: nonce_manager.next(account_address), @@ -466,7 +466,7 @@ fn execute_fail_validation( } = create_flavors_test_state(&block_context.chain_info, cairo_version); // Validation scenario: fallible validation. - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee, resource_bounds: max_resource_bounds, signature: TransactionSignature(vec![ @@ -597,7 +597,7 @@ fn test_simulate_validate_charge_fee_mid_execution( }; // First scenario: logic error. Should result in revert; actual fee should be shown. - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { calldata: recurse_calldata(test_contract_address, true, 3), nonce: nonce_manager.next(account_address), ..execution_base_args.clone() @@ -646,7 +646,7 @@ fn test_simulate_validate_charge_fee_mid_execution( validate, &fee_type, ); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee: fee_bound, resource_bounds: l1_resource_bounds(gas_bound, gas_price.into()), calldata: recurse_calldata(test_contract_address, false, 1000), @@ -703,7 +703,7 @@ fn test_simulate_validate_charge_fee_mid_execution( &fee_type, ); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee: huge_fee, resource_bounds: l1_resource_bounds(huge_gas_limit, gas_price.into()), calldata: recurse_calldata(test_contract_address, false, 10000), @@ -791,7 +791,7 @@ fn test_simulate_validate_charge_fee_post_execution( validate, &fee_type, ); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee: just_not_enough_fee_bound, resource_bounds: l1_resource_bounds(just_not_enough_gas_bound, gas_price.into()), calldata: recurse_calldata(test_contract_address, false, 1000), @@ -853,7 +853,7 @@ fn test_simulate_validate_charge_fee_post_execution( felt!(0_u8), ], ); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee: actual_fee, resource_bounds: l1_resource_bounds(success_actual_gas, gas_price.into()), calldata: transfer_calldata, diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 4f8f0de2877..03f086454e5 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -4,8 +4,9 @@ use starknet_api::block::{FeeType, GasPrice}; use starknet_api::contract_class::{ClassInfo, ContractClass, SierraVersion}; use starknet_api::core::{ClassHash, ContractAddress, Nonce}; use starknet_api::execution_resources::GasAmount; -use starknet_api::test_utils::deploy_account::DeployAccountTxArgs; -use starknet_api::test_utils::invoke::InvokeTxArgs; +use starknet_api::test_utils::declare::executable_declare_tx; +use starknet_api::test_utils::deploy_account::{executable_deploy_account_tx, DeployAccountTxArgs}; +use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::fields::{ AllResourceBounds, @@ -25,11 +26,8 @@ use crate::context::{BlockContext, ChainInfo}; use crate::state::cached_state::CachedState; use crate::state::state_api::State; use crate::test_utils::contracts::FeatureContract; -use crate::test_utils::declare::declare_tx; -use crate::test_utils::deploy_account::deploy_account_tx; use crate::test_utils::dict_state_reader::DictStateReader; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::invoke::invoke_tx; use crate::test_utils::{ create_calldata, CairoVersion, @@ -113,10 +111,9 @@ pub fn deploy_and_fund_account( deploy_tx_args: DeployAccountTxArgs, ) -> (AccountTransaction, ContractAddress) { // Deploy an account contract. - let deploy_account_tx = AccountTransaction::new_with_default_flags(deploy_account_tx( - deploy_tx_args, - nonce_manager, - )); + let deploy_account_tx = AccountTransaction::new_with_default_flags( + executable_deploy_account_tx(deploy_tx_args, nonce_manager), + ); let account_address = deploy_account_tx.sender_address(); // Update the balance of the about-to-be deployed account contract in the erc20 contract, so it @@ -247,7 +244,7 @@ pub fn create_account_tx_for_validate_test( }; let class_hash = declared_contract.get_class_hash(); let class_info = calculate_class_info_for_testing(declared_contract.get_class()); - let tx = declare_tx( + let tx = executable_declare_tx( declare_tx_args! { max_fee, resource_bounds, @@ -269,7 +266,7 @@ pub fn create_account_tx_for_validate_test( true => constants::FELT_TRUE, false => constants::FELT_FALSE, })]; - let tx = deploy_account_tx( + let tx = executable_deploy_account_tx( deploy_account_tx_args! { max_fee, resource_bounds, @@ -285,7 +282,7 @@ pub fn create_account_tx_for_validate_test( } TransactionType::InvokeFunction => { let execute_calldata = create_calldata(sender_address, "foo", &[]); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { max_fee, resource_bounds, signature, @@ -304,7 +301,7 @@ pub fn create_account_tx_for_validate_test( // TODO(AvivG): Consider removing this function. pub fn account_invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction { let execution_flags = ExecutionFlags::default(); - AccountTransaction { tx: invoke_tx(invoke_args), execution_flags } + AccountTransaction { tx: executable_invoke_tx(invoke_args), execution_flags } } pub fn run_invoke_tx( @@ -312,7 +309,7 @@ pub fn run_invoke_tx( block_context: &BlockContext, invoke_args: InvokeTxArgs, ) -> TransactionExecutionResult { - let tx = invoke_tx(invoke_args); + let tx = executable_invoke_tx(invoke_args); let account_tx = AccountTransaction::new_for_sequencing(tx); account_tx.execute(state, block_context) @@ -385,7 +382,7 @@ pub fn emit_n_events_tx( felt!(0_u32), // data length. ]; let calldata = create_calldata(contract_address, "test_emit_events", &entry_point_args); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { sender_address: account_contract, calldata, nonce diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index fa467cf6025..c641b8dd068 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -19,7 +19,9 @@ use starknet_api::core::{ChainId, ClassHash, ContractAddress, EthAddress, Nonce} use starknet_api::executable_transaction::AccountTransaction as ApiExecutableTransaction; use starknet_api::execution_resources::{GasAmount, GasVector}; use starknet_api::state::StorageKey; -use starknet_api::test_utils::invoke::InvokeTxArgs; +use starknet_api::test_utils::declare::executable_declare_tx; +use starknet_api::test_utils::deploy_account::executable_deploy_account_tx; +use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; use starknet_api::test_utils::NonceManager; use starknet_api::transaction::fields::Resource::{L1DataGas, L1Gas, L2Gas}; use starknet_api::transaction::fields::{ @@ -87,11 +89,8 @@ use crate::state::cached_state::{CachedState, StateChangesCount, TransactionalSt use crate::state::errors::StateError; use crate::state::state_api::{State, StateReader}; use crate::test_utils::contracts::FeatureContract; -use crate::test_utils::declare::declare_tx; -use crate::test_utils::deploy_account::deploy_account_tx; use crate::test_utils::dict_state_reader::DictStateReader; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::invoke::invoke_tx; use crate::test_utils::l1_handler::l1handler_tx; use crate::test_utils::prices::Prices; use crate::test_utils::{ @@ -454,11 +453,12 @@ fn test_invoke_tx( let test_contract_address = test_contract.get_instance_address(0); let account_contract_address = account_contract.get_instance_address(0); let calldata = create_trivial_calldata(test_contract_address); - let invoke_tx = AccountTransaction::new_with_default_flags(invoke_tx(invoke_tx_args! { - sender_address: account_contract_address, - calldata: Calldata(Arc::clone(&calldata.0)), - resource_bounds, - })); + let invoke_tx = + AccountTransaction::new_with_default_flags(executable_invoke_tx(invoke_tx_args! { + sender_address: account_contract_address, + calldata: Calldata(Arc::clone(&calldata.0)), + resource_bounds, + })); // Extract invoke transaction fields for testing, as it is consumed when creating an account // transaction. @@ -971,7 +971,7 @@ fn test_max_fee_exceeds_balance( )}; // Deploy. - let invalid_tx = AccountTransaction::new_with_default_flags(deploy_account_tx( + let invalid_tx = AccountTransaction::new_with_default_flags(executable_deploy_account_tx( deploy_account_tx_args! { resource_bounds, class_hash: test_contract.get_class_hash() @@ -1001,7 +1001,7 @@ fn test_max_fee_exceeds_balance( // Declare. let contract_to_declare = FeatureContract::Empty(CairoVersion::Cairo1); let class_info = calculate_class_info_for_testing(contract_to_declare.get_class()); - let invalid_tx = AccountTransaction::new_with_default_flags(declare_tx( + let invalid_tx = AccountTransaction::new_with_default_flags(executable_declare_tx( declare_tx_args! { class_hash: contract_to_declare.get_class_hash(), compiled_class_hash: contract_to_declare.get_compiled_class_hash(), @@ -1512,7 +1512,7 @@ fn test_declare_tx( None, ExecutionSummary::default(), ); - let account_tx = AccountTransaction::new_with_default_flags(declare_tx( + let account_tx = AccountTransaction::new_with_default_flags(executable_declare_tx( declare_tx_args! { max_fee: MAX_FEE, sender_address, @@ -1632,7 +1632,7 @@ fn test_declare_tx( assert_eq!(contract_class_from_state, class_info.contract_class().try_into().unwrap()); // Checks that redeclaring the same contract fails. - let account_tx2 = AccountTransaction::new_with_default_flags(declare_tx( + let account_tx2 = AccountTransaction::new_with_default_flags(executable_declare_tx( declare_tx_args! { max_fee: MAX_FEE, sender_address, @@ -1666,7 +1666,7 @@ fn test_declare_tx_v0(default_l1_resource_bounds: ValidResourceBounds) { let sender_address = account.get_instance_address(0); let mut nonce_manager = NonceManager::default(); - let tx = declare_tx( + let tx = executable_declare_tx( declare_tx_args! { max_fee: Fee(0), sender_address, @@ -1702,7 +1702,7 @@ fn test_deploy_account_tx( let account = FeatureContract::AccountWithoutValidations(cairo_version); let account_class_hash = account.get_class_hash(); let state = &mut test_state(chain_info, BALANCE, &[(account, 1)]); - let deploy_account = AccountTransaction::new_with_default_flags(deploy_account_tx( + let deploy_account = AccountTransaction::new_with_default_flags(executable_deploy_account_tx( deploy_account_tx_args! { resource_bounds: default_all_resource_bounds, class_hash: account_class_hash @@ -1858,7 +1858,7 @@ fn test_deploy_account_tx( // Negative flow. // Deploy to an existing address. - let deploy_account = AccountTransaction::new_with_default_flags(deploy_account_tx( + let deploy_account = AccountTransaction::new_with_default_flags(executable_deploy_account_tx( deploy_account_tx_args! { resource_bounds: default_all_resource_bounds, class_hash: account_class_hash @@ -1889,7 +1889,7 @@ fn test_fail_deploy_account_undeclared_class_hash( let state = &mut test_state(chain_info, BALANCE, &[]); let mut nonce_manager = NonceManager::default(); let undeclared_hash = class_hash!("0xdeadbeef"); - let deploy_account = AccountTransaction::new_with_default_flags(deploy_account_tx( + let deploy_account = AccountTransaction::new_with_default_flags(executable_deploy_account_tx( deploy_account_tx_args! { resource_bounds: default_all_resource_bounds, class_hash: undeclared_hash }, @@ -2134,7 +2134,7 @@ fn test_valid_flag( &[(account_contract, 1), (test_contract, 1)], ); - let tx = invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { sender_address: account_contract.get_instance_address(0), calldata: create_trivial_calldata(test_contract.get_instance_address(0)), resource_bounds: default_all_resource_bounds, @@ -2237,7 +2237,7 @@ fn test_only_query_flag( .concat() .into(), ); - let tx = crate::test_utils::invoke::invoke_tx(invoke_tx_args! { + let tx = executable_invoke_tx(invoke_tx_args! { calldata: execute_calldata, resource_bounds: default_all_resource_bounds, sender_address, diff --git a/crates/mempool_test_utils/src/starknet_api_test_utils.rs b/crates/mempool_test_utils/src/starknet_api_test_utils.rs index 666cb1720c3..105e06c29a4 100644 --- a/crates/mempool_test_utils/src/starknet_api_test_utils.rs +++ b/crates/mempool_test_utils/src/starknet_api_test_utils.rs @@ -262,9 +262,7 @@ impl AccountTransactionGenerator { calldata: create_trivial_calldata(self.sender_address()), ); - AccountTransaction::Invoke(starknet_api::test_utils::invoke::executable_invoke_tx( - invoke_args, - )) + starknet_api::test_utils::invoke::executable_invoke_tx(invoke_args) } /// Generates an `RpcTransaction` with fully custom parameters. diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs index 3fdb9b16d92..8ac80c7aaff 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs @@ -23,10 +23,7 @@ use papyrus_protobuf::consensus::{ }; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::core::StateDiffCommitment; -use starknet_api::executable_transaction::{ - AccountTransaction, - Transaction as ExecutableTransaction, -}; +use starknet_api::executable_transaction::Transaction as ExecutableTransaction; use starknet_api::hash::PoseidonHash; use starknet_api::test_utils::invoke::{executable_invoke_tx, invoke_tx, InvokeTxArgs}; use starknet_api::transaction::{Transaction, TransactionHash}; @@ -62,10 +59,10 @@ fn generate_invoke_tx() -> Transaction { } fn generate_executable_invoke_tx(tx_hash: Felt) -> ExecutableTransaction { - ExecutableTransaction::Account(AccountTransaction::Invoke(executable_invoke_tx(InvokeTxArgs { + ExecutableTransaction::Account(executable_invoke_tx(InvokeTxArgs { tx_hash: TransactionHash(tx_hash), ..Default::default() - }))) + })) } // Structs which aren't utilized but should not be dropped. diff --git a/crates/starknet_api/src/test_utils/declare.rs b/crates/starknet_api/src/test_utils/declare.rs index 8f905add897..a1c57f88dfe 100644 --- a/crates/starknet_api/src/test_utils/declare.rs +++ b/crates/starknet_api/src/test_utils/declare.rs @@ -2,7 +2,10 @@ use crate::contract_address; use crate::contract_class::ClassInfo; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; -use crate::executable_transaction::DeclareTransaction as ExecutableDeclareTransaction; +use crate::executable_transaction::{ + AccountTransaction, + DeclareTransaction as ExecutableDeclareTransaction, +}; use crate::rpc_transaction::{RpcDeclareTransaction, RpcDeclareTransactionV3, RpcTransaction}; use crate::state::SierraContractClass; use crate::transaction::fields::{ @@ -130,10 +133,12 @@ pub fn declare_tx(declare_tx_args: DeclareTxArgs) -> DeclareTransaction { pub fn executable_declare_tx( declare_tx_args: DeclareTxArgs, class_info: ClassInfo, -) -> ExecutableDeclareTransaction { +) -> AccountTransaction { let tx_hash = declare_tx_args.tx_hash; let tx = declare_tx(declare_tx_args); - ExecutableDeclareTransaction { tx, tx_hash, class_info } + let declare_tx = ExecutableDeclareTransaction { tx, tx_hash, class_info }; + + AccountTransaction::Declare(declare_tx) } pub fn rpc_declare_tx( diff --git a/crates/starknet_api/src/test_utils/deploy_account.rs b/crates/starknet_api/src/test_utils/deploy_account.rs index 8d64aeb6580..5c299f0396f 100644 --- a/crates/starknet_api/src/test_utils/deploy_account.rs +++ b/crates/starknet_api/src/test_utils/deploy_account.rs @@ -1,7 +1,10 @@ use super::NonceManager; use crate::core::{calculate_contract_address, ClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; -use crate::executable_transaction::DeployAccountTransaction as ExecutableDeployAccountTransaction; +use crate::executable_transaction::{ + AccountTransaction, + DeployAccountTransaction as ExecutableDeployAccountTransaction, +}; use crate::rpc_transaction::{ RpcDeployAccountTransaction, RpcDeployAccountTransactionV3, @@ -115,7 +118,7 @@ pub fn deploy_account_tx( pub fn executable_deploy_account_tx( deploy_tx_args: DeployAccountTxArgs, nonce_manager: &mut NonceManager, -) -> ExecutableDeployAccountTransaction { +) -> AccountTransaction { let tx_hash = deploy_tx_args.tx_hash; let contract_address = calculate_contract_address( deploy_tx_args.contract_address_salt, @@ -126,8 +129,9 @@ pub fn executable_deploy_account_tx( .unwrap(); let nonce = nonce_manager.next(contract_address); let tx = deploy_account_tx(deploy_tx_args, nonce); + let deploy_account_tx = ExecutableDeployAccountTransaction { tx, tx_hash, contract_address }; - ExecutableDeployAccountTransaction { tx, tx_hash, contract_address } + AccountTransaction::DeployAccount(deploy_account_tx) } pub fn rpc_deploy_account_tx(deploy_tx_args: DeployAccountTxArgs) -> RpcTransaction { diff --git a/crates/starknet_api/src/test_utils/invoke.rs b/crates/starknet_api/src/test_utils/invoke.rs index 5f0764b4f8e..879df83f421 100644 --- a/crates/starknet_api/src/test_utils/invoke.rs +++ b/crates/starknet_api/src/test_utils/invoke.rs @@ -2,7 +2,10 @@ use crate::abi::abi_utils::selector_from_name; use crate::calldata; use crate::core::{ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; -use crate::executable_transaction::InvokeTransaction as ExecutableInvokeTransaction; +use crate::executable_transaction::{ + AccountTransaction, + InvokeTransaction as ExecutableInvokeTransaction, +}; use crate::rpc_transaction::{RpcInvokeTransaction, RpcInvokeTransactionV3, RpcTransaction}; use crate::transaction::constants::EXECUTE_ENTRY_POINT_NAME; use crate::transaction::fields::{ @@ -116,11 +119,12 @@ pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction { } } -pub fn executable_invoke_tx(invoke_args: InvokeTxArgs) -> ExecutableInvokeTransaction { +pub fn executable_invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction { let tx_hash = invoke_args.tx_hash; let tx = invoke_tx(invoke_args); + let invoke_tx = ExecutableInvokeTransaction { tx, tx_hash }; - ExecutableInvokeTransaction { tx, tx_hash } + AccountTransaction::Invoke(invoke_tx) } pub fn rpc_invoke_tx(invoke_args: InvokeTxArgs) -> RpcTransaction { diff --git a/crates/starknet_batcher/src/test_utils.rs b/crates/starknet_batcher/src/test_utils.rs index b7243cc6ddd..73f251de039 100644 --- a/crates/starknet_batcher/src/test_utils.rs +++ b/crates/starknet_batcher/src/test_utils.rs @@ -4,7 +4,7 @@ use blockifier::blockifier::transaction_executor::VisitedSegmentsMapping; use blockifier::bouncer::BouncerWeights; use blockifier::state::cached_state::CommitmentStateDiff; use indexmap::IndexMap; -use starknet_api::executable_transaction::{AccountTransaction, Transaction}; +use starknet_api::executable_transaction::Transaction; use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; use starknet_api::tx_hash; @@ -13,10 +13,10 @@ use crate::block_builder::BlockExecutionArtifacts; pub fn test_txs(tx_hash_range: Range) -> Vec { tx_hash_range .map(|i| { - Transaction::Account(AccountTransaction::Invoke(executable_invoke_tx(InvokeTxArgs { + Transaction::Account(executable_invoke_tx(InvokeTxArgs { tx_hash: tx_hash!(i), ..Default::default() - }))) + })) }) .collect() } diff --git a/crates/starknet_batcher/src/transaction_provider_test.rs b/crates/starknet_batcher/src/transaction_provider_test.rs index 5cfc69564b2..fc7a5f341f2 100644 --- a/crates/starknet_batcher/src/transaction_provider_test.rs +++ b/crates/starknet_batcher/src/transaction_provider_test.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use assert_matches::assert_matches; use mockall::predicate::eq; use rstest::{fixture, rstest}; -use starknet_api::executable_transaction::{AccountTransaction, L1HandlerTransaction, Transaction}; +use starknet_api::executable_transaction::{L1HandlerTransaction, Transaction}; use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; use starknet_api::tx_hash; use starknet_mempool_types::communication::MockMempoolClient; @@ -38,10 +38,7 @@ impl MockDependencies { fn expect_get_mempool_txs(&mut self, n_to_request: usize) { self.mempool_client.expect_get_txs().with(eq(n_to_request)).returning(move |n_requested| { - Ok(vec![ - AccountTransaction::Invoke(executable_invoke_tx(InvokeTxArgs::default())); - n_requested - ]) + Ok(vec![executable_invoke_tx(InvokeTxArgs::default()); n_requested]) }); } @@ -170,9 +167,7 @@ async fn validate_flow(mut mock_dependencies: MockDependencies) { mock_dependencies .simulate_input_txs(vec![ Transaction::L1Handler(test_tx), - Transaction::Account(AccountTransaction::Invoke(executable_invoke_tx( - InvokeTxArgs::default(), - ))), + Transaction::Account(executable_invoke_tx(InvokeTxArgs::default())), ]) .await; let mut validate_tx_provider = mock_dependencies.validate_tx_provider(); @@ -192,9 +187,7 @@ async fn validate_fails(mut mock_dependencies: MockDependencies) { mock_dependencies .simulate_input_txs(vec![ Transaction::L1Handler(test_tx), - Transaction::Account(AccountTransaction::Invoke(executable_invoke_tx( - InvokeTxArgs::default(), - ))), + Transaction::Account(executable_invoke_tx(InvokeTxArgs::default())), ]) .await; let mut validate_tx_provider = mock_dependencies.validate_tx_provider(); diff --git a/crates/starknet_gateway/src/stateful_transaction_validator_test.rs b/crates/starknet_gateway/src/stateful_transaction_validator_test.rs index ad1210a1ac2..2223e5697dc 100644 --- a/crates/starknet_gateway/src/stateful_transaction_validator_test.rs +++ b/crates/starknet_gateway/src/stateful_transaction_validator_test.rs @@ -109,29 +109,28 @@ fn test_instantiate_validator(stateful_validator: StatefulTransactionValidator) #[rstest] #[case::should_skip_validation( - AccountTransaction::Invoke(executable_invoke_tx(invoke_tx_args!(nonce: nonce!(1)))), + executable_invoke_tx(invoke_tx_args!(nonce: nonce!(1))), nonce!(0), true )] #[case::should_not_skip_validation_nonce_over_max_nonce_for_skip( - AccountTransaction::Invoke(executable_invoke_tx(invoke_tx_args!(nonce: nonce!(0)))), + executable_invoke_tx(invoke_tx_args!(nonce: nonce!(0))), nonce!(0), false )] #[case::should_not_skip_validation_non_invoke( - AccountTransaction::DeployAccount( executable_deploy_account_tx(deploy_account_tx_args!(), &mut NonceManager::default()) - ), + , nonce!(0), false) ] #[case::should_not_skip_validation_account_nonce_1( - AccountTransaction::Invoke(executable_invoke_tx( + executable_invoke_tx( invoke_tx_args!( nonce: nonce!(1), sender_address: TEST_SENDER_ADDRESS.into() ) - )), + ), nonce!(1), false )] diff --git a/crates/starknet_mempool/src/test_utils.rs b/crates/starknet_mempool/src/test_utils.rs index 58bcbfc6f4a..3aeecce28f1 100644 --- a/crates/starknet_mempool/src/test_utils.rs +++ b/crates/starknet_mempool/src/test_utils.rs @@ -20,7 +20,6 @@ macro_rules! tx { max_l2_gas_price: $max_l2_gas_price:expr ) => {{ use starknet_api::block::GasPrice; - use starknet_api::executable_transaction::AccountTransaction; use starknet_api::{invoke_tx_args, tx_hash}; use starknet_api::test_utils::invoke::executable_invoke_tx; use starknet_api::transaction::fields::{ @@ -38,13 +37,13 @@ macro_rules! tx { ..Default::default() }); - AccountTransaction::Invoke(executable_invoke_tx(invoke_tx_args!{ + executable_invoke_tx(invoke_tx_args!{ tx_hash: tx_hash!($tx_hash), sender_address: contract_address!($address), nonce: nonce!($tx_nonce), tip: Tip($tip), resource_bounds, - })) + }) }}; (tx_hash: $tx_hash:expr, address: $address:expr, tx_nonce: $tx_nonce:expr, tip: $tip:expr) => {{ use mempool_test_utils::starknet_api_test_utils::VALID_L2_GAS_MAX_PRICE_PER_UNIT;