@@ -14,11 +14,15 @@ use crate::execution::contract_class::RunnableCompiledClass;
1414use crate :: execution:: entry_point:: EntryPointTypeAndSelector ;
1515#[ cfg( feature = "cairo_native" ) ]
1616use crate :: execution:: native:: contract_class:: NativeCompiledClassV1 ;
17+ #[ cfg( feature = "cairo_native" ) ]
18+ use crate :: state:: global_cache:: CachedCairoNative ;
19+ use crate :: state:: global_cache:: CachedClass ;
1720use crate :: test_utils:: struct_impls:: LoadContractFromFile ;
1821
1922pub trait FeatureContractTrait {
2023 fn get_class ( & self ) -> ContractClass ;
2124 fn get_runnable_class ( & self ) -> RunnableCompiledClass ;
25+ fn get_cached_class ( & self ) -> CachedClass ;
2226
2327 /// Fetch PC locations from the compiled contract to compute the expected PC locations in the
2428 /// traceback. Computation is not robust, but as long as the cairo function itself is not
@@ -97,12 +101,30 @@ impl FeatureContractTrait for FeatureContract {
97101
98102 self . get_class ( ) . try_into ( ) . unwrap ( )
99103 }
104+
105+ fn get_cached_class ( & self ) -> CachedClass {
106+ #[ cfg( feature = "cairo_native" ) ]
107+ if CairoVersion :: Cairo1 ( RunnableCairo1 :: Native ) == self . cairo_version ( ) {
108+ let native_contract_class =
109+ NativeCompiledClassV1 :: compile_or_get_cached ( & self . get_compiled_path ( ) ) ;
110+ return CachedClass :: V1Native ( CachedCairoNative :: Compiled (
111+ native_contract_class. clone ( ) ,
112+ ) ) ;
113+ }
114+
115+ match self . get_class ( ) {
116+ ContractClass :: V0 ( class) => CachedClass :: V0 ( class. try_into ( ) . unwrap ( ) ) ,
117+ ContractClass :: V1 ( class) => {
118+ CachedClass :: V1 ( class. try_into ( ) . unwrap ( ) , self . get_sierra ( ) . into ( ) )
119+ }
120+ }
121+ }
100122}
101123
102124/// The information needed to test a [FeatureContract].
103125pub struct FeatureContractData {
104126 pub class_hash : ClassHash ,
105- pub runnable_class : RunnableCompiledClass ,
127+ pub cached_class : CachedClass ,
106128 pub require_funding : bool ,
107129 integer_base : u32 ,
108130}
@@ -126,7 +148,7 @@ impl From<FeatureContract> for FeatureContractData {
126148
127149 Self {
128150 class_hash : contract. get_class_hash ( ) ,
129- runnable_class : contract. get_runnable_class ( ) ,
151+ cached_class : contract. get_cached_class ( ) ,
130152 require_funding,
131153 integer_base : contract. get_integer_base ( ) ,
132154 }
0 commit comments