diff --git a/crates/blockifier/src/blockifier/stateful_validator_test.rs b/crates/blockifier/src/blockifier/stateful_validator_test.rs index de72c664e5..f9d66bb235 100644 --- a/crates/blockifier/src/blockifier/stateful_validator_test.rs +++ b/crates/blockifier/src/blockifier/stateful_validator_test.rs @@ -1,6 +1,6 @@ use assert_matches::assert_matches; use rstest::rstest; -use starknet_api::transaction::{Fee, TransactionVersion}; +use starknet_api::transaction::{DeprecatedResourceBoundsMapping, Fee, TransactionVersion}; use crate::blockifier::stateful_validator::StatefulValidator; use crate::context::BlockContext; @@ -11,6 +11,7 @@ use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::test_utils::{ block_context, create_account_tx_for_validate_test_nonce_0, + max_resource_bounds, FaultyAccountTxCreatorArgs, INVALID, VALID, @@ -32,6 +33,7 @@ fn test_transaction_validator( #[case] validate_constructor: bool, #[case] tx_version: TransactionVersion, block_context: BlockContext, + max_resource_bounds: DeprecatedResourceBoundsMapping, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let chain_info = &block_context.chain_info; @@ -44,16 +46,15 @@ fn test_transaction_validator( let mut state = test_state(chain_info, account_balance, &[(faulty_account, 1)]); - // TODO(Arni, 1/5/2024): Cover resource bounds in version 3 txs. Test the validator validate - // enough "fee" in version 3 txs. let transaction_args = FaultyAccountTxCreatorArgs { tx_type, tx_version, sender_address, class_hash, validate_constructor, - // TODO(Arni, 1/5/2024): Add test for insufficient max fee. + // TODO(Arni, 1/5/2024): Add test for insufficient maximal resources. max_fee: Fee(BALANCE), + resource_bounds: max_resource_bounds, ..Default::default() }; @@ -68,13 +69,13 @@ fn test_transaction_validator( // Test the stateful validator. let mut stateful_validator = StatefulValidator::create(state, block_context); - - let result = stateful_validator.perform_validations(tx, false); + let skip_validate = false; + let result = stateful_validator.perform_validations(tx, skip_validate); assert!(result.is_ok(), "Validation failed: {:?}", result.unwrap_err()); } -#[test] -fn test_transaction_validator_skip_validate() { +#[rstest] +fn test_transaction_validator_skip_validate(max_resource_bounds: DeprecatedResourceBoundsMapping) { 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)]); @@ -86,7 +87,7 @@ fn test_transaction_validator_skip_validate() { tx_version: TransactionVersion::THREE, sender_address: faulty_account.get_instance_address(0), class_hash: faulty_account.get_class_hash(), - max_fee: Fee(BALANCE), + resource_bounds: max_resource_bounds, ..Default::default() }); diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index b2afd89626..4cff243a20 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -211,7 +211,7 @@ pub fn trivial_external_entry_point_with_address( } } -fn default_testing_resource_bounds() -> DeprecatedResourceBoundsMapping { +pub 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 diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 621a69052c..e2f3e18cf6 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -31,6 +31,7 @@ use crate::test_utils::initial_test_state::test_state; use crate::test_utils::invoke::{invoke_tx, InvokeTxArgs}; use crate::test_utils::{ create_calldata, + default_testing_resource_bounds, CairoVersion, NonceManager, BALANCE, @@ -145,6 +146,7 @@ pub struct FaultyAccountTxCreatorArgs { pub tx_version: TransactionVersion, pub scenario: u64, pub max_fee: Fee, + pub resource_bounds: DeprecatedResourceBoundsMapping, // Should be None unless scenario is CALL_CONTRACT. pub additional_data: Option>, // Should be use with tx_type Declare or InvokeFunction. @@ -171,6 +173,7 @@ impl Default for FaultyAccountTxCreatorArgs { contract_address_salt: ContractAddressSalt::default(), validate_constructor: false, max_fee: Fee::default(), + resource_bounds: default_testing_resource_bounds(), declared_contract: None, } } @@ -206,6 +209,7 @@ pub fn create_account_tx_for_validate_test( contract_address_salt, validate_constructor, max_fee, + resource_bounds, declared_contract, } = faulty_account_tx_creator_args; @@ -231,6 +235,7 @@ pub fn create_account_tx_for_validate_test( declare_tx( declare_tx_args! { max_fee, + resource_bounds: resource_bounds.clone(), signature, sender_address, version: tx_version, @@ -251,6 +256,7 @@ pub fn create_account_tx_for_validate_test( let deploy_account_tx = deploy_account_tx( deploy_account_tx_args! { max_fee, + resource_bounds: resource_bounds.clone(), signature, version: tx_version, class_hash, @@ -265,6 +271,7 @@ pub fn create_account_tx_for_validate_test( let execute_calldata = create_calldata(sender_address, "foo", &[]); let invoke_tx = invoke_tx(invoke_tx_args! { max_fee, + resource_bounds, signature, sender_address, calldata: execute_calldata, diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 78ff672651..5e670f08ab 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -66,6 +66,7 @@ use crate::test_utils::prices::Prices; use crate::test_utils::{ create_calldata, create_trivial_calldata, + default_testing_resource_bounds, get_syscall_resources, get_tx_resources, test_erc20_sequencer_balance_key, @@ -1556,6 +1557,7 @@ fn test_validate_accounts_tx( * the address of * faulty_account. */ contract_address_salt: salt_manager.next_salt(), + resource_bounds: default_testing_resource_bounds(), ..default_args }); let error = account_tx.execute(state, block_context, true, true).unwrap_err(); @@ -1571,6 +1573,7 @@ fn test_validate_accounts_tx( scenario: GET_BLOCK_HASH, contract_address_salt: salt_manager.next_salt(), additional_data: None, + resource_bounds: default_testing_resource_bounds(), ..default_args }); let error = account_tx.execute(state, block_context, true, true).unwrap_err(); @@ -1585,6 +1588,7 @@ fn test_validate_accounts_tx( let account_tx = create_account_tx_for_validate_test_nonce_0(FaultyAccountTxCreatorArgs { scenario: GET_SEQUENCER_ADDRESS, contract_address_salt: salt_manager.next_salt(), + resource_bounds: default_testing_resource_bounds(), ..default_args }); let error = account_tx.execute(state, block_context, true, true).unwrap_err(); @@ -1607,6 +1611,7 @@ fn test_validate_accounts_tx( contract_address_salt: salt_manager.next_salt(), additional_data: None, declared_contract: Some(FeatureContract::TestContract(declared_contract_cairo_version)), + resource_bounds: default_testing_resource_bounds(), ..default_args }, ); @@ -1623,6 +1628,7 @@ fn test_validate_accounts_tx( declared_contract: Some(FeatureContract::AccountWithLongValidate( declared_contract_cairo_version, )), + resource_bounds: default_testing_resource_bounds(), ..default_args }, ); @@ -1642,6 +1648,7 @@ fn test_validate_accounts_tx( declared_contract: Some(FeatureContract::AccountWithoutValidations( declared_contract_cairo_version, )), + resource_bounds: default_testing_resource_bounds(), ..default_args }, ); @@ -1657,6 +1664,7 @@ fn test_validate_accounts_tx( contract_address_salt: salt_manager.next_salt(), additional_data: Some(vec![Felt::from(CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE)]), declared_contract: Some(FeatureContract::Empty(declared_contract_cairo_version)), + resource_bounds: default_testing_resource_bounds(), ..default_args }, ); @@ -1678,6 +1686,7 @@ fn test_validate_accounts_tx( Felt::from(0_u64), // Sequencer address for validate. ]), declared_contract: Some(FeatureContract::Empty(declared_contract_cairo_version)), + resource_bounds: default_testing_resource_bounds(), ..default_args }, );