|
1 | 1 | use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1}; |
2 | 2 | use blockifier_test_utils::contracts::FeatureContract; |
| 3 | +use cached::proc_macro::cached; |
3 | 4 | use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; |
4 | 5 | use starknet_api::abi::abi_utils::selector_from_name; |
5 | 6 | use starknet_api::abi::constants::CONSTRUCTOR_ENTRY_POINT_NAME; |
@@ -71,21 +72,28 @@ pub trait FeatureContractTrait { |
71 | 72 | } |
72 | 73 | } |
73 | 74 |
|
| 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 | + |
74 | 94 | impl FeatureContractTrait for FeatureContract { |
75 | 95 | 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) |
89 | 97 | } |
90 | 98 |
|
91 | 99 | fn get_runnable_class(&self) -> RunnableCompiledClass { |
|
0 commit comments