From c85210a5eb5c44926c208facbc02451c1cdca8df Mon Sep 17 00:00:00 2001 From: Nimrod Weiss Date: Mon, 19 Aug 2024 13:35:13 +0300 Subject: [PATCH] refactor(fee): use valid resource bounds in blockifier --- .../src/concurrency/fee_utils_test.rs | 4 +-- .../src/concurrency/versioned_state_test.rs | 4 +-- .../src/concurrency/worker_logic_test.rs | 10 +++--- .../src/execution/stack_trace_test.rs | 4 +-- crates/blockifier/src/fee/actual_cost_test.rs | 4 +-- crates/blockifier/src/test_utils.rs | 15 +++------ crates/blockifier/src/test_utils/declare.rs | 6 ++-- .../src/test_utils/deploy_account.rs | 6 ++-- crates/blockifier/src/test_utils/invoke.rs | 6 ++-- .../transaction/account_transactions_test.rs | 33 +++++++++---------- .../src/transaction/execution_flavors_test.rs | 6 ++-- .../src/transaction/post_execution_test.rs | 11 ++----- .../blockifier/src/transaction/test_utils.rs | 13 +++----- .../src/transaction/transactions_test.rs | 26 +++++++-------- 14 files changed, 65 insertions(+), 83 deletions(-) diff --git a/crates/blockifier/src/concurrency/fee_utils_test.rs b/crates/blockifier/src/concurrency/fee_utils_test.rs index dba9053156..3e36d6998f 100644 --- a/crates/blockifier/src/concurrency/fee_utils_test.rs +++ b/crates/blockifier/src/concurrency/fee_utils_test.rs @@ -1,7 +1,7 @@ use num_bigint::BigUint; use rstest::rstest; use starknet_api::felt; -use starknet_api::transaction::{DeprecatedResourceBoundsMapping, Fee}; +use starknet_api::transaction::{Fee, ValidResourceBounds}; use starknet_types_core::felt::Felt; use crate::concurrency::fee_utils::{add_fee_to_sequencer_balance, fill_sequencer_balance_reads}; @@ -19,7 +19,7 @@ use crate::transaction::test_utils::{account_invoke_tx, block_context, max_resou #[rstest] pub fn test_fill_sequencer_balance_reads( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] erc20_version: CairoVersion, ) { let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); diff --git a/crates/blockifier/src/concurrency/versioned_state_test.rs b/crates/blockifier/src/concurrency/versioned_state_test.rs index db64d3fe08..ffe9aa3ac3 100644 --- a/crates/blockifier/src/concurrency/versioned_state_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_test.rs @@ -11,7 +11,7 @@ use starknet_api::core::{ Nonce, PatriciaKey, }; -use starknet_api::transaction::{Calldata, ContractAddressSalt, DeprecatedResourceBoundsMapping}; +use starknet_api::transaction::{Calldata, ContractAddressSalt, ValidResourceBounds}; use starknet_api::{calldata, class_hash, contract_address, felt, patricia_key}; use crate::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address}; @@ -201,7 +201,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_resource_bounds: DeprecatedResourceBoundsMapping) { +fn test_run_parallel_txs(max_resource_bounds: ValidResourceBounds) { let block_context = BlockContext::create_for_account_testing(); let chain_info = &block_context.chain_info; let zero_bounds = true; diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index 3f9a9ebcac..e6aca5c932 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -5,9 +5,9 @@ use rstest::rstest; use starknet_api::core::{ContractAddress, Nonce, PatriciaKey}; use starknet_api::transaction::{ ContractAddressSalt, - DeprecatedResourceBoundsMapping, Fee, TransactionVersion, + ValidResourceBounds, }; use starknet_api::{contract_address, felt, patricia_key}; use starknet_types_core::felt::Felt; @@ -256,7 +256,7 @@ fn test_commit_tx_when_sender_is_sequencer() { } #[rstest] -fn test_worker_execute(max_resource_bounds: DeprecatedResourceBoundsMapping) { +fn test_worker_execute(max_resource_bounds: ValidResourceBounds) { // Settings. let block_context = BlockContext::create_for_account_testing(); let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); @@ -430,7 +430,7 @@ fn test_worker_execute(max_resource_bounds: DeprecatedResourceBoundsMapping) { } #[rstest] -fn test_worker_validate(max_resource_bounds: DeprecatedResourceBoundsMapping) { +fn test_worker_validate(max_resource_bounds: ValidResourceBounds) { // Settings. let block_context = BlockContext::create_for_account_testing(); let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); @@ -537,7 +537,7 @@ fn test_worker_validate(max_resource_bounds: DeprecatedResourceBoundsMapping) { #[case::declare_cairo1(CairoVersion::Cairo1, TransactionVersion::THREE)] fn test_deploy_before_declare( max_fee: Fee, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[case] cairo_version: CairoVersion, #[case] version: TransactionVersion, ) { @@ -629,7 +629,7 @@ fn test_deploy_before_declare( } #[rstest] -fn test_worker_commit_phase(max_resource_bounds: DeprecatedResourceBoundsMapping) { +fn test_worker_commit_phase(max_resource_bounds: ValidResourceBounds) { // Settings. let block_context = BlockContext::create_for_account_testing(); let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); diff --git a/crates/blockifier/src/execution/stack_trace_test.rs b/crates/blockifier/src/execution/stack_trace_test.rs index faf2303568..f51e86fb87 100644 --- a/crates/blockifier/src/execution/stack_trace_test.rs +++ b/crates/blockifier/src/execution/stack_trace_test.rs @@ -6,9 +6,9 @@ use starknet_api::transaction::{ Calldata, ContractAddressSalt, Fee, - DeprecatedResourceBoundsMapping, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; use starknet_api::{calldata, felt}; @@ -599,7 +599,7 @@ An ASSERT_EQ instruction failed: 1 != 0. /// point selector). fn test_contract_ctor_frame_stack_trace( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let chain_info = &block_context.chain_info; diff --git a/crates/blockifier/src/fee/actual_cost_test.rs b/crates/blockifier/src/fee/actual_cost_test.rs index bb9b513322..46d812d359 100644 --- a/crates/blockifier/src/fee/actual_cost_test.rs +++ b/crates/blockifier/src/fee/actual_cost_test.rs @@ -1,5 +1,5 @@ use rstest::{fixture, rstest}; -use starknet_api::transaction::{L2ToL1Payload, DeprecatedResourceBoundsMapping}; +use starknet_api::transaction::{L2ToL1Payload, ValidResourceBounds}; use starknet_types_core::felt::Felt; use crate::context::BlockContext; @@ -286,7 +286,7 @@ fn test_calculate_tx_gas_usage_basic<'a>(#[values(false, true)] use_kzg_da: bool // resources are taken into account). #[rstest] fn test_calculate_tx_gas_usage( - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(false, true)] use_kzg_da: bool, ) { let account_cairo_version = CairoVersion::Cairo0; diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index b2afd89626..694860e77b 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -18,10 +18,9 @@ use starknet_api::state::StorageKey; use starknet_api::transaction::{ Calldata, ContractAddressSalt, - DeprecatedResourceBoundsMapping, - Resource, ResourceBounds, TransactionVersion, + ValidResourceBounds, }; use starknet_api::{contract_address, felt, patricia_key}; use starknet_types_core::felt::Felt; @@ -211,14 +210,10 @@ pub fn trivial_external_entry_point_with_address( } } -fn default_testing_resource_bounds() -> DeprecatedResourceBoundsMapping { - DeprecatedResourceBoundsMapping::try_from(vec![ - (Resource::L1Gas, ResourceBounds { max_amount: 0, max_price_per_unit: 1 }), - // TODO(Dori, 1/2/2024): When fee market is developed, change the default price of - // L2 gas. - (Resource::L2Gas, ResourceBounds { max_amount: 0, max_price_per_unit: 0 }), - ]) - .unwrap() +fn default_testing_resource_bounds() -> ValidResourceBounds { + // TODO(Dori, 1/2/2024): When fee market is developed, change the default price of + // L2 gas. + ValidResourceBounds::L1Gas(ResourceBounds { max_amount: 0, max_price_per_unit: 1 }) } #[macro_export] diff --git a/crates/blockifier/src/test_utils/declare.rs b/crates/blockifier/src/test_utils/declare.rs index 89592c631e..308f2c54ea 100644 --- a/crates/blockifier/src/test_utils/declare.rs +++ b/crates/blockifier/src/test_utils/declare.rs @@ -5,13 +5,13 @@ use starknet_api::transaction::{ DeclareTransactionV0V1, DeclareTransactionV2, DeclareTransactionV3, - DeprecatedResourceBoundsMapping, Fee, PaymasterData, Tip, TransactionHash, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; use crate::execution::contract_class::ClassInfo; @@ -25,7 +25,7 @@ pub struct DeclareTxArgs { pub signature: TransactionSignature, pub sender_address: ContractAddress, pub version: TransactionVersion, - pub resource_bounds: DeprecatedResourceBoundsMapping, + pub resource_bounds: ValidResourceBounds, pub tip: Tip, pub nonce_data_availability_mode: DataAvailabilityMode, pub fee_data_availability_mode: DataAvailabilityMode, @@ -108,7 +108,7 @@ pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> Acco starknet_api::transaction::DeclareTransaction::V3(DeclareTransactionV3 { signature: declare_tx_args.signature, sender_address: declare_tx_args.sender_address, - resource_bounds: declare_tx_args.resource_bounds.0.try_into().expect("todo"), + resource_bounds: declare_tx_args.resource_bounds, tip: declare_tx_args.tip, nonce_data_availability_mode: declare_tx_args.nonce_data_availability_mode, fee_data_availability_mode: declare_tx_args.fee_data_availability_mode, diff --git a/crates/blockifier/src/test_utils/deploy_account.rs b/crates/blockifier/src/test_utils/deploy_account.rs index 69302436a8..6f2c9a5803 100644 --- a/crates/blockifier/src/test_utils/deploy_account.rs +++ b/crates/blockifier/src/test_utils/deploy_account.rs @@ -5,13 +5,13 @@ use starknet_api::transaction::{ ContractAddressSalt, DeployAccountTransactionV1, DeployAccountTransactionV3, - DeprecatedResourceBoundsMapping, Fee, PaymasterData, Tip, TransactionHash, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; use crate::test_utils::{default_testing_resource_bounds, NonceManager}; @@ -23,7 +23,7 @@ pub struct DeployAccountTxArgs { pub signature: TransactionSignature, pub deployer_address: ContractAddress, pub version: TransactionVersion, - pub resource_bounds: DeprecatedResourceBoundsMapping, + pub resource_bounds: ValidResourceBounds, pub tip: Tip, pub nonce_data_availability_mode: DataAvailabilityMode, pub fee_data_availability_mode: DataAvailabilityMode, @@ -96,7 +96,7 @@ pub fn deploy_account_tx( } else if deploy_tx_args.version == TransactionVersion::THREE { starknet_api::transaction::DeployAccountTransaction::V3(DeployAccountTransactionV3 { signature: deploy_tx_args.signature, - resource_bounds: deploy_tx_args.resource_bounds.0.try_into().expect("todo"), + resource_bounds: deploy_tx_args.resource_bounds, tip: deploy_tx_args.tip, nonce_data_availability_mode: deploy_tx_args.nonce_data_availability_mode, fee_data_availability_mode: deploy_tx_args.fee_data_availability_mode, diff --git a/crates/blockifier/src/test_utils/invoke.rs b/crates/blockifier/src/test_utils/invoke.rs index a44535b57f..0c8cbc9196 100644 --- a/crates/blockifier/src/test_utils/invoke.rs +++ b/crates/blockifier/src/test_utils/invoke.rs @@ -4,7 +4,6 @@ use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::transaction::{ AccountDeploymentData, Calldata, - DeprecatedResourceBoundsMapping, Fee, InvokeTransactionV0, InvokeTransactionV1, @@ -14,6 +13,7 @@ use starknet_api::transaction::{ TransactionHash, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; use crate::abi::abi_utils::selector_from_name; @@ -28,7 +28,7 @@ pub struct InvokeTxArgs { pub sender_address: ContractAddress, pub calldata: Calldata, pub version: TransactionVersion, - pub resource_bounds: DeprecatedResourceBoundsMapping, + pub resource_bounds: ValidResourceBounds, pub tip: Tip, pub nonce_data_availability_mode: DataAvailabilityMode, pub fee_data_availability_mode: DataAvailabilityMode, @@ -96,7 +96,7 @@ pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction { }) } else if invoke_args.version == TransactionVersion::THREE { starknet_api::transaction::InvokeTransaction::V3(InvokeTransactionV3 { - resource_bounds: invoke_args.resource_bounds.0.try_into().expect("todo"), + resource_bounds: invoke_args.resource_bounds, calldata: invoke_args.calldata, sender_address: invoke_args.sender_address, nonce: invoke_args.nonce, diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index dff96762b8..ec6d2c7be2 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -12,10 +12,10 @@ use starknet_api::transaction::{ Calldata, ContractAddressSalt, DeclareTransactionV2, - DeprecatedResourceBoundsMapping, Fee, TransactionHash, TransactionVersion, + ValidResourceBounds, }; use starknet_api::{calldata, class_hash, contract_address, felt, patricia_key}; use starknet_types_core::felt::Felt; @@ -80,7 +80,7 @@ use crate::{ }; #[rstest] -fn test_circuit(block_context: BlockContext, max_resource_bounds: DeprecatedResourceBoundsMapping) { +fn test_circuit(block_context: BlockContext, max_resource_bounds: ValidResourceBounds) { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1); let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); let chain_info = &block_context.chain_info; @@ -114,10 +114,7 @@ fn test_circuit(block_context: BlockContext, max_resource_bounds: DeprecatedReso } #[rstest] -fn test_rc96_holes( - block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, -) { +fn test_rc96_holes(block_context: BlockContext, max_resource_bounds: ValidResourceBounds) { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1); let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); let chain_info = &block_context.chain_info; @@ -208,7 +205,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_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(TransactionVersion::ZERO, TransactionVersion::ONE, TransactionVersion::THREE)] tx_version: TransactionVersion, #[values(true, false)] only_query: bool, @@ -240,7 +237,7 @@ fn test_account_flow_test( fn test_invoke_tx_from_non_deployed_account( block_context: BlockContext, max_fee: Fee, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[case] tx_version: TransactionVersion, ) { let TestInitData { mut state, account_address, contract_address: _, mut nonce_manager } = @@ -289,7 +286,7 @@ fn test_infinite_recursion( #[values(true, false)] success: bool, #[values(true, false)] normal_recurse: bool, mut block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { // Limit the number of execution steps (so we quickly hit the limit). block_context.versioned_constants.invoke_tx_max_n_steps = 4100; @@ -344,7 +341,7 @@ fn test_infinite_recursion( fn test_max_fee_limit_validate( block_context: BlockContext, #[case] version: TransactionVersion, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { let chain_info = &block_context.chain_info; let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = @@ -449,7 +446,7 @@ fn test_recursion_depth_exceeded( #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, block_context: BlockContext, max_fee: Fee, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = create_test_init_data(&block_context.chain_info, cairo_version); @@ -693,7 +690,7 @@ fn recursive_function_calldata( #[case(TransactionVersion::THREE)] fn test_reverted_reach_steps_limit( max_fee: Fee, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, mut block_context: BlockContext, #[case] version: TransactionVersion, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, @@ -801,7 +798,7 @@ 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_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = @@ -982,7 +979,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_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = @@ -1049,7 +1046,7 @@ fn test_insufficient_max_fee_reverts( #[rstest] fn test_deploy_account_constructor_storage_write( - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, block_context: BlockContext, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { @@ -1093,7 +1090,7 @@ fn test_deploy_account_constructor_storage_write( fn test_count_actual_storage_changes( max_fee: Fee, block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[case] version: TransactionVersion, #[case] fee_type: FeeType, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, @@ -1274,7 +1271,7 @@ fn test_count_actual_storage_changes( #[case::tx_version_3(TransactionVersion::THREE)] fn test_concurrency_execute_fee_transfer( max_fee: Fee, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[case] version: TransactionVersion, ) { // TODO(Meshi, 01/06/2024): make the test so it will include changes in @@ -1374,7 +1371,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_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[case] version: TransactionVersion, ) { let mut block_context = BlockContext::create_for_account_testing(); diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index 0ca7773148..ca9442bb9b 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -6,9 +6,9 @@ use starknet_api::felt; use starknet_api::transaction::{ Calldata, Fee, - DeprecatedResourceBoundsMapping, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; use starknet_types_core::felt::Felt; @@ -349,7 +349,7 @@ fn test_simulate_validate_charge_fee_fail_validate( #[values(CairoVersion::Cairo0)] cairo_version: CairoVersion, #[case] version: TransactionVersion, #[case] fee_type: FeeType, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { let block_context = BlockContext::create_for_account_testing(); let max_fee = Fee(MAX_FEE); @@ -411,7 +411,7 @@ fn test_simulate_validate_charge_fee_mid_execution( #[values(CairoVersion::Cairo0)] cairo_version: CairoVersion, #[case] version: TransactionVersion, #[case] fee_type: FeeType, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { let block_context = BlockContext::create_for_account_testing(); let chain_info = &block_context.chain_info; diff --git a/crates/blockifier/src/transaction/post_execution_test.rs b/crates/blockifier/src/transaction/post_execution_test.rs index 271718e7e0..0c5d9c10cc 100644 --- a/crates/blockifier/src/transaction/post_execution_test.rs +++ b/crates/blockifier/src/transaction/post_execution_test.rs @@ -2,12 +2,7 @@ use assert_matches::assert_matches; use rstest::rstest; use starknet_api::core::{ContractAddress, PatriciaKey}; use starknet_api::state::StorageKey; -use starknet_api::transaction::{ - Calldata, - DeprecatedResourceBoundsMapping, - Fee, - TransactionVersion, -}; +use starknet_api::transaction::{Calldata, Fee, TransactionVersion, ValidResourceBounds}; use starknet_api::{felt, patricia_key}; use starknet_types_core::felt::Felt; @@ -72,7 +67,7 @@ fn calldata_for_write_and_transfer( #[case(TransactionVersion::THREE, FeeType::Strk)] fn test_revert_on_overdraft( max_fee: Fee, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, block_context: BlockContext, #[case] version: TransactionVersion, #[case] fee_type: FeeType, @@ -217,7 +212,7 @@ fn test_revert_on_overdraft( #[case(TransactionVersion::THREE, "Insufficient max L1 gas", true)] fn test_revert_on_resource_overuse( max_fee: Fee, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, block_context: BlockContext, #[case] version: TransactionVersion, #[case] expected_error_prefix: &str, diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 637cf1235c..fd3c39781f 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -7,12 +7,11 @@ use starknet_api::transaction::{ InvokeTransactionV0, InvokeTransactionV1, InvokeTransactionV3, - Resource, ResourceBounds, - DeprecatedResourceBoundsMapping, TransactionHash, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; use starknet_api::{calldata, felt}; use starknet_types_core::felt::Felt; @@ -82,7 +81,7 @@ pub fn max_fee() -> Fee { } #[fixture] -pub fn max_resource_bounds() -> DeprecatedResourceBoundsMapping { +pub fn max_resource_bounds() -> ValidResourceBounds { l1_resource_bounds(MAX_L1_GAS_AMOUNT, MAX_L1_GAS_PRICE) } @@ -291,12 +290,8 @@ pub fn run_invoke_tx( /// Creates a `ResourceBoundsMapping` with the given `max_amount` and `max_price` for L1 gas limits. /// No guarantees on the values of the other resources bounds. -pub fn l1_resource_bounds(max_amount: u64, max_price: u128) -> DeprecatedResourceBoundsMapping { - DeprecatedResourceBoundsMapping::try_from(vec![ - (Resource::L1Gas, ResourceBounds { max_amount, max_price_per_unit: max_price }), - (Resource::L2Gas, ResourceBounds { max_amount: 0, max_price_per_unit: 0 }), - ]) - .unwrap() +pub fn l1_resource_bounds(max_amount: u64, max_price: u128) -> ValidResourceBounds { + ValidResourceBounds::L1Gas(ResourceBounds { max_amount, max_price_per_unit: max_price }) } pub fn calculate_class_info_for_testing(contract_class: ContractClass) -> ClassInfo { diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index f86b1db4df..1d1503c0fe 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -14,7 +14,6 @@ use starknet_api::deprecated_contract_class::EntryPointType; use starknet_api::state::StorageKey; use starknet_api::transaction::{ Calldata, - DeprecatedResourceBoundsMapping, EventContent, EventData, EventKey, @@ -22,6 +21,7 @@ use starknet_api::transaction::{ L2ToL1Payload, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; use starknet_api::{calldata, class_hash, contract_address, felt, patricia_key}; use starknet_types_core::felt::Felt; @@ -383,7 +383,7 @@ fn add_kzg_da_resources_to_resources_mapping( }, CairoVersion::Cairo1)] fn test_invoke_tx( - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[case] expected_arguments: ExpectedResultTestInvokeTx, #[case] account_cairo_version: CairoVersion, #[values(false, true)] use_kzg_da: bool, @@ -576,7 +576,7 @@ fn verify_storage_after_invoke_advanced_operations( #[rstest] fn test_invoke_tx_advanced_operations( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let block_context = &block_context; @@ -818,7 +818,7 @@ fn assert_failure_if_resource_bounds_exceed_balance( #[rstest] fn test_max_fee_exceeds_balance( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, ) { let block_context = &block_context; @@ -974,7 +974,7 @@ fn test_insufficient_resource_bounds( #[rstest] fn test_actual_fee_gt_resource_bounds( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, ) { let block_context = &block_context; @@ -1014,7 +1014,7 @@ fn test_actual_fee_gt_resource_bounds( #[rstest] fn test_invalid_nonce( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, ) { let account_contract = FeatureContract::AccountWithoutValidations(account_cairo_version); @@ -1134,7 +1134,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_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, #[case] tx_version: TransactionVersion, #[case] empty_contract_version: CairoVersion, @@ -1287,7 +1287,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_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { let block_context = &BlockContext::create_for_account_testing_with_kzg(use_kzg_da); let versioned_constants = &block_context.versioned_constants; @@ -1454,7 +1454,7 @@ fn test_deploy_account_tx( #[rstest] fn test_fail_deploy_account_undeclared_class_hash( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { let block_context = &block_context; let chain_info = &block_context.chain_info; @@ -1685,7 +1685,7 @@ fn test_validate_accounts_tx( #[rstest] fn test_valid_flag( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] test_contract_cairo_version: CairoVersion, ) { @@ -1713,7 +1713,7 @@ fn test_valid_flag( #[rstest] fn test_only_query_flag( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[values(true, false)] only_query: bool, ) { let account_balance = BALANCE; @@ -1955,7 +1955,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { #[rstest] fn test_execute_tx_with_invalid_transaction_version( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, ) { let cairo_version = CairoVersion::Cairo0; let account = FeatureContract::AccountWithoutValidations(cairo_version); @@ -2028,7 +2028,7 @@ fn max_event_data() -> usize { }))] fn test_emit_event_exceeds_limit( block_context: BlockContext, - max_resource_bounds: DeprecatedResourceBoundsMapping, + max_resource_bounds: ValidResourceBounds, #[case] event_keys: Vec, #[case] event_data: Vec, #[case] n_emitted_events: usize,