diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 206012bdb9e..f39005984f4 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -20,11 +20,7 @@ use starknet_api::core::{ClassHash, ContractAddress, PatriciaKey}; use starknet_api::execution_resources::{GasAmount, GasVector}; use starknet_api::state::StorageKey; use starknet_api::transaction::{ - Calldata, - ContractAddressSalt, - Fee, - GasVectorComputationMode, - TransactionVersion, + Calldata, ContractAddressSalt, Fee, GasVectorComputationMode, TransactionVersion, }; use starknet_api::{contract_address, felt, patricia_key}; use starknet_types_core::felt::Felt; @@ -62,6 +58,7 @@ pub const ERC20_CONTRACT_PATH: &str = "./ERC20/ERC20_Cairo0/ERC20_without_some_s pub enum CairoVersion { Cairo0, Cairo1, + #[cfg(feature = "cairo_native")] Native, } @@ -89,6 +86,7 @@ impl CairoVersion { match self { Self::Cairo0 => Self::Cairo1, Self::Cairo1 => Self::Cairo0, + #[cfg(feature = "cairo_native")] Self::Native => todo!("who should be your other?"), } } @@ -116,6 +114,8 @@ impl CompilerBasedVersion { TrackedResource::CairoSteps } Self::CairoVersion(CairoVersion::Cairo1) => TrackedResource::SierraGas, + #[cfg(feature = "cairo_native")] + Self::CairoVersion(CairoVersion::Native) => TrackedResource::SierraGas, } } } @@ -323,7 +323,19 @@ macro_rules! check_tx_execution_error_for_invalid_scenario { $validate_constructor, ); } - CairoVersion::Cairo1 | CairoVersion::Native => { + CairoVersion::Cairo1 => { + if let $crate::transaction::errors::TransactionExecutionError::ValidateTransactionError { + error, .. + } = $error { + assert_eq!( + error.to_string(), + "Execution failed. Failure reason: 0x496e76616c6964207363656e6172696f \ + ('Invalid scenario')." + ) + } + } + #[cfg(feature = "cairo_native")] + CairoVersion::Cairo1 => { if let $crate::transaction::errors::TransactionExecutionError::ValidateTransactionError { error, .. } = $error { diff --git a/crates/blockifier/src/test_utils/contracts.rs b/crates/blockifier/src/test_utils/contracts.rs index 0ebd2d18c16..8def2df8649 100644 --- a/crates/blockifier/src/test_utils/contracts.rs +++ b/crates/blockifier/src/test_utils/contracts.rs @@ -1,14 +1,9 @@ use starknet_api::contract_class::EntryPointType; use starknet_api::core::{ - ClassHash, - CompiledClassHash, - ContractAddress, - EntryPointSelector, - PatriciaKey, + ClassHash, CompiledClassHash, ContractAddress, EntryPointSelector, PatriciaKey, }; use starknet_api::deprecated_contract_class::{ - ContractClass as DeprecatedContractClass, - EntryPointOffset, + ContractClass as DeprecatedContractClass, EntryPointOffset, }; use starknet_api::{class_hash, contract_address, felt, patricia_key}; use starknet_types_core::felt::Felt; @@ -17,14 +12,14 @@ use strum_macros::EnumIter; use crate::abi::abi_utils::selector_from_name; use crate::abi::constants::CONSTRUCTOR_ENTRY_POINT_NAME; -use crate::execution::contract_class::{ - ContractClass, - ContractClassV0, - ContractClassV1, - NativeContractClassV1, -}; +use crate::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; use crate::execution::entry_point::CallEntryPoint; -use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile, starknet_compile}; +#[cfg(feature = "cairo_native")] +use crate::execution::native::contract_class::NativeContractClassV1; +#[cfg(feature = "cairo_native")] +use crate::test_utils::cairo_compile::starknet_compile; + +use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile}; use crate::test_utils::{get_raw_contract_class, CairoVersion}; // This file contains featured contracts, used for tests. Use the function 'test_state' in @@ -149,9 +144,9 @@ impl FeatureContract { pub fn get_compiled_class_hash(&self) -> CompiledClassHash { match self.cairo_version() { CairoVersion::Cairo0 => CompiledClassHash(Felt::ZERO), - CairoVersion::Cairo1 | CairoVersion::Native => { - CompiledClassHash(felt!(self.get_integer_base())) - } + CairoVersion::Cairo1 => CompiledClassHash(felt!(self.get_integer_base())), + #[cfg(feature = "cairo_native")] + CairoVersion::Native => CompiledClassHash(felt!(self.get_integer_base())), } } @@ -165,6 +160,7 @@ impl FeatureContract { match self.cairo_version() { CairoVersion::Cairo0 => ContractClassV0::from_file(&self.get_compiled_path()).into(), CairoVersion::Cairo1 => ContractClassV1::from_file(&self.get_compiled_path()).into(), + #[cfg(feature = "cairo_native")] CairoVersion::Native => { NativeContractClassV1::from_file(&self.get_compiled_path()).into() } @@ -193,7 +189,9 @@ impl FeatureContract { fn get_cairo_version_bit(&self) -> u32 { match self.cairo_version() { CairoVersion::Cairo0 => 0, - CairoVersion::Cairo1 | CairoVersion::Native => CAIRO1_BIT, + CairoVersion::Cairo1 => CAIRO1_BIT, + #[cfg(feature = "cairo_native")] + CairoVersion::Native => CAIRO1_BIT, } } @@ -250,6 +248,7 @@ impl FeatureContract { match cairo_version { CairoVersion::Cairo0 => ERC20_CAIRO0_CONTRACT_SOURCE_PATH, CairoVersion::Cairo1 => ERC20_CAIRO1_CONTRACT_SOURCE_PATH, + #[cfg(feature = "cairo_native")] CairoVersion::Native => todo!("ERC20 cannot be tested with Native"), } .into() @@ -259,6 +258,7 @@ impl FeatureContract { match self.cairo_version() { CairoVersion::Cairo0 => "0", CairoVersion::Cairo1 => "1", + #[cfg(feature = "cairo_native")] CairoVersion::Native => "_native", }, self.get_non_erc20_base_name() @@ -272,6 +272,7 @@ impl FeatureContract { match cairo_version { CairoVersion::Cairo0 => ERC20_CAIRO0_CONTRACT_PATH, CairoVersion::Cairo1 => ERC20_CAIRO1_CONTRACT_PATH, + #[cfg(feature = "cairo_native")] CairoVersion::Native => todo!("ERC20 cannot be tested with Native"), } .into() @@ -282,12 +283,14 @@ impl FeatureContract { match cairo_version { CairoVersion::Cairo0 => "0", CairoVersion::Cairo1 => "1", + #[cfg(feature = "cairo_native")] CairoVersion::Native => "_native", }, self.get_non_erc20_base_name(), match cairo_version { CairoVersion::Cairo0 => "_compiled", CairoVersion::Cairo1 => ".casm", + #[cfg(feature = "cairo_native")] CairoVersion::Native => ".sierra", } ) @@ -320,6 +323,7 @@ impl FeatureContract { let (tag_override, cargo_nightly_arg) = self.fixed_tag_and_rust_toolchain(); cairo1_compile(self.get_source_path(), tag_override, cargo_nightly_arg) } + #[cfg(feature = "cairo_native")] CairoVersion::Native => starknet_compile(self.get_source_path(), None, None), } } diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 07fb15fc73c..349d71a9534 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -1,6 +1,10 @@ use std::sync::Arc; +#[cfg(feature = "cairo_native")] +use crate::execution::native::contract_class::NativeContractClassV1; +#[cfg(feature = "cairo_native")] use cairo_native::executor::AotNativeExecutor; + use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use serde_json::Value; use starknet_api::block::{BlockHash, BlockNumber, BlockTimestamp, NonzeroGasPrice}; @@ -18,32 +22,21 @@ use crate::bouncer::{BouncerConfig, BouncerWeights, BuiltinCount}; use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}; use crate::execution::call_info::{CallExecution, CallInfo, Retdata}; use crate::execution::common_hints::ExecutionMode; -use crate::execution::contract_class::{ContractClassV0, ContractClassV1, NativeContractClassV1}; +use crate::execution::contract_class::{ContractClassV0, ContractClassV1}; use crate::execution::entry_point::{ - CallEntryPoint, - EntryPointExecutionContext, - EntryPointExecutionResult, + CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult, }; use crate::state::state_api::State; use crate::test_utils::{ - get_raw_contract_class, - CURRENT_BLOCK_NUMBER, - CURRENT_BLOCK_TIMESTAMP, - DEFAULT_ETH_L1_DATA_GAS_PRICE, - DEFAULT_ETH_L1_GAS_PRICE, - DEFAULT_STRK_L1_DATA_GAS_PRICE, - DEFAULT_STRK_L1_GAS_PRICE, - TEST_ERC20_CONTRACT_ADDRESS, - TEST_ERC20_CONTRACT_ADDRESS2, + get_raw_contract_class, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TIMESTAMP, + DEFAULT_ETH_L1_DATA_GAS_PRICE, DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_STRK_L1_DATA_GAS_PRICE, + DEFAULT_STRK_L1_GAS_PRICE, TEST_ERC20_CONTRACT_ADDRESS, TEST_ERC20_CONTRACT_ADDRESS2, TEST_SEQUENCER_ADDRESS, }; use crate::transaction::objects::{DeprecatedTransactionInfo, TransactionInfo}; use crate::transaction::transactions::L1HandlerTransaction; use crate::versioned_constants::{ - GasCosts, - OsConstants, - VersionedConstants, - VERSIONED_CONSTANTS_LATEST_JSON, + GasCosts, OsConstants, VersionedConstants, VERSIONED_CONSTANTS_LATEST_JSON, }; impl CallEntryPoint { @@ -264,6 +257,7 @@ impl BouncerWeights { } } +#[cfg(feature = "cairo_native")] impl NativeContractClassV1 { /// Convenience function to construct a NativeContractClassV1 from a raw contract class. /// If control over the compilation is desired use [Self::new] instead. diff --git a/crates/tests-integration/Cargo.toml b/crates/tests-integration/Cargo.toml index 294c3470fbb..cb09b5c0c01 100644 --- a/crates/tests-integration/Cargo.toml +++ b/crates/tests-integration/Cargo.toml @@ -8,6 +8,9 @@ license.workspace = true [lints] workspace = true +[features] +cairo_native = ["blockifier/cairo_native"] + [dependencies] anyhow.workspace = true assert_matches.workspace = true diff --git a/crates/tests-integration/src/state_reader.rs b/crates/tests-integration/src/state_reader.rs index b566245d0b0..0d7d7e94f3f 100644 --- a/crates/tests-integration/src/state_reader.rs +++ b/crates/tests-integration/src/state_reader.rs @@ -6,12 +6,8 @@ use blockifier::abi::abi_utils::get_fee_token_var_address; use blockifier::context::{BlockContext, ChainInfo}; use blockifier::test_utils::contracts::FeatureContract; use blockifier::test_utils::{ - CairoVersion, - BALANCE, - CURRENT_BLOCK_TIMESTAMP, - DEFAULT_ETH_L1_GAS_PRICE, - DEFAULT_STRK_L1_GAS_PRICE, - TEST_SEQUENCER_ADDRESS, + CairoVersion, BALANCE, CURRENT_BLOCK_TIMESTAMP, DEFAULT_ETH_L1_GAS_PRICE, + DEFAULT_STRK_L1_GAS_PRICE, TEST_SEQUENCER_ADDRESS, }; use blockifier::transaction::objects::FeeType; use blockifier::versioned_constants::VersionedConstants; @@ -28,20 +24,10 @@ use papyrus_storage::state::StateStorageWriter; use papyrus_storage::test_utils::{get_test_storage, get_test_storage_with_config_by_scope}; use papyrus_storage::{StorageConfig, StorageReader, StorageWriter}; use starknet_api::block::{ - BlockBody, - BlockHeader, - BlockHeaderWithoutHash, - BlockNumber, - BlockTimestamp, - GasPricePerToken, + BlockBody, BlockHeader, BlockHeaderWithoutHash, BlockNumber, BlockTimestamp, GasPricePerToken, }; use starknet_api::core::{ - ChainId, - ClassHash, - ContractAddress, - Nonce, - PatriciaKey, - SequencerContractAddress, + ChainId, ClassHash, ContractAddress, Nonce, PatriciaKey, SequencerContractAddress, }; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::state::{StorageKey, ThinStateDiff}; @@ -183,7 +169,10 @@ fn prepare_compiled_contract_classes( serde_json::from_str(&contract.raw_class()).unwrap(), )); } - CairoVersion::Native => todo!("look up what we need here"), + #[cfg(feature = "cairo_native")] + CairoVersion::Native => { + todo!("native integration doesn't support this yet") + } } } @@ -319,8 +308,9 @@ impl<'a> ThinStateDiffBuilder<'a> { CairoVersion::Cairo1 => { self.declared_classes.insert(contract.class_hash(), Default::default()); } + #[cfg(feature = "cairo_native")] CairoVersion::Native => { - todo!("look up what we need to do here") + todo!("native integration doesn't support this yet") } } }