From af6a7348b469b58db2fe63799f5b0165e36452b4 Mon Sep 17 00:00:00 2001 From: Aviv Greenburg Date: Thu, 5 Dec 2024 13:18:08 +0200 Subject: [PATCH] chore(blockifier): rename fn account_invoke_tx to invoke_tx_with_default_flags --- .../src/concurrency/fee_utils_test.rs | 4 +- .../src/concurrency/worker_logic_test.rs | 18 ++--- .../src/execution/stack_trace_test.rs | 4 +- crates/blockifier/src/fee/fee_test.rs | 8 +-- crates/blockifier/src/fee/gas_usage_test.rs | 6 +- crates/blockifier/src/fee/receipt_test.rs | 6 +- crates/blockifier/src/test_utils/prices.rs | 7 +- .../transaction/account_transactions_test.rs | 36 +++++----- .../src/transaction/execution_flavors_test.rs | 4 +- .../src/transaction/post_execution_test.rs | 4 +- .../blockifier/src/transaction/test_utils.rs | 7 +- .../src/transaction/transactions_test.rs | 70 ++++++++++--------- 12 files changed, 90 insertions(+), 84 deletions(-) diff --git a/crates/blockifier/src/concurrency/fee_utils_test.rs b/crates/blockifier/src/concurrency/fee_utils_test.rs index f136a8f491b..231c4620d44 100644 --- a/crates/blockifier/src/concurrency/fee_utils_test.rs +++ b/crates/blockifier/src/concurrency/fee_utils_test.rs @@ -14,9 +14,9 @@ use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::{fund_account, test_state, test_state_inner}; use crate::test_utils::{create_trivial_calldata, CairoVersion, BALANCE}; use crate::transaction::test_utils::{ - account_invoke_tx, block_context, default_all_resource_bounds, + invoke_tx_with_default_flags, }; #[rstest] @@ -26,7 +26,7 @@ pub fn test_fill_sequencer_balance_reads( #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] erc20_version: CairoVersion, ) { let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account.get_instance_address(0), calldata: create_trivial_calldata(account.get_instance_address(0)), resource_bounds: default_all_resource_bounds, diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index d9e92d7ad26..34af57f2ad9 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -35,10 +35,10 @@ use crate::test_utils::{ use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::objects::HasRelatedFeeType; use crate::transaction::test_utils::{ - account_invoke_tx, calculate_class_info_for_testing, default_all_resource_bounds, emit_n_events_tx, + invoke_tx_with_default_flags, max_fee, }; use crate::transaction::transaction_execution::Transaction; @@ -48,7 +48,7 @@ fn trivial_calldata_invoke_tx( test_contract_address: ContractAddress, nonce: Nonce, ) -> AccountTransaction { - account_invoke_tx(invoke_tx_args! { + invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, calldata: create_trivial_calldata(test_contract_address), resource_bounds: default_all_resource_bounds(), @@ -268,7 +268,7 @@ fn test_worker_execute(default_all_resource_bounds: ValidResourceBounds) { let storage_value = felt!(93_u8); let storage_key = storage_key!(1993_u16); - let tx_success = account_invoke_tx(invoke_tx_args! { + let tx_success = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, calldata: create_calldata( test_contract_address, @@ -281,7 +281,7 @@ fn test_worker_execute(default_all_resource_bounds: ValidResourceBounds) { // Create a transaction with invalid nonce. nonce_manager.rollback(account_address); - let tx_failure = account_invoke_tx(invoke_tx_args! { + let tx_failure = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, calldata: create_calldata( test_contract_address, @@ -293,7 +293,7 @@ fn test_worker_execute(default_all_resource_bounds: ValidResourceBounds) { }); - let tx_revert = account_invoke_tx(invoke_tx_args! { + let tx_revert = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, calldata: create_calldata( test_contract_address, @@ -444,7 +444,7 @@ fn test_worker_validate(default_all_resource_bounds: ValidResourceBounds) { let storage_key = storage_key!(1993_u16); // Both transactions change the same storage key. - let account_tx0 = account_invoke_tx(invoke_tx_args! { + let account_tx0 = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, calldata: create_calldata( test_contract_address, @@ -455,7 +455,7 @@ fn test_worker_validate(default_all_resource_bounds: ValidResourceBounds) { nonce: nonce_manager.next(account_address) }); - let account_tx1 = account_invoke_tx(invoke_tx_args! { + let account_tx1 = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, calldata: create_calldata( test_contract_address, @@ -563,7 +563,7 @@ fn test_deploy_before_declare( )); // Deploy test contract. - let invoke_tx = account_invoke_tx(invoke_tx_args! { + let invoke_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address_1, calldata: create_calldata( account_address_0, @@ -646,7 +646,7 @@ fn test_worker_commit_phase(default_all_resource_bounds: ValidResourceBounds) { let txs = (0..3) .map(|_| { - Transaction::Account(account_invoke_tx(invoke_tx_args! { + Transaction::Account(invoke_tx_with_default_flags(invoke_tx_args! { sender_address, calldata: calldata.clone(), resource_bounds: default_all_resource_bounds, diff --git a/crates/blockifier/src/execution/stack_trace_test.rs b/crates/blockifier/src/execution/stack_trace_test.rs index 5b171d9cffa..ec2238263bc 100644 --- a/crates/blockifier/src/execution/stack_trace_test.rs +++ b/crates/blockifier/src/execution/stack_trace_test.rs @@ -47,10 +47,10 @@ use crate::test_utils::initial_test_state::{fund_account, test_state}; use crate::test_utils::{create_calldata, CairoVersion, BALANCE}; use crate::transaction::account_transaction::{AccountTransaction, ExecutionFlags}; use crate::transaction::test_utils::{ - account_invoke_tx, block_context, create_account_tx_for_validate_test_nonce_0, default_all_resource_bounds, + invoke_tx_with_default_flags, run_invoke_tx, FaultyAccountTxCreatorArgs, INVALID, @@ -752,7 +752,7 @@ fn test_contract_ctor_frame_stack_trace( ) .unwrap(); // Invoke the deploy_contract function on the dummy account to deploy the faulty contract. - let invoke_deploy_tx = account_invoke_tx(invoke_tx_args! { + let invoke_deploy_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, signature, calldata: create_calldata( diff --git a/crates/blockifier/src/fee/fee_test.rs b/crates/blockifier/src/fee/fee_test.rs index 98ad761ef45..2719791e22c 100644 --- a/crates/blockifier/src/fee/fee_test.rs +++ b/crates/blockifier/src/fee/fee_test.rs @@ -33,9 +33,9 @@ use crate::test_utils::{ DEFAULT_STRK_L1_GAS_PRICE, }; use crate::transaction::test_utils::{ - account_invoke_tx, all_resource_bounds, block_context, + invoke_tx_with_default_flags, l1_resource_bounds, }; use crate::utils::u64_from_usize; @@ -195,7 +195,7 @@ fn test_discounted_gas_overdraft( let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0); let mut state = test_state(&block_context.chain_info, BALANCE, &[(account, 1)]); - let tx = account_invoke_tx(invoke_tx_args! { + let tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account.get_instance_address(0), resource_bounds: l1_resource_bounds(gas_bound, (gas_price.get().0 * 10).into()), }); @@ -270,7 +270,7 @@ fn test_post_execution_gas_overdraft_all_resource_bounds( let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0); let mut state = test_state(&block_context.chain_info, BALANCE, &[(account, 1)]); - let tx = account_invoke_tx(invoke_tx_args! { + let tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account.get_instance_address(0), resource_bounds: all_resource_bounds, }); @@ -383,7 +383,7 @@ fn test_initial_sierra_gas( ..Default::default() }), }; - let account_tx = account_invoke_tx(invoke_tx_args!(resource_bounds)); + let account_tx = invoke_tx_with_default_flags(invoke_tx_args!(resource_bounds)); let actual = block_context.to_tx_context(&account_tx).initial_sierra_gas(); assert_eq!(actual, expected) } diff --git a/crates/blockifier/src/fee/gas_usage_test.rs b/crates/blockifier/src/fee/gas_usage_test.rs index 25dfb09958b..f6fe3e315a4 100644 --- a/crates/blockifier/src/fee/gas_usage_test.rs +++ b/crates/blockifier/src/fee/gas_usage_test.rs @@ -28,7 +28,7 @@ use crate::test_utils::{ DEFAULT_ETH_L1_DATA_GAS_PRICE, DEFAULT_ETH_L1_GAS_PRICE, }; -use crate::transaction::test_utils::account_invoke_tx; +use crate::transaction::test_utils::invoke_tx_with_default_flags; use crate::utils::u64_from_usize; use crate::versioned_constants::{ResourceCost, VersionedConstants, VmResourceCosts}; @@ -282,8 +282,8 @@ fn test_get_message_segment_length( #[rstest] fn test_discounted_gas_from_gas_vector_computation() { - let tx_context = - BlockContext::create_for_testing().to_tx_context(&account_invoke_tx(invoke_tx_args! {})); + let tx_context = BlockContext::create_for_testing() + .to_tx_context(&invoke_tx_with_default_flags(invoke_tx_args! {})); let gas_usage = GasVector { l1_gas: 100_u8.into(), l1_data_gas: 2_u8.into(), ..Default::default() }; let actual_result = gas_usage.to_discounted_l1_gas(tx_context.get_gas_prices()); diff --git a/crates/blockifier/src/fee/receipt_test.rs b/crates/blockifier/src/fee/receipt_test.rs index c6ae428f497..86ea2a15fd0 100644 --- a/crates/blockifier/src/fee/receipt_test.rs +++ b/crates/blockifier/src/fee/receipt_test.rs @@ -26,9 +26,9 @@ use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{create_calldata, create_trivial_calldata, CairoVersion, BALANCE}; use crate::transaction::objects::HasRelatedFeeType; use crate::transaction::test_utils::{ - account_invoke_tx, calculate_class_info_for_testing, create_resource_bounds, + invoke_tx_with_default_flags, }; use crate::transaction::transactions::ExecutableTransaction; use crate::utils::{u64_from_usize, usize_from_u64}; @@ -375,7 +375,7 @@ fn test_calculate_tx_gas_usage( let account_contract_address = account_contract.get_instance_address(0); let state = &mut test_state(chain_info, BALANCE, &[(account_contract, 1), (test_contract, 1)]); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_contract_address, calldata: create_trivial_calldata(test_contract.get_instance_address(0)), resource_bounds: max_resource_bounds, @@ -428,7 +428,7 @@ fn test_calculate_tx_gas_usage( ], ); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: max_resource_bounds, sender_address: account_contract_address, calldata: execute_calldata, diff --git a/crates/blockifier/src/test_utils/prices.rs b/crates/blockifier/src/test_utils/prices.rs index 5b8fee66163..0184474f69a 100644 --- a/crates/blockifier/src/test_utils/prices.rs +++ b/crates/blockifier/src/test_utils/prices.rs @@ -15,7 +15,7 @@ use crate::execution::entry_point::{CallEntryPoint, EntryPointExecutionContext}; use crate::state::state_api::State; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::BALANCE; -use crate::transaction::test_utils::account_invoke_tx; +use crate::transaction::test_utils::invoke_tx_with_default_flags; /// Enum for all resource costs. pub enum Prices { @@ -71,7 +71,10 @@ fn fee_transfer_resources( .execute( state, &mut EntryPointExecutionContext::new( - Arc::new(block_context.to_tx_context(&account_invoke_tx(InvokeTxArgs::default()))), + Arc::new( + block_context + .to_tx_context(&invoke_tx_with_default_flags(InvokeTxArgs::default())), + ), ExecutionMode::Execute, false, ), diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index ef84d8fa776..8267351af64 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -89,7 +89,6 @@ use crate::transaction::account_transaction::{ }; use crate::transaction::objects::{HasRelatedFeeType, TransactionInfoCreator}; use crate::transaction::test_utils::{ - account_invoke_tx, all_resource_bounds, block_context, calculate_class_info_for_testing, @@ -99,6 +98,7 @@ use crate::transaction::test_utils::{ default_all_resource_bounds, default_l1_resource_bounds, deploy_and_fund_account, + invoke_tx_with_default_flags, l1_resource_bounds, max_fee, run_invoke_tx, @@ -232,7 +232,7 @@ fn test_all_bounds_combinations_enforce_fee( #[values(0, 1)] l2_gas_bound: u64, ) { let expected_enforce_fee = l1_gas_bound + l1_data_gas_bound + l2_gas_bound > 0; - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { version: TransactionVersion::THREE, resource_bounds: create_all_resource_bounds( l1_gas_bound.into(), @@ -261,7 +261,9 @@ fn test_assert_actual_fee_in_bounds( let actual_fee_offset = Fee(if positive_flow { 0 } else { 1 }); if deprecated_tx { let max_fee = Fee(100); - let tx = account_invoke_tx(invoke_tx_args! { max_fee, version: TransactionVersion::ONE }); + let tx = invoke_tx_with_default_flags( + invoke_tx_args! { max_fee, version: TransactionVersion::ONE }, + ); let context = Arc::new(block_context.to_tx_context(&tx)); AccountTransaction::assert_actual_fee_in_bounds(&context, max_fee + actual_fee_offset); } else { @@ -285,7 +287,7 @@ fn test_assert_actual_fee_in_bounds( for (bounds, actual_fee) in [(all_resource_bounds, all_resource_fee), (l1_resource_bounds, l1_resource_fee)] { - let tx = account_invoke_tx(invoke_tx_args! { + let tx = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: bounds, version: TransactionVersion::THREE, }); @@ -514,7 +516,7 @@ fn test_max_fee_limit_validate( nonce: nonce_manager.next(grindy_account_address) }; - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { // Temporary upper bounds; just for gas estimation. max_fee: MAX_FEE, resource_bounds, @@ -1049,7 +1051,7 @@ fn test_max_fee_computation_from_tx_bounds(block_context: BlockContext) { // V1 transaction: limit based on max fee. // Convert max fee to L1 gas units, and then to steps. let max_fee = Fee(100); - let account_tx_max_fee = account_invoke_tx(invoke_tx_args! { + let account_tx_max_fee = invoke_tx_with_default_flags(invoke_tx_args! { max_fee, version: TransactionVersion::ONE }); let steps_per_l1_gas = block_context.versioned_constants.vm_resource_fee_cost().n_steps.inv(); @@ -1066,7 +1068,7 @@ fn test_max_fee_computation_from_tx_bounds(block_context: BlockContext) { // V3 transaction: limit based on L1 gas bounds. // Convert L1 gas units to steps. let l1_gas_bound = 200_u64; - let account_tx_l1_bounds = account_invoke_tx(invoke_tx_args! { + let account_tx_l1_bounds = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: l1_resource_bounds(l1_gas_bound.into(), 1_u8.into()), version: TransactionVersion::THREE }); @@ -1078,7 +1080,7 @@ fn test_max_fee_computation_from_tx_bounds(block_context: BlockContext) { // V3 transaction: limit based on L2 gas bounds (all resource_bounds). // Convert L2 gas units to steps. let l2_gas_bound = 300_u64; - let account_tx_l2_bounds = account_invoke_tx(invoke_tx_args! { + let account_tx_l2_bounds = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: ValidResourceBounds::AllResources(AllResourceBounds { l2_gas: ResourceBounds { max_amount: l2_gas_bound.into(), @@ -1119,7 +1121,7 @@ fn test_max_fee_to_max_steps_conversion( ); // First invocation of `with_arg` gets the exact pre-calculated actual fee as max_fee. - let account_tx1 = account_invoke_tx(invoke_tx_args! { + let account_tx1 = invoke_tx_with_default_flags(invoke_tx_args! { max_fee: Fee(actual_fee), sender_address: account_address, calldata: execute_calldata.clone(), @@ -1139,7 +1141,7 @@ fn test_max_fee_to_max_steps_conversion( ); // Second invocation of `with_arg` gets twice the pre-calculated actual fee as max_fee. - let account_tx2 = account_invoke_tx(invoke_tx_args! { + let account_tx2 = invoke_tx_with_default_flags(invoke_tx_args! { max_fee: Fee(2 * actual_fee), sender_address: account_address, calldata: execute_calldata, @@ -1362,7 +1364,7 @@ fn test_count_actual_storage_changes( calldata: write_1_calldata, nonce: nonce_manager.next(account_address), }; - let account_tx = account_invoke_tx(invoke_args.clone()); + let account_tx = invoke_tx_with_default_flags(invoke_args.clone()); let concurrency_mode = false; let execution_info = account_tx.execute_raw(&mut state, &block_context, concurrency_mode).unwrap(); @@ -1408,7 +1410,7 @@ fn test_count_actual_storage_changes( // Second transaction: storage cell starts and ends with value 1. let mut state = TransactionalState::create_transactional(&mut state); - let account_tx = account_invoke_tx(InvokeTxArgs { + let account_tx = invoke_tx_with_default_flags(InvokeTxArgs { nonce: nonce_manager.next(account_address), ..invoke_args.clone() }); @@ -1448,7 +1450,7 @@ fn test_count_actual_storage_changes( // Transfer transaction: transfer 1 ETH to recepient. let mut state = TransactionalState::create_transactional(&mut state); - let account_tx = account_invoke_tx(InvokeTxArgs { + let account_tx = invoke_tx_with_default_flags(InvokeTxArgs { nonce: nonce_manager.next(account_address), calldata: transfer_calldata, ..invoke_args @@ -1520,7 +1522,7 @@ fn test_concurrency_execute_fee_transfer( let state = &mut test_state(chain_info, BALANCE, &[(account, 1), (test_contract, 1)]); let (sequencer_balance_key_low, sequencer_balance_key_high) = get_sequencer_balance_keys(&block_context); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account.get_instance_address(0), max_fee, calldata: create_trivial_calldata(test_contract.get_instance_address(0)), @@ -1566,7 +1568,7 @@ fn test_concurrency_execute_fee_transfer( let mut transactional_state = TransactionalState::create_transactional(state); // Invokes transfer to the sequencer. - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account.get_instance_address(0), calldata: transfer_calldata, max_fee, @@ -1617,7 +1619,7 @@ fn test_concurrent_fee_transfer_when_sender_is_sequencer( let state = &mut test_state(chain_info, sender_balance, &[(account, 1), (test_contract, 1)]); let (sequencer_balance_key_low, sequencer_balance_key_high) = get_sequencer_balance_keys(&block_context); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { max_fee, sender_address: account_address, calldata: create_trivial_calldata(test_contract.get_instance_address(0)), @@ -1669,7 +1671,7 @@ fn test_initial_gas( sender_balance, &contracts.into_iter().map(|contract| (contract, 1u16)).collect::>(), ); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_address, calldata: build_recurse_calldata(versions), resource_bounds: default_all_resource_bounds, diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index bdc60a05f1a..e13abc1a1df 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -45,8 +45,8 @@ use crate::transaction::errors::{ }; use crate::transaction::objects::{TransactionExecutionInfo, TransactionExecutionResult}; use crate::transaction::test_utils::{ - account_invoke_tx, default_l1_resource_bounds, + invoke_tx_with_default_flags, l1_resource_bounds, INVALID, }; @@ -263,7 +263,7 @@ fn test_simulate_validate_pre_validate_with_charge_fee( let account_address = pre_validation_base_args.sender_address; // First scenario: minimal fee not covered. Actual fee is precomputed. - let err = account_invoke_tx(invoke_tx_args! { + let err = invoke_tx_with_default_flags(invoke_tx_args! { max_fee: Fee(10), resource_bounds: l1_resource_bounds(10_u8.into(), 10_u8.into()), nonce: nonce_manager.next(account_address), diff --git a/crates/blockifier/src/transaction/post_execution_test.rs b/crates/blockifier/src/transaction/post_execution_test.rs index ed8e3df15bb..8718ee7bb96 100644 --- a/crates/blockifier/src/transaction/post_execution_test.rs +++ b/crates/blockifier/src/transaction/post_execution_test.rs @@ -34,11 +34,11 @@ use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::errors::TransactionExecutionError; use crate::transaction::objects::{HasRelatedFeeType, TransactionInfoCreator}; use crate::transaction::test_utils::{ - account_invoke_tx, block_context, create_all_resource_bounds, default_all_resource_bounds, default_l1_resource_bounds, + invoke_tx_with_default_flags, l1_resource_bounds, max_fee, run_invoke_tx, @@ -125,7 +125,7 @@ fn test_revert_on_overdraft( ], ); - let approve_tx: AccountTransaction = account_invoke_tx(invoke_tx_args! { + let approve_tx: AccountTransaction = invoke_tx_with_default_flags(invoke_tx_args! { max_fee, sender_address: account_address, calldata: approve_calldata, diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 03f086454e5..e96327f2ba7 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -298,10 +298,9 @@ 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: executable_invoke_tx(invoke_args), execution_flags } +pub fn invoke_tx_with_default_flags(invoke_args: InvokeTxArgs) -> AccountTransaction { + let tx = executable_invoke_tx(invoke_args); + AccountTransaction::new_with_default_flags(tx) } pub fn run_invoke_tx( diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index c641b8dd068..80450355b94 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -128,7 +128,6 @@ use crate::transaction::objects::{ TransactionInfoCreator, }; use crate::transaction::test_utils::{ - account_invoke_tx, block_context, calculate_class_info_for_testing, create_account_tx_for_validate_test, @@ -136,6 +135,7 @@ use crate::transaction::test_utils::{ create_all_resource_bounds, default_all_resource_bounds, default_l1_resource_bounds, + invoke_tx_with_default_flags, l1_resource_bounds, FaultyAccountTxCreatorArgs, CALL_CONTRACT, @@ -453,12 +453,11 @@ 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(executable_invoke_tx(invoke_tx_args! { - sender_address: account_contract_address, - calldata: Calldata(Arc::clone(&calldata.0)), - resource_bounds, - })); + let invoke_tx = invoke_tx_with_default_flags(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. @@ -674,7 +673,7 @@ fn test_invoke_tx_advanced_operations( let initial_counters = [felt!(counter_diffs[0]), felt!(counter_diffs[1])]; let calldata_args = vec![index, initial_counters[0], initial_counters[1]]; - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { nonce: nonce_manager.next(account_address), calldata: create_calldata(contract_address, "advance_counter", &calldata_args), @@ -699,7 +698,7 @@ fn test_invoke_tx_advanced_operations( let calldata_args = vec![*contract_address.0.key(), index, felt!(xor_values[0]), felt!(xor_values[1])]; - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { nonce: next_nonce, calldata: create_calldata(contract_address, "call_xor_counters", &calldata_args), @@ -721,7 +720,7 @@ fn test_invoke_tx_advanced_operations( ); // Invoke test_ec_op function. - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { nonce: next_nonce, calldata: create_calldata(contract_address, "test_ec_op", &[]), @@ -758,7 +757,7 @@ fn test_invoke_tx_advanced_operations( let signature_values = [Felt::from(200_u64), Felt::from(300_u64)]; let signature = TransactionSignature(signature_values.into()); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { signature, nonce: next_nonce, calldata: @@ -784,7 +783,7 @@ fn test_invoke_tx_advanced_operations( // Invoke send_message function that send a message to L1. let to_address = Felt::from(85); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { nonce: next_nonce, calldata: create_calldata(contract_address, "send_message", &[to_address]), @@ -846,7 +845,7 @@ fn test_state_get_fee_token_balance( // Mint some tokens. let execute_calldata = create_calldata(fee_token_address, "permissionedMint", &[recipient, mint_low, mint_high]); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { max_fee: MAX_FEE, resource_bounds: default_l1_resource_bounds(), sender_address: account_address, @@ -931,7 +930,7 @@ fn test_estimate_minimal_gas_vector( }; // The minimal gas estimate does not depend on tx version. - let tx = &account_invoke_tx(valid_invoke_tx_args); + let tx = &invoke_tx_with_default_flags(valid_invoke_tx_args); let minimal_gas_vector = estimate_minimal_gas_vector(block_context, tx, &gas_vector_computation_mode); let minimal_l1_gas = minimal_gas_vector.l1_gas; @@ -982,7 +981,7 @@ fn test_max_fee_exceeds_balance( // V1 Invoke. let invalid_max_fee = Fee(BALANCE.0 + 1); - let invalid_tx = account_invoke_tx(invoke_tx_args! { + let invalid_tx = invoke_tx_with_default_flags(invoke_tx_args! { max_fee: invalid_max_fee, version: TransactionVersion::ONE, ..default_invoke_args.clone() @@ -993,7 +992,7 @@ fn test_max_fee_exceeds_balance( macro_rules! assert_resource_overdraft { ($invalid_resource_bounds:expr) => { // V3 invoke. - let invalid_tx = account_invoke_tx(invoke_tx_args! { + let invalid_tx = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: $invalid_resource_bounds, ..default_invoke_args.clone() }); @@ -1079,7 +1078,7 @@ fn test_insufficient_new_resource_bounds_pre_validation( calldata: create_trivial_calldata(test_contract.get_instance_address(0)), max_fee: MAX_FEE }; - let tx = &account_invoke_tx(valid_invoke_tx_args.clone()); + let tx = &invoke_tx_with_default_flags(valid_invoke_tx_args.clone()); // V3 transaction. let GasPriceVector { @@ -1107,7 +1106,7 @@ fn test_insufficient_new_resource_bounds_pre_validation( }; // Verify successful execution on default resource bounds. - let valid_resources_tx = account_invoke_tx(InvokeTxArgs { + let valid_resources_tx = invoke_tx_with_default_flags(InvokeTxArgs { resource_bounds: ValidResourceBounds::AllResources(default_resource_bounds), ..valid_invoke_tx_args.clone() }) @@ -1148,7 +1147,7 @@ fn test_insufficient_new_resource_bounds_pre_validation( L2Gas => invalid_resources.l2_gas.max_amount.0 -= 1, L1DataGas => invalid_resources.l1_data_gas.max_amount.0 -= 1, } - let invalid_v3_tx = account_invoke_tx(InvokeTxArgs { + let invalid_v3_tx = invoke_tx_with_default_flags(InvokeTxArgs { resource_bounds: ValidResourceBounds::AllResources(invalid_resources), nonce: nonce!(next_nonce), ..valid_invoke_tx_args.clone() @@ -1174,7 +1173,7 @@ fn test_insufficient_new_resource_bounds_pre_validation( L1DataGas => invalid_resources.l1_data_gas.max_price_per_unit.0 -= 1, } - let invalid_v3_tx = account_invoke_tx(InvokeTxArgs { + let invalid_v3_tx = invoke_tx_with_default_flags(InvokeTxArgs { resource_bounds: ValidResourceBounds::AllResources(invalid_resources), nonce: nonce!(next_nonce), ..valid_invoke_tx_args.clone() @@ -1212,7 +1211,7 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( }; // The minimal gas estimate does not depend on tx version. - let tx = &account_invoke_tx(valid_invoke_tx_args.clone()); + let tx = &invoke_tx_with_default_flags(valid_invoke_tx_args.clone()); let minimal_l1_gas = estimate_minimal_gas_vector(block_context, tx, &GasVectorComputationMode::NoL2Gas).l1_gas; @@ -1224,7 +1223,7 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( minimal_l1_gas.checked_mul(gas_prices.eth_gas_prices.l1_gas_price.get()).unwrap(); // Max fee too low (lower than minimal estimated fee). let invalid_max_fee = Fee(minimal_fee.0 - 1); - let invalid_v1_tx = account_invoke_tx( + let invalid_v1_tx = invoke_tx_with_default_flags( invoke_tx_args! { max_fee: invalid_max_fee, version: TransactionVersion::ONE, ..valid_invoke_tx_args.clone() }, ); let execution_error = invalid_v1_tx.execute(state, block_context).unwrap_err(); @@ -1244,7 +1243,7 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( // Max L1 gas amount too low, old resource bounds. // TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the conversion works. let insufficient_max_l1_gas_amount = (minimal_l1_gas.0 - 1).into(); - let invalid_v3_tx = account_invoke_tx(invoke_tx_args! { + let invalid_v3_tx = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: l1_resource_bounds(insufficient_max_l1_gas_amount, actual_strk_l1_gas_price.into()), ..valid_invoke_tx_args.clone() }); @@ -1263,7 +1262,7 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( // Max L1 gas price too low, old resource bounds. let insufficient_max_l1_gas_price = (actual_strk_l1_gas_price.get().0 - 1).into(); - let invalid_v3_tx = account_invoke_tx(invoke_tx_args! { + let invalid_v3_tx = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: l1_resource_bounds(minimal_l1_gas, insufficient_max_l1_gas_price), ..valid_invoke_tx_args.clone() }); @@ -1314,7 +1313,7 @@ fn test_actual_fee_gt_resource_bounds( }; // Execute the tx to compute the final gas costs. - let tx = &account_invoke_tx(tx_args.clone()); + let tx = &invoke_tx_with_default_flags(tx_args.clone()); let execution_result = tx.execute(state, block_context).unwrap(); let mut actual_gas = execution_result.receipt.gas; @@ -1339,7 +1338,7 @@ fn test_actual_fee_gt_resource_bounds( ) } }; - let invalid_tx = account_invoke_tx(invoke_tx_args! { + let invalid_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: sender_address1, resource_bounds: overdraft_resource_bounds, // To get the same DA cost, write a different value. @@ -1381,8 +1380,9 @@ fn test_invalid_nonce( // Strict, negative flow: account nonce = 0, incoming tx nonce = 1. let invalid_nonce = nonce!(1_u8); - let invalid_tx = - account_invoke_tx(invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }); + let invalid_tx = invoke_tx_with_default_flags( + invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }, + ); let invalid_tx_context = block_context.to_tx_context(&invalid_tx); let pre_validation_err = invalid_tx .perform_pre_validation_stage(&mut transactional_state, &invalid_tx_context, false, true) @@ -1400,8 +1400,9 @@ fn test_invalid_nonce( // Positive flow: account nonce = 0, incoming tx nonce = 1. let valid_nonce = nonce!(1_u8); - let valid_tx = - account_invoke_tx(invoke_tx_args! { nonce: valid_nonce, ..valid_invoke_tx_args.clone() }); + let valid_tx = invoke_tx_with_default_flags( + invoke_tx_args! { nonce: valid_nonce, ..valid_invoke_tx_args.clone() }, + ); let valid_tx_context = block_context.to_tx_context(&valid_tx); valid_tx @@ -1410,8 +1411,9 @@ fn test_invalid_nonce( // Negative flow: account nonce = 1, incoming tx nonce = 0. let invalid_nonce = nonce!(0_u8); - let invalid_tx = - account_invoke_tx(invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }); + let invalid_tx = invoke_tx_with_default_flags( + invoke_tx_args! { nonce: invalid_nonce, ..valid_invoke_tx_args.clone() }, + ); let invalid_tx_context = block_context.to_tx_context(&invalid_tx); let pre_validation_err = invalid_tx .perform_pre_validation_stage(&mut transactional_state, &invalid_tx_context, false, false) @@ -2425,7 +2427,7 @@ fn test_execute_tx_with_invalid_tx_version( "test_tx_version", &[felt!(invalid_version)], ); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { resource_bounds: default_all_resource_bounds, sender_address: account.get_instance_address(0), calldata, @@ -2521,7 +2523,7 @@ fn test_emit_event_exceeds_limit( .into(), ); - let account_tx = account_invoke_tx(invoke_tx_args! { + let account_tx = invoke_tx_with_default_flags(invoke_tx_args! { sender_address: account_contract.get_instance_address(0), calldata: execute_calldata, resource_bounds: default_all_resource_bounds,