@@ -2,6 +2,7 @@ use std::collections::HashMap;
22use std:: fs;
33use std:: path:: PathBuf ;
44
5+ use apollo_infra_utils:: cairo_compiler_version:: cairo1_compiler_version;
56use apollo_infra_utils:: compile_time_cargo_manifest_dir;
67use cairo_lang_starknet_classes:: contract_class:: ContractClass as CairoLangContractClass ;
78use itertools:: Itertools ;
@@ -77,16 +78,12 @@ const ERC20_CAIRO1_CONTRACT_SOURCE_PATH: &str = "./resources/ERC20/ERC20_Cairo1/
7778const ERC20_SIERRA_CONTRACT_PATH : & str = "./resources/ERC20/ERC20_Cairo1/erc20.sierra.json" ;
7879const ERC20_CAIRO1_CONTRACT_PATH : & str = "./resources/ERC20/ERC20_Cairo1/erc20.casm.json" ;
7980
80- // The following contracts are compiled with a fixed version of the compiler. This compiler version
81- // no longer compiles with stable rust, so the toolchain is also fixed.
82- const LEGACY_CONTRACT_COMPILER_TAG : & str = "v2.1.0" ;
83- const LEGACY_CONTRACT_RUST_TOOLCHAIN : & str = "2023-07-05" ;
81+ // The following contracts are compiled with a fixed version of the compiler.
82+ const LEGACY_CONTRACT_COMPILER_VERSION : & str = "2.1.0" ;
83+ const CAIRO_STEPS_TEST_CONTRACT_COMPILER_VERSION : & str = "2.7.0" ;
8484
85- const CAIRO_STEPS_TEST_CONTRACT_COMPILER_TAG : & str = "v2.7.0" ;
86- const CAIRO_STEPS_TEST_CONTRACT_RUST_TOOLCHAIN : & str = "2024-04-29" ;
87-
88- pub type TagAndToolchain = ( Option < String > , Option < String > ) ;
89- pub type TagToContractsMapping = HashMap < TagAndToolchain , Vec < FeatureContract > > ;
85+ pub type CairoVersionString = String ;
86+ pub type VersionToContractsMapping = HashMap < CairoVersionString , Vec < FeatureContract > > ;
9087
9188/// Enum representing all feature contracts.
9289/// The contracts that are implemented in both Cairo versions include a version field.
@@ -197,20 +194,20 @@ impl FeatureContract {
197194 }
198195 }
199196
200- /// Some contracts are designed to test behavior of code compiled with a
201- /// specific (old) compiler tag. To run the (old) compiler, older rust
202- /// version is required .
203- pub fn fixed_tag_and_rust_toolchain ( & self ) -> TagAndToolchain {
197+ /// Some Cairo1 contracts are designed to test behavior of code compiled with a specific (old)
198+ /// compiler version. Returns the compiler version used to compile the contract.
199+ /// Panics if called on a Cairo0 contract .
200+ pub fn fixed_version ( & self ) -> CairoVersionString {
204201 match self {
205- Self :: LegacyTestContract => (
206- Some ( LEGACY_CONTRACT_COMPILER_TAG . into ( ) ) ,
207- Some ( LEGACY_CONTRACT_RUST_TOOLCHAIN . into ( ) ) ,
208- ) ,
209- Self :: CairoStepsTestContract => (
210- Some ( CAIRO_STEPS_TEST_CONTRACT_COMPILER_TAG . into ( ) ) ,
211- Some ( CAIRO_STEPS_TEST_CONTRACT_RUST_TOOLCHAIN . into ( ) ) ,
212- ) ,
213- _ => ( None , None ) ,
202+ Self :: LegacyTestContract => LEGACY_CONTRACT_COMPILER_VERSION . into ( ) ,
203+ Self :: CairoStepsTestContract => CAIRO_STEPS_TEST_CONTRACT_COMPILER_VERSION . into ( ) ,
204+ contract => {
205+ assert ! (
206+ !contract . cairo_version ( ) . is_cairo0 ( ) ,
207+ "fixed_version() should only be called for Cairo1 contracts."
208+ ) ;
209+ cairo1_compiler_version ( )
210+ }
214211 }
215212 }
216213
@@ -343,10 +340,7 @@ impl FeatureContract {
343340 } ;
344341 cairo0_compile ( self . get_source_path ( ) , extra_arg, false )
345342 }
346- CairoVersion :: Cairo1 ( _) => {
347- let ( tag_override, cargo_nightly_arg) = self . fixed_tag_and_rust_toolchain ( ) ;
348- cairo1_compile ( self . get_source_path ( ) , tag_override, cargo_nightly_arg)
349- }
343+ CairoVersion :: Cairo1 ( _) => cairo1_compile ( self . get_source_path ( ) , self . fixed_version ( ) ) ,
350344 }
351345 }
352346
@@ -410,10 +404,10 @@ impl FeatureContract {
410404 Self :: all_contracts ( ) . filter ( |contract| !matches ! ( contract, Self :: ERC20 ( _) ) )
411405 }
412406
413- pub fn cairo1_feature_contracts_by_tag ( ) -> TagToContractsMapping {
407+ pub fn cairo1_feature_contracts_by_version ( ) -> VersionToContractsMapping {
414408 Self :: all_feature_contracts ( )
415409 . filter ( |contract| contract. cairo_version ( ) != CairoVersion :: Cairo0 )
416- . map ( |contract| ( contract. fixed_tag_and_rust_toolchain ( ) , contract) )
410+ . map ( |contract| ( contract. fixed_version ( ) , contract) )
417411 . into_group_map ( )
418412 }
419413}
0 commit comments