Skip to content

Commit be03442

Browse files
blockifier: cache get_class for feature contracts (#8499)
1 parent 04edaa0 commit be03442

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

crates/blockifier/src/test_utils/contracts.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
22
use blockifier_test_utils::contracts::FeatureContract;
3+
use cached::proc_macro::cached;
34
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
45
use starknet_api::abi::abi_utils::selector_from_name;
56
use starknet_api::abi::constants::CONSTRUCTOR_ENTRY_POINT_NAME;
@@ -71,21 +72,28 @@ pub trait FeatureContractTrait {
7172
}
7273
}
7374

75+
#[cached]
76+
// Note: This function is defined outside of the impl block to allow caching.
77+
// The `#[cached]` macro doesn't support caching functions that take self as an argument.
78+
fn get_class_for_feature_contract(feature_contract: FeatureContract) -> ContractClass {
79+
match feature_contract.cairo_version() {
80+
CairoVersion::Cairo0 => ContractClass::V0(DeprecatedContractClass::from_file(
81+
&feature_contract.get_compiled_path(),
82+
)),
83+
CairoVersion::Cairo1(RunnableCairo1::Casm) => ContractClass::V1((
84+
CasmContractClass::from_file(&feature_contract.get_compiled_path()),
85+
feature_contract.get_sierra_version(),
86+
)),
87+
#[cfg(feature = "cairo_native")]
88+
CairoVersion::Cairo1(RunnableCairo1::Native) => {
89+
panic!("Native contracts are not supported by this function.")
90+
}
91+
}
92+
}
93+
7494
impl FeatureContractTrait for FeatureContract {
7595
fn get_class(&self) -> ContractClass {
76-
match self.cairo_version() {
77-
CairoVersion::Cairo0 => {
78-
ContractClass::V0(DeprecatedContractClass::from_file(&self.get_compiled_path()))
79-
}
80-
CairoVersion::Cairo1(RunnableCairo1::Casm) => ContractClass::V1((
81-
CasmContractClass::from_file(&self.get_compiled_path()),
82-
self.get_sierra_version(),
83-
)),
84-
#[cfg(feature = "cairo_native")]
85-
CairoVersion::Cairo1(RunnableCairo1::Native) => {
86-
panic!("Native contracts are not supported by this function.")
87-
}
88-
}
96+
get_class_for_feature_contract(*self)
8997
}
9098

9199
fn get_runnable_class(&self) -> RunnableCompiledClass {

0 commit comments

Comments
 (0)