1- #[ cfg( not( feature = "cairo_native" ) ) ]
2- use std:: sync:: LazyLock ;
1+ use std:: sync:: { Arc , LazyLock } ;
32
43use assert_matches:: assert_matches;
54use blockifier_test_utils:: cairo_versions:: { CairoVersion , RunnableCairo1 } ;
65use blockifier_test_utils:: contracts:: FeatureContract ;
76use rstest:: rstest;
8- #[ cfg( not( feature = "cairo_native" ) ) ]
97use starknet_api:: class_hash;
108use starknet_api:: contract_class:: compiled_class_hash:: HashVersion ;
11- #[ cfg( not( feature = "cairo_native" ) ) ]
129use starknet_api:: core:: ClassHash ;
1310
14- #[ cfg( not( feature = "cairo_native" ) ) ]
15- use crate :: blockifier:: config:: CairoNativeRunConfig ;
16- use crate :: blockifier:: config:: ContractClassManagerConfig ;
11+ use crate :: blockifier:: config:: { CairoNativeRunConfig , ContractClassManagerConfig } ;
1712use crate :: execution:: contract_class:: RunnableCompiledClass ;
1813use crate :: state:: contract_class_manager:: ContractClassManager ;
19- #[ cfg( not( feature = "cairo_native" ) ) ]
2014use crate :: state:: errors:: StateError ;
2115#[ cfg( feature = "cairo_native" ) ]
2216use crate :: state:: global_cache:: CachedCairoNative ;
2317use crate :: state:: global_cache:: CompiledClasses ;
24- use crate :: state:: state_api:: StateReader ;
25- #[ cfg( not( feature = "cairo_native" ) ) ]
26- use crate :: state:: state_api:: StateResult ;
27- #[ cfg( not( feature = "cairo_native" ) ) ]
18+ use crate :: state:: state_api:: { StateReader , StateResult } ;
2819use crate :: state:: state_api_test_utils:: assert_eq_state_result;
2920use crate :: state:: state_reader_and_contract_manager:: StateReaderAndContractManager ;
30- #[ cfg( not( feature = "cairo_native" ) ) ]
3121use crate :: state:: state_reader_and_contract_manager_test_utils:: MockFetchCompiledClasses ;
3222use crate :: test_utils:: contracts:: { FeatureContractData , FeatureContractTrait } ;
3323use crate :: test_utils:: dict_state_reader:: DictStateReader ;
3424use crate :: test_utils:: initial_test_state:: state_reader_and_contract_manager_for_testing;
3525
36- #[ cfg( not( feature = "cairo_native" ) ) ]
3726static DUMMY_CLASS_HASH : LazyLock < ClassHash > = LazyLock :: new ( || class_hash ! ( 2_u32 ) ) ;
3827
3928fn build_reader_and_declare_contract (
@@ -137,21 +126,18 @@ fn test_get_compiled_class_when_native_is_cached() {
137126 assert_matches ! ( compiled_class, RunnableCompiledClass :: V1Native ( _) ) ;
138127}
139128
140- #[ cfg( not( feature = "cairo_native" ) ) ]
141129struct GetCompiledClassTestScenario {
142130 expectations : GetCompiledClassTestExpectation ,
143131
144132 // Test result.
145133 expected_result : StateResult < RunnableCompiledClass > ,
146134}
147135
148- #[ cfg( not( feature = "cairo_native" ) ) ]
149136struct GetCompiledClassTestExpectation {
150137 get_compiled_classes_result : Option < StateResult < CompiledClasses > > ,
151138 is_declared_result : Option < StateResult < bool > > ,
152139}
153140
154- #[ cfg( not( feature = "cairo_native" ) ) ]
155141fn add_expectation_to_mock_fetch_compiled_classes (
156142 mock_fetch_compiled_classes : & mut MockFetchCompiledClasses ,
157143 expectations : GetCompiledClassTestExpectation ,
@@ -171,31 +157,33 @@ fn add_expectation_to_mock_fetch_compiled_classes(
171157 }
172158}
173159
174- #[ cfg( not( feature = "cairo_native" ) ) ]
175160fn cairo_1_declared_scenario ( ) -> GetCompiledClassTestScenario {
161+ let test_contract = FeatureContract :: TestContract ( CairoVersion :: Cairo1 ( RunnableCairo1 :: Casm ) ) ;
162+ let runnable_compiled_class = test_contract. get_runnable_class ( ) ;
163+ let compiled_class = assert_matches ! ( runnable_compiled_class. clone( ) , RunnableCompiledClass :: V1 ( compiled_class) => compiled_class) ;
164+ let compiled_classes =
165+ CompiledClasses :: V1 ( compiled_class, Arc :: new ( test_contract. get_sierra ( ) ) ) ;
176166 GetCompiledClassTestScenario {
177167 expectations : GetCompiledClassTestExpectation {
178- get_compiled_classes_result : Some ( Ok ( CompiledClasses :: from_runnable_for_testing (
179- RunnableCompiledClass :: test_casm_contract_class ( ) ,
180- ) ) ) ,
168+ get_compiled_classes_result : Some ( Ok ( compiled_classes) ) ,
181169 is_declared_result : None ,
182170 } ,
183- expected_result : Ok ( RunnableCompiledClass :: test_casm_contract_class ( ) ) ,
171+ expected_result : Ok ( runnable_compiled_class ) ,
184172 }
185173}
186174
187- #[ cfg( not( feature = "cairo_native" ) ) ]
188175fn cairo_1_cached_scenario ( ) -> GetCompiledClassTestScenario {
176+ let test_contract = FeatureContract :: TestContract ( CairoVersion :: Cairo1 ( RunnableCairo1 :: Casm ) ) ;
177+ let runnable_compiled_class = test_contract. get_runnable_class ( ) ;
189178 GetCompiledClassTestScenario {
190179 expectations : GetCompiledClassTestExpectation {
191180 get_compiled_classes_result : None ,
192181 is_declared_result : Some ( Ok ( true ) ) , // Verification call for cached Cairo1 class.
193182 } ,
194- expected_result : Ok ( RunnableCompiledClass :: test_casm_contract_class ( ) ) ,
183+ expected_result : Ok ( runnable_compiled_class ) ,
195184 }
196185}
197186
198- #[ cfg( not( feature = "cairo_native" ) ) ]
199187fn cached_but_verification_failed_after_reorg_scenario ( ) -> GetCompiledClassTestScenario {
200188 GetCompiledClassTestScenario {
201189 expectations : GetCompiledClassTestExpectation {
@@ -206,7 +194,6 @@ fn cached_but_verification_failed_after_reorg_scenario() -> GetCompiledClassTest
206194 }
207195}
208196
209- #[ cfg( not( feature = "cairo_native" ) ) ]
210197fn cairo_0_declared_scenario ( ) -> GetCompiledClassTestScenario {
211198 GetCompiledClassTestScenario {
212199 expectations : GetCompiledClassTestExpectation {
@@ -219,7 +206,6 @@ fn cairo_0_declared_scenario() -> GetCompiledClassTestScenario {
219206 }
220207}
221208
222- #[ cfg( not( feature = "cairo_native" ) ) ]
223209fn cairo_0_cached_scenario ( ) -> GetCompiledClassTestScenario {
224210 GetCompiledClassTestScenario {
225211 expectations : GetCompiledClassTestExpectation {
@@ -230,7 +216,6 @@ fn cairo_0_cached_scenario() -> GetCompiledClassTestScenario {
230216 }
231217}
232218
233- #[ cfg( not( feature = "cairo_native" ) ) ]
234219fn not_declared_scenario ( ) -> GetCompiledClassTestScenario {
235220 GetCompiledClassTestScenario {
236221 expectations : GetCompiledClassTestExpectation {
@@ -243,7 +228,6 @@ fn not_declared_scenario() -> GetCompiledClassTestScenario {
243228 }
244229}
245230
246- #[ cfg( not( feature = "cairo_native" ) ) ]
247231#[ rstest]
248232#[ case:: cairo_0_declared_and_cached( cairo_0_declared_scenario( ) , cairo_0_cached_scenario( ) ) ]
249233#[ case:: cairo_1_declared_and_cached( cairo_1_declared_scenario( ) , cairo_1_cached_scenario( ) ) ]
@@ -256,10 +240,11 @@ fn not_declared_scenario() -> GetCompiledClassTestScenario {
256240fn test_get_compiled_class_caching_scenarios (
257241 #[ case] first_scenario : GetCompiledClassTestScenario ,
258242 #[ case] second_scenario : GetCompiledClassTestScenario ,
243+ #[ values( true , false ) ] wait_on_native_compilation : bool ,
259244) {
260245 let contract_class_manager = ContractClassManager :: start ( ContractClassManagerConfig {
261246 cairo_native_run_config : CairoNativeRunConfig {
262- wait_on_native_compilation : false ,
247+ wait_on_native_compilation,
263248 ..Default :: default ( )
264249 } ,
265250 ..Default :: default ( )
0 commit comments