From ab56dd12580d3d330c52880778182a47bd5cf5cc Mon Sep 17 00:00:00 2001 From: AvivYossef-starkware Date: Sun, 15 Dec 2024 16:46:41 +0200 Subject: [PATCH] chore(blockifier): add get versioned class to feature contract --- crates/blockifier/src/test_utils/contracts.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/blockifier/src/test_utils/contracts.rs b/crates/blockifier/src/test_utils/contracts.rs index 2980112f53e..66ae844cced 100644 --- a/crates/blockifier/src/test_utils/contracts.rs +++ b/crates/blockifier/src/test_utils/contracts.rs @@ -5,7 +5,7 @@ use cairo_lang_starknet_classes::contract_class::ContractClass as CairoLangContr use itertools::Itertools; use starknet_api::abi::abi_utils::selector_from_name; use starknet_api::abi::constants::CONSTRUCTOR_ENTRY_POINT_NAME; -use starknet_api::contract_class::{ContractClass, EntryPointType}; +use starknet_api::contract_class::{ContractClass, EntryPointType, SierraVersion}; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, EntryPointSelector}; use starknet_api::deprecated_contract_class::{ ContractClass as DeprecatedContractClass, @@ -17,7 +17,7 @@ use starknet_types_core::felt::Felt; use strum::IntoEnumIterator; use strum_macros::EnumIter; -use crate::execution::contract_class::RunnableCompiledClass; +use crate::execution::contract_class::{RunnableCompiledClass, VersionedRunnableCompiledClass}; use crate::execution::entry_point::CallEntryPoint; #[cfg(feature = "cairo_native")] use crate::execution::native::contract_class::NativeCompiledClassV1; @@ -190,6 +190,18 @@ impl FeatureContract { self.get_class().try_into().unwrap() } + #[allow(dead_code)] + pub fn get_versioned_runnable_class(&self) -> VersionedRunnableCompiledClass { + let runnable_class = self.get_runnable_class(); + match self.cairo_version() { + CairoVersion::Cairo0 => VersionedRunnableCompiledClass::Cairo0(runnable_class), + + CairoVersion::Cairo1(_) => { + VersionedRunnableCompiledClass::Cairo1((runnable_class, self.get_sierra_version())) + } + } + } + pub fn get_raw_sierra(&self) -> String { if self.cairo_version() == CairoVersion::Cairo0 { panic!("The sierra contract is only available for Cairo1."); @@ -205,6 +217,10 @@ impl FeatureContract { SierraContractClass::from(cairo_contract_class) } + pub fn get_sierra_version(&self) -> SierraVersion { + SierraVersion::extract_from_program(&self.get_sierra().sierra_program).unwrap() + } + pub fn get_raw_class(&self) -> String { get_raw_contract_class(&self.get_compiled_path()) }