diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index ee64bb82104..1261b141eba 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -32,7 +32,7 @@ use crate::test_utils::{ BALANCE, TEST_ERC20_CONTRACT_ADDRESS2, }; -use crate::transaction::account_transaction::{AccountTransaction, ExecutionFlags}; +use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::objects::HasRelatedFeeType; use crate::transaction::test_utils::{ account_invoke_tx, @@ -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 tx = declare_tx( + let declare_tx = AccountTransaction::new(declare_tx( declare_tx_args! { sender_address: account_address_0, resource_bounds: default_all_resource_bounds, @@ -560,9 +560,7 @@ fn test_deploy_before_declare( nonce: nonce!(0_u8), }, test_class_info.clone(), - ); - let execution_flags = ExecutionFlags::default(); - let declare_tx = AccountTransaction { tx, execution_flags }; + )); // Deploy test contract. let invoke_tx = account_invoke_tx(invoke_tx_args! { diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index fabeac7e7a8..a32184f0feb 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -104,7 +104,11 @@ macro_rules! implement_tx_getter_calls { })* }; } - +impl AccountTransaction { + pub fn new(tx: Transaction) -> Self { + Self { tx, execution_flags: ExecutionFlags::default() } + } +} impl HasRelatedFeeType for AccountTransaction { fn version(&self) -> TransactionVersion { self.tx.version() diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 73db0ab828e..23f3d7e9f9e 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -469,8 +469,7 @@ fn test_max_fee_limit_validate( }, class_info, ); - let execution_flags = AccountExecutionFlags::default(); - let account_tx = AccountTransaction { tx, execution_flags }; + let account_tx = AccountTransaction::new(tx); account_tx.execute(&mut state, &block_context).unwrap(); // Deploy grindy account with a lot of grind in the constructor. @@ -791,10 +790,8 @@ fn test_fail_declare(block_context: BlockContext, max_fee: Fee) { tx_hash: TransactionHash::default(), class_info, }; - let declare_account_tx = AccountTransaction { - tx: ApiExecutableTransaction::Declare(executable_declare), - execution_flags: AccountExecutionFlags::default(), - }; + let declare_account_tx = + AccountTransaction::new(ApiExecutableTransaction::Declare(executable_declare)); // Fail execution, assert nonce and balance are unchanged. let tx_info = declare_account_tx.create_tx_info(); diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 08c4411d3c5..727c366bc33 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -113,10 +113,8 @@ pub fn deploy_and_fund_account( deploy_tx_args: DeployAccountTxArgs, ) -> (AccountTransaction, ContractAddress) { // Deploy an account contract. - let deploy_account_tx = AccountTransaction { - tx: deploy_account_tx(deploy_tx_args, nonce_manager), - execution_flags: ExecutionFlags::default(), - }; + let deploy_account_tx = + AccountTransaction::new(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 diff --git a/crates/blockifier/src/transaction/transaction_execution.rs b/crates/blockifier/src/transaction/transaction_execution.rs index 93c3ef5f0a8..9ca1ed03ea7 100644 --- a/crates/blockifier/src/transaction/transaction_execution.rs +++ b/crates/blockifier/src/transaction/transaction_execution.rs @@ -43,10 +43,7 @@ impl From for Transaction { fn from(value: starknet_api::executable_transaction::Transaction) -> Self { match value { starknet_api::executable_transaction::Transaction::Account(tx) => { - Transaction::Account(AccountTransaction { - tx, - execution_flags: AccountExecutionFlags::default(), - }) + Transaction::Account(AccountTransaction::new(tx)) } starknet_api::executable_transaction::Transaction::L1Handler(tx) => { Transaction::L1Handler(tx) diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index b93702a4246..ceff8a22b42 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -449,13 +449,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 tx = invoke_tx(invoke_tx_args! { + let invoke_tx = AccountTransaction::new(invoke_tx(invoke_tx_args! { sender_address: account_contract_address, calldata: Calldata(Arc::clone(&calldata.0)), resource_bounds, - }); - let execution_flags = ExecutionFlags::default(); - let invoke_tx = AccountTransaction { tx, execution_flags }; + })); // Extract invoke transaction fields for testing, as it is consumed when creating an account // transaction. @@ -969,16 +967,13 @@ fn test_max_fee_exceeds_balance( )}; // Deploy. - let invalid_tx = AccountTransaction { - tx: deploy_account_tx( - deploy_account_tx_args! { - resource_bounds, - class_hash: test_contract.get_class_hash() - }, - &mut NonceManager::default(), - ), - execution_flags: ExecutionFlags::default(), - }; + let invalid_tx = AccountTransaction::new(deploy_account_tx( + deploy_account_tx_args! { + resource_bounds, + class_hash: test_contract.get_class_hash() + }, + &mut NonceManager::default(), + )); assert_resource_bounds_exceed_balance_failure(state, block_context, invalid_tx); // V1 Invoke. @@ -1002,18 +997,15 @@ 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 { - tx: declare_tx( - declare_tx_args! { - class_hash: contract_to_declare.get_class_hash(), - compiled_class_hash: contract_to_declare.get_compiled_class_hash(), - sender_address, - resource_bounds: $invalid_resource_bounds, - }, - class_info, - ), - execution_flags: ExecutionFlags::default(), - }; + let invalid_tx = AccountTransaction::new(declare_tx( + declare_tx_args! { + class_hash: contract_to_declare.get_class_hash(), + compiled_class_hash: contract_to_declare.get_compiled_class_hash(), + sender_address, + resource_bounds: $invalid_resource_bounds, + }, + class_info, + )); assert_resource_bounds_exceed_balance_failure(state, block_context, invalid_tx); }; } @@ -1516,7 +1508,7 @@ fn test_declare_tx( None, ExecutionSummary::default(), ); - let tx = declare_tx( + let account_tx = AccountTransaction::new(declare_tx( declare_tx_args! { max_fee: MAX_FEE, sender_address, @@ -1527,8 +1519,7 @@ fn test_declare_tx( nonce: nonce_manager.next(sender_address), }, class_info.clone(), - ); - let account_tx = AccountTransaction { tx, execution_flags: ExecutionFlags::default() }; + )); // Check state before transaction application. assert_matches!( @@ -1638,7 +1629,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 tx2 = declare_tx( + let account_tx2 = AccountTransaction::new(declare_tx( declare_tx_args! { max_fee: MAX_FEE, sender_address, @@ -1649,8 +1640,7 @@ fn test_declare_tx( nonce: nonce_manager.next(sender_address), }, class_info.clone(), - ); - let account_tx2 = AccountTransaction { tx: tx2, execution_flags: ExecutionFlags::default() }; + )); let result = account_tx2.execute(state, block_context); assert_matches!( result.unwrap_err(), @@ -1709,16 +1699,13 @@ 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 { - tx: deploy_account_tx( - deploy_account_tx_args! { - resource_bounds: default_all_resource_bounds, - class_hash: account_class_hash - }, - &mut nonce_manager, - ), - execution_flags: ExecutionFlags::default(), - }; + let deploy_account = AccountTransaction::new(deploy_account_tx( + deploy_account_tx_args! { + resource_bounds: default_all_resource_bounds, + class_hash: account_class_hash + }, + &mut nonce_manager, + )); // Extract deploy account transaction fields for testing, as it is consumed when creating an // account transaction. @@ -1869,16 +1856,13 @@ fn test_deploy_account_tx( // Negative flow. // Deploy to an existing address. - let deploy_account = AccountTransaction { - tx: deploy_account_tx( - deploy_account_tx_args! { - resource_bounds: default_all_resource_bounds, - class_hash: account_class_hash - }, - &mut nonce_manager, - ), - execution_flags: ExecutionFlags::default(), - }; + let deploy_account = AccountTransaction::new(deploy_account_tx( + deploy_account_tx_args! { + resource_bounds: default_all_resource_bounds, + class_hash: account_class_hash + }, + &mut nonce_manager, + )); let error = deploy_account.execute(state, block_context).unwrap_err(); assert_matches!( error, @@ -1903,15 +1887,12 @@ 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 { - tx: deploy_account_tx( - deploy_account_tx_args! { - resource_bounds: default_all_resource_bounds, class_hash: undeclared_hash - }, - &mut nonce_manager, - ), - execution_flags: ExecutionFlags::default(), - }; + let deploy_account = AccountTransaction::new(deploy_account_tx( + deploy_account_tx_args! { + resource_bounds: default_all_resource_bounds, class_hash: undeclared_hash + }, + &mut nonce_manager, + )); let tx_context = block_context.to_tx_context(&deploy_account); let fee_type = tx_context.tx_info.fee_type();