diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 572d05e305..d320992ecf 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -19,6 +19,7 @@ use starknet_api::hash::{StarkFelt, StarkHash}; use starknet_api::state::StorageKey; use starknet_api::transaction::{ Calldata, ContractAddressSalt, Resource, ResourceBounds, ResourceBoundsMapping, + TransactionVersion, }; use starknet_api::{contract_address, patricia_key, stark_felt}; @@ -61,6 +62,18 @@ impl Default for CairoVersion { } } +impl CairoVersion { + // A declare transaction of the given version, can be used to declare contracts of the returned + // cairo version. + pub fn from_declare_tx_version(tx_version: TransactionVersion) -> Self { + match tx_version { + TransactionVersion::ZERO | TransactionVersion::ONE => CairoVersion::Cairo0, + TransactionVersion::TWO | TransactionVersion::THREE => CairoVersion::Cairo1, + _ => panic!("Transaction version {:?} is not supported.", tx_version), + } + } +} + // Storage keys. pub fn test_erc20_sequencer_balance_key() -> StorageKey { get_fee_token_var_address(contract_address!(TEST_SEQUENCER_ADDRESS)) diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 9ceb8399ec..affb811aa7 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -130,6 +130,7 @@ pub struct FaultyAccountTxCreatorArgs { pub tx_type: TransactionType, pub tx_version: TransactionVersion, pub scenario: u64, + pub max_fee: Fee, // Should be None unless scenario is CALL_CONTRACT. pub additional_data: Option>, // Should be use with tx_type Declare or InvokeFunction. @@ -140,7 +141,8 @@ pub struct FaultyAccountTxCreatorArgs { pub contract_address_salt: ContractAddressSalt, // Should be used with tx_type DeployAccount. pub validate_constructor: bool, - pub max_fee: Fee, + // Should be used with tx_type Declare. + pub declared_contract: Option, } impl Default for FaultyAccountTxCreatorArgs { @@ -155,6 +157,7 @@ impl Default for FaultyAccountTxCreatorArgs { contract_address_salt: ContractAddressSalt::default(), validate_constructor: false, max_fee: Fee::default(), + declared_contract: None, } } } @@ -176,6 +179,7 @@ pub fn create_account_tx_for_validate_test( contract_address_salt, validate_constructor, max_fee, + declared_contract, } = faulty_account_tx_creator_args; // The first felt of the signature is used to set the scenario. If the scenario is @@ -188,13 +192,13 @@ pub fn create_account_tx_for_validate_test( match tx_type { TransactionType::Declare => { - // It does not matter which class is declared for this test. - let declared_contract_cairo_version = match tx_version { - TransactionVersion::ZERO | TransactionVersion::ONE => CairoVersion::Cairo0, - TransactionVersion::TWO | TransactionVersion::THREE => CairoVersion::Cairo1, - _ => panic!("Transaction version {:?} is not supported.", tx_version), + let declared_contract = match declared_contract { + Some(declared_contract) => declared_contract, + None => { + // It does not matter which class is declared for this test. + FeatureContract::TestContract(CairoVersion::from_declare_tx_version(tx_version)) + } }; - let declared_contract = FeatureContract::TestContract(declared_contract_cairo_version); let class_hash = declared_contract.get_class_hash(); let class_info = calculate_class_info_for_testing(declared_contract.get_class()); declare_tx( diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 33d297fa37..840ae7620f 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1407,6 +1407,8 @@ fn test_fail_deploy_account_undeclared_class_hash(block_context: BlockContext) { #[case::validate_version_1(TransactionType::InvokeFunction, false, TransactionVersion::ONE)] #[case::validate_version_3(TransactionType::InvokeFunction, false, TransactionVersion::THREE)] #[case::validate_declare_version_1(TransactionType::Declare, false, TransactionVersion::ONE)] +#[case::validate_declare_version_2(TransactionType::Declare, false, TransactionVersion::TWO)] +#[case::validate_declare_version_3(TransactionType::Declare, false, TransactionVersion::THREE)] #[case::validate_deploy_version_1(TransactionType::DeployAccount, false, TransactionVersion::ONE)] #[case::validate_deploy_version_3(TransactionType::DeployAccount, false, TransactionVersion::THREE)] #[case::constructor_version_1(TransactionType::DeployAccount, true, TransactionVersion::ONE)] @@ -1513,12 +1515,14 @@ fn test_validate_accounts_tx( // Valid logic. let nonce_manager = &mut NonceManager::default(); + let declared_contract_cairo_version = CairoVersion::from_declare_tx_version(tx_version); let account_tx = create_account_tx_for_validate_test( nonce_manager, FaultyAccountTxCreatorArgs { scenario: VALID, contract_address_salt: salt_manager.next_salt(), additional_data: None, + declared_contract: Some(FeatureContract::TestContract(declared_contract_cairo_version)), ..default_args }, ); @@ -1532,6 +1536,9 @@ fn test_validate_accounts_tx( FaultyAccountTxCreatorArgs { scenario: CALL_CONTRACT, additional_data: Some(vec![*sender_address.0.key()]), + declared_contract: Some(FeatureContract::AccountWithLongValidate( + declared_contract_cairo_version, + )), ..default_args }, ); @@ -1548,6 +1555,9 @@ fn test_validate_accounts_tx( scenario: GET_BLOCK_NUMBER, contract_address_salt: salt_manager.next_salt(), additional_data: Some(vec![StarkFelt::from(CURRENT_BLOCK_NUMBER_FOR_VALIDATE)]), + declared_contract: Some(FeatureContract::AccountWithoutValidations( + declared_contract_cairo_version, + )), ..default_args }, ); @@ -1562,6 +1572,7 @@ fn test_validate_accounts_tx( scenario: GET_BLOCK_TIMESTAMP, contract_address_salt: salt_manager.next_salt(), additional_data: Some(vec![StarkFelt::from(CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE)]), + declared_contract: Some(FeatureContract::Empty(declared_contract_cairo_version)), ..default_args }, ); @@ -1582,6 +1593,7 @@ fn test_validate_accounts_tx( StarkFelt::from(CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE), StarkFelt::from(0_u64), // Sequencer address for validate. ]), + declared_contract: Some(FeatureContract::Empty(declared_contract_cairo_version)), ..default_args }, );