Skip to content

Commit

Permalink
chore(blockifier): rename fn account_invoke_tx to invoke_tx_with_defa…
Browse files Browse the repository at this point in the history
…ult_flags
  • Loading branch information
avivg-starkware committed Dec 5, 2024
1 parent a863fa6 commit dca892f
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 84 deletions.
4 changes: 2 additions & 2 deletions crates/blockifier/src/concurrency/fee_utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/execution/stack_trace_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions crates/blockifier/src/fee/fee_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
});
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions crates/blockifier/src/fee/gas_usage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/fee/receipt_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions crates/blockifier/src/test_utils/prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
),
Expand Down
36 changes: 19 additions & 17 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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
});
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -1669,7 +1671,7 @@ fn test_initial_gas(
sender_balance,
&contracts.into_iter().map(|contract| (contract, 1u16)).collect::<Vec<_>>(),
);
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,
Expand Down
Loading

0 comments on commit dca892f

Please sign in to comment.