diff --git a/crates/blockifier/src/blockifier/stateful_validator_test.rs b/crates/blockifier/src/blockifier/stateful_validator_test.rs index 580dc5f581..1a30749fd5 100644 --- a/crates/blockifier/src/blockifier/stateful_validator_test.rs +++ b/crates/blockifier/src/blockifier/stateful_validator_test.rs @@ -11,7 +11,7 @@ use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::test_utils::{ block_context, create_account_tx_for_validate_test_nonce_0, - max_l1_resource_bounds, + default_l1_resource_bounds, FaultyAccountTxCreatorArgs, INVALID, VALID, @@ -33,7 +33,7 @@ fn test_tx_validator( #[case] validate_constructor: bool, #[case] tx_version: TransactionVersion, block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let chain_info = &block_context.chain_info; @@ -54,7 +54,7 @@ fn test_tx_validator( validate_constructor, // TODO(Arni, 1/5/2024): Add test for insufficient maximal resources. max_fee: BALANCE, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, ..Default::default() }; @@ -75,7 +75,7 @@ fn test_tx_validator( } #[rstest] -fn test_tx_validator_skip_validate(max_l1_resource_bounds: ValidResourceBounds) { +fn test_tx_validator_skip_validate(default_l1_resource_bounds: ValidResourceBounds) { let block_context = BlockContext::create_for_testing(); let faulty_account = FeatureContract::FaultyAccount(CairoVersion::Cairo1); let state = test_state(&block_context.chain_info, BALANCE, &[(faulty_account, 1)]); @@ -87,7 +87,7 @@ fn test_tx_validator_skip_validate(max_l1_resource_bounds: ValidResourceBounds) tx_version: TransactionVersion::THREE, sender_address: faulty_account.get_instance_address(0), class_hash: faulty_account.get_class_hash(), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, ..Default::default() }); diff --git a/crates/blockifier/src/concurrency/fee_utils_test.rs b/crates/blockifier/src/concurrency/fee_utils_test.rs index 028842bf13..ba6cc8df95 100644 --- a/crates/blockifier/src/concurrency/fee_utils_test.rs +++ b/crates/blockifier/src/concurrency/fee_utils_test.rs @@ -13,19 +13,23 @@ 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::objects::FeeType; -use crate::transaction::test_utils::{account_invoke_tx, block_context, max_l1_resource_bounds}; +use crate::transaction::test_utils::{ + account_invoke_tx, + block_context, + default_l1_resource_bounds, +}; #[rstest] pub fn test_fill_sequencer_balance_reads( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] erc20_version: CairoVersion, ) { let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); let account_tx = account_invoke_tx(invoke_tx_args! { sender_address: account.get_instance_address(0), calldata: create_trivial_calldata(account.get_instance_address(0)), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, }); let chain_info = &block_context.chain_info; let state = &mut test_state_inner(chain_info, BALANCE, &[(account, 1)], erc20_version); diff --git a/crates/blockifier/src/concurrency/versioned_state_test.rs b/crates/blockifier/src/concurrency/versioned_state_test.rs index 2d09ea036d..b6d7087fb6 100644 --- a/crates/blockifier/src/concurrency/versioned_state_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_test.rs @@ -53,7 +53,7 @@ use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE}; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::objects::{HasRelatedFeeType, TransactionInfoCreator}; -use crate::transaction::test_utils::{l1_resource_bounds, max_l1_resource_bounds}; +use crate::transaction::test_utils::{default_l1_resource_bounds, l1_resource_bounds}; use crate::transaction::transactions::ExecutableTransaction; #[fixture] @@ -211,7 +211,7 @@ fn test_versioned_state_proxy() { #[rstest] // Test parallel execution of two transactions that use the same versioned state. -fn test_run_parallel_txs(max_l1_resource_bounds: ValidResourceBounds) { +fn test_run_parallel_txs(default_l1_resource_bounds: ValidResourceBounds) { let block_context = BlockContext::create_for_account_testing(); let chain_info = &block_context.chain_info; let zero_bounds = true; @@ -254,7 +254,7 @@ fn test_run_parallel_txs(max_l1_resource_bounds: ValidResourceBounds) { let constructor_calldata = calldata![ctor_grind_arg, ctor_storage_arg]; let deploy_tx_args = deploy_account_tx_args! { class_hash, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, constructor_calldata: constructor_calldata.clone(), }; let nonce_manager = &mut NonceManager::default(); diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index 00b2cc5481..cebdebf61a 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -50,9 +50,9 @@ use crate::transaction::objects::HasRelatedFeeType; use crate::transaction::test_utils::{ account_invoke_tx, calculate_class_info_for_testing, + default_l1_resource_bounds, emit_n_events_tx, max_fee, - max_l1_resource_bounds, }; use crate::transaction::transaction_execution::Transaction; @@ -64,7 +64,7 @@ fn trivial_calldata_invoke_tx( account_invoke_tx(invoke_tx_args! { sender_address: account_address, calldata: create_trivial_calldata(test_contract_address), - resource_bounds: max_l1_resource_bounds(), + resource_bounds: default_l1_resource_bounds(), nonce, }) } @@ -263,7 +263,7 @@ fn test_commit_tx_when_sender_is_sequencer() { } #[rstest] -fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) { +fn test_worker_execute(default_l1_resource_bounds: ValidResourceBounds) { // Settings. let block_context = BlockContext::create_for_account_testing(); let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); @@ -288,7 +288,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) { "test_storage_read_write", &[*storage_key.0.key(),storage_value ], // Calldata: address, value. ), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address) }); @@ -301,7 +301,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) { "test_storage_read_write", &[*storage_key.0.key(),storage_value ], // Calldata: address, value. ), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address) }); @@ -313,7 +313,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) { "write_and_revert", &[felt!(1991_u16),storage_value ], // Calldata: address, value. ), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address) }); @@ -437,7 +437,7 @@ fn test_worker_execute(max_l1_resource_bounds: ValidResourceBounds) { } #[rstest] -fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) { +fn test_worker_validate(default_l1_resource_bounds: ValidResourceBounds) { // Settings. let block_context = BlockContext::create_for_account_testing(); let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); @@ -464,7 +464,7 @@ fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) { "test_storage_read_write", &[*storage_key.0.key(),storage_value0 ], // Calldata: address, value. ), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address) }); @@ -475,7 +475,7 @@ fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) { "test_storage_read_write", &[*storage_key.0.key(),storage_value1 ], // Calldata: address, value. ), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address) }); @@ -544,7 +544,7 @@ fn test_worker_validate(max_l1_resource_bounds: ValidResourceBounds) { #[case::declare_cairo1(CairoVersion::Cairo1, TransactionVersion::THREE)] fn test_deploy_before_declare( max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] cairo_version: CairoVersion, #[case] version: TransactionVersion, ) { @@ -565,7 +565,7 @@ fn test_deploy_before_declare( let declare_tx = declare_tx( declare_tx_args! { sender_address: account_address_0, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, class_hash: test_class_hash, compiled_class_hash: test_compiled_class_hash, version, @@ -589,7 +589,7 @@ fn test_deploy_before_declare( felt!(1_u8), // Constructor calldata arg2. ] ), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce!(0_u8) }); @@ -634,7 +634,7 @@ fn test_deploy_before_declare( } #[rstest] -fn test_worker_commit_phase(max_l1_resource_bounds: ValidResourceBounds) { +fn test_worker_commit_phase(default_l1_resource_bounds: ValidResourceBounds) { // Settings. let block_context = BlockContext::create_for_account_testing(); let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); @@ -662,7 +662,7 @@ fn test_worker_commit_phase(max_l1_resource_bounds: ValidResourceBounds) { Transaction::Account(account_invoke_tx(invoke_tx_args! { sender_address, calldata: calldata.clone(), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(sender_address) })) }) diff --git a/crates/blockifier/src/execution/stack_trace_test.rs b/crates/blockifier/src/execution/stack_trace_test.rs index 0b9cca54c2..9c750d63b3 100644 --- a/crates/blockifier/src/execution/stack_trace_test.rs +++ b/crates/blockifier/src/execution/stack_trace_test.rs @@ -31,7 +31,7 @@ use crate::transaction::test_utils::{ account_invoke_tx, block_context, create_account_tx_for_validate_test_nonce_0, - max_l1_resource_bounds, + default_l1_resource_bounds, run_invoke_tx, FaultyAccountTxCreatorArgs, INVALID, @@ -664,7 +664,7 @@ An ASSERT_EQ instruction failed: 1 != 0. /// point selector). fn test_contract_ctor_frame_stack_trace( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let chain_info = &block_context.chain_info; @@ -701,7 +701,7 @@ fn test_contract_ctor_frame_stack_trace( validate_constructor, ] ), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: Nonce(felt!(0_u8)), }); diff --git a/crates/blockifier/src/fee/fee_test.rs b/crates/blockifier/src/fee/fee_test.rs index 6d0ac55566..6f827a22a9 100644 --- a/crates/blockifier/src/fee/fee_test.rs +++ b/crates/blockifier/src/fee/fee_test.rs @@ -21,9 +21,9 @@ use crate::test_utils::{ DEFAULT_ETH_L1_DATA_GAS_PRICE, DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_L1_DATA_GAS_MAX_AMOUNT, + DEFAULT_L1_GAS_AMOUNT, DEFAULT_L2_GAS_MAX_AMOUNT, DEFAULT_STRK_L1_GAS_PRICE, - MAX_L1_GAS_AMOUNT, }; use crate::transaction::objects::FeeType; use crate::transaction::test_utils::{account_invoke_tx, all_resource_bounds, l1_resource_bounds}; @@ -225,25 +225,25 @@ fn test_discounted_gas_overdraft( /// resource. If the gas used exceeds the limit, the post-execution validation should fail. #[rstest] #[case::l1_bound_overdraft( - (2 * MAX_L1_GAS_AMOUNT.0).into(), + (2 * DEFAULT_L1_GAS_AMOUNT.0).into(), DEFAULT_L2_GAS_MAX_AMOUNT, DEFAULT_L1_DATA_GAS_MAX_AMOUNT, Some(Resource::L1Gas) )] #[case::l2_bound_overdraft( - MAX_L1_GAS_AMOUNT, + DEFAULT_L1_GAS_AMOUNT, (2 * DEFAULT_L2_GAS_MAX_AMOUNT.0).into(), DEFAULT_L1_DATA_GAS_MAX_AMOUNT, Some(Resource::L2Gas) )] #[case::l1_data_bound_overdraft( - MAX_L1_GAS_AMOUNT, + DEFAULT_L1_GAS_AMOUNT, DEFAULT_L2_GAS_MAX_AMOUNT, (2 * DEFAULT_L1_DATA_GAS_MAX_AMOUNT.0).into(), Some(Resource::L1DataGas) )] #[case::no_overdraft( - (MAX_L1_GAS_AMOUNT.0 / 2).into(), + (DEFAULT_L1_GAS_AMOUNT.0 / 2).into(), (DEFAULT_L2_GAS_MAX_AMOUNT.0 / 2).into(), (DEFAULT_L1_DATA_GAS_MAX_AMOUNT.0 / 2).into(), None diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 388d54dc71..8736f86827 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -96,14 +96,10 @@ pub fn test_erc20_sequencer_balance_key() -> StorageKey { } // The max_fee / resource bounds used for txs in this test. -pub const MAX_L1_GAS_AMOUNT: GasAmount = GasAmount(1000000); -pub const MAX_L1_GAS_PRICE: NonzeroGasPrice = DEFAULT_STRK_L1_GAS_PRICE; -pub const MAX_RESOURCE_COMMITMENT: Fee = MAX_L1_GAS_AMOUNT.nonzero_saturating_mul(MAX_L1_GAS_PRICE); -pub const MAX_FEE: Fee = MAX_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_ETH_L1_GAS_PRICE); - -// The amount of test-token allocated to the account in this test, set to a multiple of the max -// amount deprecated / non-deprecated transactions commit to paying. -pub const BALANCE: Fee = Fee(10 * const_max(MAX_FEE.0, MAX_RESOURCE_COMMITMENT.0)); +// V3 transactions: +pub const DEFAULT_L1_GAS_AMOUNT: GasAmount = GasAmount(1000000); +pub const DEFAULT_L1_DATA_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 6)); +pub const DEFAULT_L2_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 9)); pub const DEFAULT_ETH_L1_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(100 * u128::pow(10, 9))); // Given in units of Wei. @@ -113,10 +109,26 @@ pub const DEFAULT_ETH_L1_DATA_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 6))); // Given in units of Wei. pub const DEFAULT_STRK_L1_DATA_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); // Given in units of STRK. -pub const DEFAULT_L1_DATA_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 6)); pub const DEFAULT_STRK_L2_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); -pub const DEFAULT_L2_GAS_MAX_AMOUNT: GasAmount = GasAmount(u64::pow(10, 6)); + +// Deprecated transactions: +pub const MAX_FEE: Fee = DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_ETH_L1_GAS_PRICE); + +// The amount of test-token allocated to the account in this test, set to a multiple of the max +// amount deprecated / non-deprecated transactions commit to paying. +pub const BALANCE: Fee = Fee(10 + * const_max( + const_max(DEFAULT_ALL_BOUNDS_COMMITTED_FEE.0, DEFAULT_L1_BOUNDS_COMMITTED_FEE.0), + MAX_FEE.0, + )); +const DEFAULT_L1_BOUNDS_COMMITTED_FEE: Fee = + DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_STRK_L1_GAS_PRICE); +const DEFAULT_ALL_BOUNDS_COMMITTED_FEE: Fee = DEFAULT_L1_BOUNDS_COMMITTED_FEE + .saturating_add(DEFAULT_L2_GAS_MAX_AMOUNT.nonzero_saturating_mul(DEFAULT_STRK_L2_GAS_PRICE)) + .saturating_add( + DEFAULT_L1_DATA_GAS_MAX_AMOUNT.nonzero_saturating_mul(DEFAULT_STRK_L1_DATA_GAS_PRICE), + ); // The block number of the BlockContext being used for testing. pub const CURRENT_BLOCK_NUMBER: u64 = 2001; diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 8c6fe6db2a..45e433f2c5 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -78,10 +78,10 @@ use crate::transaction::test_utils::{ create_all_resource_bounds, create_test_init_data, default_all_resource_bounds, + default_l1_resource_bounds, deploy_and_fund_account, l1_resource_bounds, max_fee, - max_l1_resource_bounds, run_invoke_tx, FaultyAccountTxCreatorArgs, TestInitData, @@ -92,7 +92,7 @@ use crate::transaction::transactions::{DeclareTransaction, ExecutableTransaction use crate::utils::u64_from_usize; #[rstest] -fn test_circuit(block_context: BlockContext, max_l1_resource_bounds: ValidResourceBounds) { +fn test_circuit(block_context: BlockContext, default_l1_resource_bounds: ValidResourceBounds) { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1); let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); let chain_info = &block_context.chain_info; @@ -115,7 +115,7 @@ fn test_circuit(block_context: BlockContext, max_l1_resource_bounds: ValidResour state, &block_context, invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, ..tx_args }, ) @@ -125,7 +125,7 @@ fn test_circuit(block_context: BlockContext, max_l1_resource_bounds: ValidResour } #[rstest] -fn test_rc96_holes(block_context: BlockContext, max_l1_resource_bounds: ValidResourceBounds) { +fn test_rc96_holes(block_context: BlockContext, default_l1_resource_bounds: ValidResourceBounds) { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1); let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); let chain_info = &block_context.chain_info; @@ -148,7 +148,7 @@ fn test_rc96_holes(block_context: BlockContext, max_l1_resource_bounds: ValidRes state, &block_context, invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, ..tx_args }, ) @@ -267,7 +267,7 @@ fn test_enforce_fee_false_works(block_context: BlockContext, #[case] version: Tr fn test_account_flow_test( block_context: BlockContext, max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(TransactionVersion::ZERO, TransactionVersion::ONE, TransactionVersion::THREE)] tx_version: TransactionVersion, #[values(true, false)] only_query: bool, @@ -284,7 +284,7 @@ fn test_account_flow_test( sender_address: account_address, calldata: create_trivial_calldata(contract_address), version: tx_version, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address), only_query, }, @@ -299,7 +299,7 @@ fn test_account_flow_test( fn test_invoke_tx_from_non_deployed_account( block_context: BlockContext, max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] tx_version: TransactionVersion, ) { let TestInitData { mut state, account_address, contract_address: _, mut nonce_manager } = @@ -321,7 +321,7 @@ fn test_invoke_tx_from_non_deployed_account( felt!(1_u8), // Calldata length. felt!(2_u8) // Calldata: num. ], - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, version: tx_version, nonce: nonce_manager.next(account_address), }, @@ -348,7 +348,7 @@ fn test_infinite_recursion( #[values(true, false)] success: bool, #[values(true, false)] normal_recurse: bool, mut block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { // Limit the number of execution steps (so we quickly hit the limit). block_context.versioned_constants.invoke_tx_max_n_steps = 4200; @@ -376,7 +376,7 @@ fn test_infinite_recursion( &mut state, &block_context, invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, sender_address: account_address, calldata: execute_calldata, nonce: nonce_manager.next(account_address), @@ -397,8 +397,8 @@ fn test_infinite_recursion( /// Tests that validation fails on insufficient steps if max fee is too low. #[rstest] -#[case::v1(TransactionVersion::ONE, max_l1_resource_bounds())] -#[case::v3_l1_bounds_only(TransactionVersion::THREE, max_l1_resource_bounds())] +#[case::v1(TransactionVersion::ONE, default_l1_resource_bounds())] +#[case::v3_l1_bounds_only(TransactionVersion::THREE, default_l1_resource_bounds())] #[case::v3_all_bounds(TransactionVersion::THREE, default_all_resource_bounds())] fn test_max_fee_limit_validate( mut block_context: BlockContext, @@ -541,7 +541,7 @@ fn test_recursion_depth_exceeded( #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, block_context: BlockContext, max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = create_test_init_data(&block_context.chain_info, cairo_version); @@ -575,7 +575,7 @@ fn test_recursion_depth_exceeded( calldata, version: tx_version, nonce: nonce_manager.next(account_address), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, }; let tx_execution_info = run_invoke_tx(&mut state, &block_context, invoke_args.clone()); @@ -782,7 +782,7 @@ fn recursive_function_calldata( #[case(TransactionVersion::THREE)] fn test_reverted_reach_steps_limit( max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, mut block_context: BlockContext, #[case] version: TransactionVersion, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, @@ -794,7 +794,7 @@ fn test_reverted_reach_steps_limit( block_context.versioned_constants.invoke_tx_max_n_steps = 6000; let recursion_base_args = invoke_tx_args! { max_fee, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, sender_address: account_address, version, }; @@ -892,13 +892,13 @@ fn test_reverted_reach_steps_limit( /// asserts false. We test deltas between consecutive depths, and further depths. fn test_n_reverted_steps( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = create_test_init_data(&block_context.chain_info, cairo_version); let recursion_base_args = invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, sender_address: account_address, }; @@ -1071,7 +1071,7 @@ fn test_max_fee_to_max_steps_conversion( /// recorded and max_fee is charged. fn test_insufficient_max_fee_reverts( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = @@ -1085,7 +1085,7 @@ fn test_insufficient_max_fee_reverts( &mut state, &block_context, invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address), calldata: recursive_function_calldata(&contract_address, 1, false), ..recursion_base_args.clone() @@ -1144,7 +1144,7 @@ fn test_insufficient_max_fee_reverts( #[rstest] fn test_deploy_account_constructor_storage_write( - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, block_context: BlockContext, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { @@ -1162,7 +1162,7 @@ fn test_deploy_account_constructor_storage_write( chain_info, deploy_account_tx_args! { class_hash, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, constructor_calldata: constructor_calldata.clone(), }, ); @@ -1188,7 +1188,7 @@ fn test_deploy_account_constructor_storage_write( fn test_count_actual_storage_changes( max_fee: Fee, block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] version: TransactionVersion, #[case] fee_type: FeeType, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, @@ -1231,7 +1231,7 @@ fn test_count_actual_storage_changes( let mut state = TransactionalState::create_transactional(&mut state); let invoke_args = invoke_tx_args! { max_fee, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, version, sender_address: account_address, calldata: write_1_calldata, @@ -1369,7 +1369,7 @@ fn test_count_actual_storage_changes( #[case::tx_version_3(TransactionVersion::THREE)] fn test_concurrency_execute_fee_transfer( max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] version: TransactionVersion, ) { // TODO(Meshi, 01/06/2024): make the test so it will include changes in @@ -1388,7 +1388,7 @@ fn test_concurrency_execute_fee_transfer( sender_address: account.get_instance_address(0), max_fee, calldata: create_trivial_calldata(test_contract.get_instance_address(0)), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, version }); let fee_type = &account_tx.fee_type(); @@ -1435,7 +1435,7 @@ fn test_concurrency_execute_fee_transfer( sender_address: account.get_instance_address(0), calldata: transfer_calldata, max_fee, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, }); let execution_result = @@ -1469,7 +1469,7 @@ fn test_concurrency_execute_fee_transfer( #[case::tx_version_3(TransactionVersion::THREE)] fn test_concurrent_fee_transfer_when_sender_is_sequencer( max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] version: TransactionVersion, ) { let mut block_context = BlockContext::create_for_account_testing(); @@ -1486,7 +1486,7 @@ fn test_concurrent_fee_transfer_when_sender_is_sequencer( max_fee, sender_address: account_address, calldata: create_trivial_calldata(test_contract.get_instance_address(0)), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, version }); let fee_type = &account_tx.fee_type(); @@ -1509,7 +1509,7 @@ fn test_concurrent_fee_transfer_when_sender_is_sequencer( #[rstest] fn test_revert_in_execute( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); let chain_info = &block_context.chain_info; @@ -1527,7 +1527,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_execution_info = account_invoke_tx(invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, ..tx_args }) .execute(state, &block_context, true, validate) @@ -1542,7 +1542,7 @@ fn test_revert_in_execute( #[case(false)] fn test_call_contract_that_panics( mut block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] enable_reverts: bool, ) { // Override enable reverts. @@ -1578,7 +1578,7 @@ fn test_call_contract_that_panics( state, &block_context, invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_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 5dcc368a68..5943d53302 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -32,9 +32,9 @@ use crate::test_utils::{ get_tx_resources, CairoVersion, BALANCE, + DEFAULT_L1_GAS_AMOUNT, + DEFAULT_STRK_L1_GAS_PRICE, MAX_FEE, - MAX_L1_GAS_AMOUNT, - MAX_L1_GAS_PRICE, }; use crate::transaction::errors::{ TransactionExecutionError, @@ -44,8 +44,8 @@ use crate::transaction::errors::{ use crate::transaction::objects::{FeeType, TransactionExecutionInfo, TransactionExecutionResult}; use crate::transaction::test_utils::{ account_invoke_tx, + default_l1_resource_bounds, l1_resource_bounds, - max_l1_resource_bounds, INVALID, }; use crate::transaction::transaction_types::TransactionType; @@ -182,7 +182,8 @@ fn get_pre_validate_test_args( let max_fee = MAX_FEE; // The max resource bounds fixture is not used here because this function already has the // maximum number of arguments. - let resource_bounds = l1_resource_bounds(MAX_L1_GAS_AMOUNT, MAX_L1_GAS_PRICE.into()); + let resource_bounds = + l1_resource_bounds(DEFAULT_L1_GAS_AMOUNT, DEFAULT_STRK_L1_GAS_PRICE.into()); let FlavorTestInitialState { state, account_address, test_contract_address, nonce_manager, .. } = create_flavors_test_state(&block_context.chain_info, cairo_version); @@ -323,7 +324,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 err = account_invoke_tx(invoke_tx_args! { - resource_bounds: l1_resource_bounds(MAX_L1_GAS_AMOUNT, (gas_price.get().0 - 1).into()), + resource_bounds: l1_resource_bounds(DEFAULT_L1_GAS_AMOUNT, (gas_price.get().0 - 1).into()), nonce: nonce_manager.next(account_address), ..pre_validation_base_args }) @@ -414,7 +415,7 @@ fn test_simulate_validate_pre_validate_not_charge_fee( if !is_deprecated { execute_and_check_gas_and_fee!( pre_validation_base_args.max_fee, - l1_resource_bounds(MAX_L1_GAS_AMOUNT, (gas_price.get().0 - 1).into()) + l1_resource_bounds(DEFAULT_L1_GAS_AMOUNT, (gas_price.get().0 - 1).into()) ); } } @@ -464,7 +465,7 @@ fn test_simulate_charge_fee_with_validation_fail_validate( // TODO(Dori, 1/1/2024): Add Cairo1 case, after price abstraction is implemented. #[values(CairoVersion::Cairo0)] cairo_version: CairoVersion, #[values(TransactionVersion::ONE, TransactionVersion::THREE)] version: TransactionVersion, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let validate = true; assert!( @@ -474,7 +475,7 @@ fn test_simulate_charge_fee_with_validation_fail_validate( charge_fee, cairo_version, version, - max_l1_resource_bounds, + default_l1_resource_bounds, ) .unwrap_err() .to_string() @@ -494,7 +495,7 @@ fn test_simulate_charge_fee_no_validation_fail_validate( #[values(CairoVersion::Cairo0)] cairo_version: CairoVersion, #[case] version: TransactionVersion, #[case] fee_type: FeeType, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let validate = false; let tx_execution_info = execute_fail_validation( @@ -503,7 +504,7 @@ fn test_simulate_charge_fee_no_validation_fail_validate( charge_fee, cairo_version, version, - max_l1_resource_bounds, + default_l1_resource_bounds, ) .unwrap(); @@ -538,7 +539,7 @@ fn test_simulate_validate_charge_fee_mid_execution( #[values(CairoVersion::Cairo0)] cairo_version: CairoVersion, #[case] version: TransactionVersion, #[case] fee_type: FeeType, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let block_context = BlockContext::create_for_account_testing(); let chain_info = &block_context.chain_info; @@ -562,7 +563,7 @@ fn test_simulate_validate_charge_fee_mid_execution( // 3. Execution fails due to out-of-resources error, due to max block bounds, mid-run. let execution_base_args = invoke_tx_args! { max_fee: MAX_FEE, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, sender_address: account_address, version, only_query, diff --git a/crates/blockifier/src/transaction/post_execution_test.rs b/crates/blockifier/src/transaction/post_execution_test.rs index 59f4fb3910..1ac3270c3c 100644 --- a/crates/blockifier/src/transaction/post_execution_test.rs +++ b/crates/blockifier/src/transaction/post_execution_test.rs @@ -18,16 +18,16 @@ use crate::fee::fee_checks::FeeCheckError; use crate::state::state_api::StateReader; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::{create_calldata, CairoVersion, BALANCE, MAX_L1_GAS_PRICE}; +use crate::test_utils::{create_calldata, CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE}; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::errors::TransactionExecutionError; use crate::transaction::objects::{FeeType, HasRelatedFeeType, TransactionInfoCreator}; use crate::transaction::test_utils::{ account_invoke_tx, block_context, + default_l1_resource_bounds, l1_resource_bounds, max_fee, - max_l1_resource_bounds, run_invoke_tx, TestInitData, }; @@ -73,7 +73,7 @@ fn calldata_for_write_and_transfer( #[case(TransactionVersion::THREE, FeeType::Strk)] fn test_revert_on_overdraft( max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, block_context: BlockContext, #[case] version: TransactionVersion, #[case] fee_type: FeeType, @@ -115,7 +115,7 @@ fn test_revert_on_overdraft( sender_address: account_address, calldata: approve_calldata, version, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address), }); let tx_info = approve_tx.create_tx_info(); @@ -140,7 +140,7 @@ fn test_revert_on_overdraft( fee_token_address ), version, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address), }, ) @@ -171,7 +171,7 @@ fn test_revert_on_overdraft( fee_token_address ), version, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address), }, ) @@ -218,7 +218,7 @@ fn test_revert_on_overdraft( #[case(TransactionVersion::THREE, &format!("Insufficient max {resource}", resource=Resource::L1Gas), true)] fn test_revert_on_resource_overuse( max_fee: Fee, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, block_context: BlockContext, #[case] version: TransactionVersion, #[case] expected_error_prefix: &str, @@ -249,7 +249,7 @@ fn test_revert_on_resource_overuse( &block_context, invoke_tx_args! { max_fee, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce_manager.next(account_address), calldata: write_a_lot_calldata(), ..base_args.clone() @@ -276,7 +276,7 @@ fn test_revert_on_resource_overuse( &block_context, invoke_tx_args! { max_fee: actual_fee, - resource_bounds: l1_resource_bounds(actual_gas_usage, MAX_L1_GAS_PRICE.into()), + resource_bounds: l1_resource_bounds(actual_gas_usage, DEFAULT_STRK_L1_GAS_PRICE.into()), nonce: nonce_manager.next(account_address), calldata: write_a_lot_calldata(), ..base_args.clone() @@ -296,7 +296,7 @@ fn test_revert_on_resource_overuse( invoke_tx_args! { max_fee: low_max_fee, resource_bounds: l1_resource_bounds( - (actual_gas_usage.0 - 1).into(), MAX_L1_GAS_PRICE.into() + (actual_gas_usage.0 - 1).into(), DEFAULT_STRK_L1_GAS_PRICE.into() ), nonce: nonce_manager.next(account_address), calldata: write_a_lot_calldata(), diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 276217f006..5545262f17 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -40,13 +40,12 @@ use crate::test_utils::{ CairoVersion, BALANCE, DEFAULT_L1_DATA_GAS_MAX_AMOUNT, + DEFAULT_L1_GAS_AMOUNT, DEFAULT_L2_GAS_MAX_AMOUNT, DEFAULT_STRK_L1_DATA_GAS_PRICE, DEFAULT_STRK_L1_GAS_PRICE, DEFAULT_STRK_L2_GAS_PRICE, MAX_FEE, - MAX_L1_GAS_AMOUNT, - MAX_L1_GAS_PRICE, }; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::constants; @@ -92,7 +91,7 @@ pub fn max_fee() -> Fee { // TODO(Amos, 1/10/2024): Delete this fixture and use `create_resource_bounds` #[fixture] -pub fn max_l1_resource_bounds() -> ValidResourceBounds { +pub fn default_l1_resource_bounds() -> ValidResourceBounds { create_resource_bounds(&GasVectorComputationMode::NoL2Gas) } @@ -104,11 +103,11 @@ pub fn default_all_resource_bounds() -> ValidResourceBounds { pub fn create_resource_bounds(computation_mode: &GasVectorComputationMode) -> ValidResourceBounds { match computation_mode { GasVectorComputationMode::NoL2Gas => { - l1_resource_bounds(MAX_L1_GAS_AMOUNT, MAX_L1_GAS_PRICE.into()) + l1_resource_bounds(DEFAULT_L1_GAS_AMOUNT, DEFAULT_STRK_L1_GAS_PRICE.into()) } GasVectorComputationMode::All => create_all_resource_bounds( - MAX_L1_GAS_AMOUNT, - MAX_L1_GAS_PRICE.into(), + DEFAULT_L1_GAS_AMOUNT, + DEFAULT_STRK_L1_GAS_PRICE.into(), DEFAULT_L2_GAS_MAX_AMOUNT, DEFAULT_STRK_L2_GAS_PRICE.into(), DEFAULT_L1_DATA_GAS_MAX_AMOUNT, @@ -338,7 +337,7 @@ pub fn l1_resource_bounds( #[fixture] pub fn all_resource_bounds( - #[default(MAX_L1_GAS_AMOUNT)] l1_max_amount: GasAmount, + #[default(DEFAULT_L1_GAS_AMOUNT)] l1_max_amount: GasAmount, #[default(GasPrice::from(DEFAULT_STRK_L1_GAS_PRICE))] l1_max_price: GasPrice, #[default(DEFAULT_L2_GAS_MAX_AMOUNT)] l2_max_amount: GasAmount, #[default(GasPrice::from(DEFAULT_STRK_L2_GAS_PRICE))] l2_max_price: GasPrice, diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index e12e163179..e1c21a3b50 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -103,9 +103,9 @@ use crate::test_utils::{ CURRENT_BLOCK_NUMBER_FOR_VALIDATE, CURRENT_BLOCK_TIMESTAMP, CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, + DEFAULT_L1_GAS_AMOUNT, + DEFAULT_STRK_L1_GAS_PRICE, MAX_FEE, - MAX_L1_GAS_AMOUNT, - MAX_L1_GAS_PRICE, TEST_SEQUENCER_ADDRESS, }; use crate::transaction::account_transaction::AccountTransaction; @@ -127,8 +127,8 @@ use crate::transaction::test_utils::{ calculate_class_info_for_testing, create_account_tx_for_validate_test, create_account_tx_for_validate_test_nonce_0, + default_l1_resource_bounds, l1_resource_bounds, - max_l1_resource_bounds, FaultyAccountTxCreatorArgs, CALL_CONTRACT, GET_BLOCK_HASH, @@ -405,7 +405,7 @@ fn add_kzg_da_resources_to_resources_mapping( }, CairoVersion::Cairo1)] fn test_invoke_tx( - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] expected_arguments: ExpectedResultTestInvokeTx, #[case] account_cairo_version: CairoVersion, #[values(false, true)] use_kzg_da: bool, @@ -421,7 +421,7 @@ fn test_invoke_tx( let invoke_tx = invoke_tx(invoke_tx_args! { sender_address: account_contract_address, calldata: create_trivial_calldata(test_contract_address), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, }); // Extract invoke transaction fields for testing, as it is consumed when creating an account @@ -608,7 +608,7 @@ fn verify_storage_after_invoke_advanced_operations( #[rstest] fn test_invoke_tx_advanced_operations( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let block_context = &block_context; @@ -620,7 +620,7 @@ fn test_invoke_tx_advanced_operations( let contract_address = test_contract.get_instance_address(0); let index = felt!(123_u32); let base_tx_args = invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, sender_address: account_address, }; @@ -886,7 +886,7 @@ fn test_estimate_minimal_gas_vector( #[rstest] fn test_max_fee_exceeds_balance( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, ) { let block_context = &block_context; @@ -905,9 +905,9 @@ fn test_max_fee_exceeds_balance( let invalid_max_fee = Fee(BALANCE.0 + 1); // TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the conversion works. - let balance_over_gas_price = BALANCE.checked_div(MAX_L1_GAS_PRICE).unwrap(); + let balance_over_gas_price = BALANCE.checked_div(DEFAULT_STRK_L1_GAS_PRICE).unwrap(); let invalid_resource_bounds = - l1_resource_bounds((balance_over_gas_price.0 + 1).into(), MAX_L1_GAS_PRICE.into()); + l1_resource_bounds((balance_over_gas_price.0 + 1).into(), DEFAULT_STRK_L1_GAS_PRICE.into()); // V1 Invoke. let invalid_tx = account_invoke_tx(invoke_tx_args! { @@ -927,7 +927,7 @@ fn test_max_fee_exceeds_balance( // Deploy. let invalid_tx = AccountTransaction::DeployAccount(deploy_account_tx( deploy_account_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, class_hash: test_contract.get_class_hash() }, &mut NonceManager::default(), @@ -1173,7 +1173,7 @@ fn test_insufficient_resource_bounds( #[rstest] fn test_actual_fee_gt_resource_bounds( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, ) { let block_context = &block_context; @@ -1187,7 +1187,7 @@ fn test_actual_fee_gt_resource_bounds( let invoke_tx_args = invoke_tx_args! { sender_address: account_contract.get_instance_address(0), calldata: create_trivial_calldata(test_contract.get_instance_address(0)), - resource_bounds: max_l1_resource_bounds + resource_bounds: default_l1_resource_bounds }; let tx = &account_invoke_tx(invoke_tx_args.clone()); let minimal_l1_gas = @@ -1217,7 +1217,7 @@ fn test_actual_fee_gt_resource_bounds( #[rstest] fn test_invalid_nonce( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, ) { let account_contract = FeatureContract::AccountWithoutValidations(account_cairo_version); @@ -1230,7 +1230,7 @@ fn test_invalid_nonce( let valid_invoke_tx_args = invoke_tx_args! { sender_address: account_contract.get_instance_address(0), calldata: create_trivial_calldata(test_contract.get_instance_address(0)), - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, }; let mut transactional_state = TransactionalState::create_transactional(state); @@ -1339,7 +1339,7 @@ fn declare_expected_state_changes_count(version: TransactionVersion) -> StateCha #[case(TransactionVersion::TWO, CairoVersion::Cairo1)] #[case(TransactionVersion::THREE, CairoVersion::Cairo1)] fn test_declare_tx( - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, #[case] tx_version: TransactionVersion, #[case] empty_contract_version: CairoVersion, @@ -1371,7 +1371,7 @@ fn test_declare_tx( max_fee: MAX_FEE, sender_address, version: tx_version, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, class_hash, compiled_class_hash, nonce: nonce_manager.next(sender_address), @@ -1481,7 +1481,7 @@ fn test_declare_tx( max_fee: MAX_FEE, sender_address, version: tx_version, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, class_hash, compiled_class_hash, nonce: nonce_manager.next(sender_address), @@ -1500,7 +1500,7 @@ fn test_declare_tx( fn test_deploy_account_tx( #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, #[values(false, true)] use_kzg_da: bool, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let block_context = &BlockContext::create_for_account_testing_with_kzg(use_kzg_da); let versioned_constants = &block_context.versioned_constants; @@ -1510,7 +1510,7 @@ fn test_deploy_account_tx( let account_class_hash = account.get_class_hash(); let state = &mut test_state(chain_info, BALANCE, &[(account, 1)]); let deploy_account = deploy_account_tx( - deploy_account_tx_args! { resource_bounds: max_l1_resource_bounds, class_hash: account_class_hash }, + deploy_account_tx_args! { resource_bounds: default_l1_resource_bounds, class_hash: account_class_hash }, &mut nonce_manager, ); @@ -1653,7 +1653,7 @@ fn test_deploy_account_tx( // Negative flow. // Deploy to an existing address. let deploy_account = deploy_account_tx( - deploy_account_tx_args! { resource_bounds: max_l1_resource_bounds, class_hash: account_class_hash }, + deploy_account_tx_args! { resource_bounds: default_l1_resource_bounds, class_hash: account_class_hash }, &mut nonce_manager, ); let account_tx = AccountTransaction::DeployAccount(deploy_account); @@ -1674,7 +1674,7 @@ fn test_deploy_account_tx( #[rstest] fn test_fail_deploy_account_undeclared_class_hash( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let block_context = &block_context; let chain_info = &block_context.chain_info; @@ -1682,7 +1682,7 @@ fn test_fail_deploy_account_undeclared_class_hash( let mut nonce_manager = NonceManager::default(); let undeclared_hash = class_hash!("0xdeadbeef"); let deploy_account = deploy_account_tx( - deploy_account_tx_args! {resource_bounds: max_l1_resource_bounds, class_hash: undeclared_hash }, + deploy_account_tx_args! {resource_bounds: default_l1_resource_bounds, class_hash: undeclared_hash }, &mut nonce_manager, ); let tx_context = block_context.to_tx_context(&deploy_account); @@ -1909,7 +1909,7 @@ fn test_validate_accounts_tx( #[rstest] fn test_valid_flag( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] test_contract_cairo_version: CairoVersion, ) { @@ -1925,7 +1925,7 @@ fn test_valid_flag( let account_tx = account_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: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, }); let actual_execution_info = account_tx.execute(state, block_context, true, false).unwrap(); @@ -1937,7 +1937,7 @@ fn test_valid_flag( #[rstest] fn test_only_query_flag( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[values(true, false)] only_query: bool, ) { let account_balance = BALANCE; @@ -1967,13 +1967,13 @@ fn test_only_query_flag( ]; let expected_resource_bounds = vec![ - Felt::TWO, // Length of ResourceBounds array. - felt!(L1Gas.to_hex()), // Resource. - felt!(MAX_L1_GAS_AMOUNT.0), // Max amount. - felt!(MAX_L1_GAS_PRICE.get().0), // Max price per unit. - felt!(L2Gas.to_hex()), // Resource. - Felt::ZERO, // Max amount. - Felt::ZERO, // Max price per unit. + Felt::TWO, // Length of ResourceBounds array. + felt!(L1Gas.to_hex()), // Resource. + felt!(DEFAULT_L1_GAS_AMOUNT.0), // Max amount. + felt!(DEFAULT_STRK_L1_GAS_PRICE.get().0), // Max price per unit. + felt!(L2Gas.to_hex()), // Resource. + Felt::ZERO, // Max amount. + Felt::ZERO, // Max price per unit. ]; let expected_unsupported_fields = vec![ @@ -2021,7 +2021,7 @@ fn test_only_query_flag( ); let invoke_tx = crate::test_utils::invoke::invoke_tx(invoke_tx_args! { calldata: execute_calldata, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, sender_address, only_query, }); @@ -2197,7 +2197,7 @@ fn test_l1_handler( #[rstest] fn test_execute_tx_with_invalid_tx_version( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, ) { let cairo_version = CairoVersion::Cairo0; let account = FeatureContract::AccountWithoutValidations(cairo_version); @@ -2212,7 +2212,7 @@ fn test_execute_tx_with_invalid_tx_version( &[felt!(invalid_version)], ); let account_tx = account_invoke_tx(invoke_tx_args! { - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, sender_address: account.get_instance_address(0), calldata, }); @@ -2270,7 +2270,7 @@ fn max_event_data() -> usize { }))] fn test_emit_event_exceeds_limit( block_context: BlockContext, - max_l1_resource_bounds: ValidResourceBounds, + default_l1_resource_bounds: ValidResourceBounds, #[case] event_keys: Vec, #[case] event_data: Vec, #[case] n_emitted_events: usize, @@ -2309,7 +2309,7 @@ fn test_emit_event_exceeds_limit( let account_tx = account_invoke_tx(invoke_tx_args! { sender_address: account_contract.get_instance_address(0), calldata: execute_calldata, - resource_bounds: max_l1_resource_bounds, + resource_bounds: default_l1_resource_bounds, nonce: nonce!(0_u8), }); let execution_info = account_tx.execute(state, block_context, true, true).unwrap(); diff --git a/crates/starknet_api/src/transaction.rs b/crates/starknet_api/src/transaction.rs index 8008885b4d..6bf6bc0ca9 100644 --- a/crates/starknet_api/src/transaction.rs +++ b/crates/starknet_api/src/transaction.rs @@ -746,7 +746,7 @@ impl Fee { self.0.checked_add(rhs.0).map(Fee) } - pub fn saturating_add(self, rhs: Self) -> Self { + pub const fn saturating_add(self, rhs: Self) -> Self { Self(self.0.saturating_add(rhs.0)) }