diff --git a/crates/blockifier/src/blockifier/stateful_validator_test.rs b/crates/blockifier/src/blockifier/stateful_validator_test.rs index afafad290dc..11c7a30fc58 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::{Fee, ResourceBoundsMapping, 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: ResourceBoundsMapping, #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion, ) { let chain_info = &block_context.chain_info; @@ -54,6 +56,7 @@ fn test_transaction_validator( validate_constructor, // TODO(Arni, 1/5/2024): Add test for insufficient max fee. max_fee: Fee(BALANCE), + resource_bounds: max_resource_bounds, ..Default::default() }; @@ -69,12 +72,12 @@ 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, false); + let result = stateful_validator.perform_validations(tx, false, true); 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: ResourceBoundsMapping) { 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,6 +90,7 @@ fn test_transaction_validator_skip_validate() { 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 6832b5601c8..b10e44c2d98 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -210,7 +210,7 @@ pub fn trivial_external_entry_point_with_address( } } -fn default_testing_resource_bounds() -> ResourceBoundsMapping { +pub fn default_testing_resource_bounds() -> ResourceBoundsMapping { ResourceBoundsMapping::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 1e60f5a2443..06985d46d44 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, @@ -146,6 +147,7 @@ pub struct FaultyAccountTxCreatorArgs { pub tx_version: TransactionVersion, pub scenario: u64, pub max_fee: Fee, + pub resource_bounds: ResourceBoundsMapping, // Should be None unless scenario is CALL_CONTRACT. pub additional_data: Option>, // Should be use with tx_type Declare or InvokeFunction. @@ -172,6 +174,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, } } @@ -207,6 +210,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; @@ -232,6 +236,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, @@ -252,6 +257,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, @@ -266,6 +272,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 da090218e5a..9a56b1dd2b4 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -67,6 +67,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, @@ -1552,6 +1553,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, false, true).unwrap_err(); @@ -1567,6 +1569,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, false, true).unwrap_err(); @@ -1581,6 +1584,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, false, true).unwrap_err(); @@ -1603,6 +1607,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 }, ); @@ -1619,6 +1624,7 @@ fn test_validate_accounts_tx( declared_contract: Some(FeatureContract::AccountWithLongValidate( declared_contract_cairo_version, )), + resource_bounds: default_testing_resource_bounds(), ..default_args }, ); @@ -1638,6 +1644,7 @@ fn test_validate_accounts_tx( declared_contract: Some(FeatureContract::AccountWithoutValidations( declared_contract_cairo_version, )), + resource_bounds: default_testing_resource_bounds(), ..default_args }, ); @@ -1653,6 +1660,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 }, ); @@ -1674,6 +1682,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 }, );