@@ -19,33 +19,24 @@ const FIX_COMMAND: &str = "FIX_FEATURE_TEST=1 cargo test -- --ignored";
19
19
// ```
20
20
// Then, run the FIX_COMMAND above.
21
21
22
- // This test currently doesn't support Cairo1 contracts. To fix them you'll need to compile them one
23
- // by one:
24
- // 1. Clone the [cairo repo](https://github.com/starkware-libs/cairo).
25
- // 2. Checkout the commit defined in [the root Cargo.toml](../../../../Cargo.toml).
26
- // 3. From within the compiler repo root directory, run:
27
- // ```
28
- // PREFIX=~/workspace/blockifier/crates/blockifier/feature_contracts/cairo1
29
- // CONTRACT_NAME=<contract_base_filename>
30
- // cargo run --release --bin starknet-compile -- --single-file \
31
- // $PREFIX/$CONTRACT_NAME.cairo \
32
- // $PREFIX/compiled/$CONTRACT_NAME.sierra.json
33
- // cargo run --release --bin starknet-sierra-compile \
34
- // $PREFIX/compiled/$CONTRACT_NAME.sierra.json \
35
- // $PREFIX/compiled/$CONTRACT_NAME.casm.json
36
- // ```
37
- // TODO(Gilad, 1/1/2024): New year's resolution: support Cairo1 in the test.
22
+ // To test Cairo1 feature contracts, first clone the Cairo repo and checkout the required tag.
23
+ // The repo should be located next to the sequencer repo:
24
+ // <WORKSPACE_DIR>/
25
+ // - sequencer/
26
+ // - cairo/
27
+ // Then, run the FIX_COMMAND above.
38
28
39
29
// Checks that:
40
30
// 1. `TEST_CONTRACTS` dir exists and contains only `.cairo` files and the subdirectory
41
31
// `COMPILED_CONTRACTS_SUBDIR`.
42
32
// 2. for each `X.cairo` file in `TEST_CONTRACTS` there exists an `X_compiled.json` file in
43
33
// `COMPILED_CONTRACTS_SUBDIR` which equals `starknet-compile-deprecated X.cairo --no_debug_info`.
44
- fn verify_feature_contracts_compatibility ( fix : bool , cairo_version : CairoVersion ) {
34
+ fn verify_feature_contracts_compatibility (
35
+ fix : bool ,
36
+ contracts_to_test : impl Iterator < Item = FeatureContract > ,
37
+ ) {
45
38
// TODO(Dori, 1/10/2024): Parallelize this test.
46
- for contract in FeatureContract :: all_feature_contracts ( )
47
- . filter ( |contract| contract. cairo_version ( ) == cairo_version)
48
- {
39
+ for contract in contracts_to_test {
49
40
// Compare output of cairo-file on file with existing compiled file.
50
41
let expected_compiled_output = contract. compile ( ) ;
51
42
let existing_compiled_path = contract. get_compiled_path ( ) ;
@@ -136,15 +127,28 @@ fn verify_feature_contracts_match_enum() {
136
127
assert_eq ! ( compiled_paths_from_enum, compiled_paths_on_filesystem) ;
137
128
}
138
129
130
+ fn is_env_var_set ( env_var : & str ) -> bool {
131
+ std:: env:: var ( env_var) . is_ok ( )
132
+ }
133
+
139
134
#[ rstest]
140
135
#[ ignore]
141
136
fn verify_feature_contracts (
142
137
#[ values( CairoVersion :: Cairo0 , CairoVersion :: Cairo1 ) ] cairo_version : CairoVersion ,
143
138
) {
144
- // TODO(Dori, 1/9/2024): Support Cairo1 contracts in the CI and remove this `if` statement.
145
- if std:: env:: var ( "CI" ) . is_ok ( ) && matches ! ( cairo_version, CairoVersion :: Cairo1 ) {
146
- return ;
147
- }
148
- let fix_features = std:: env:: var ( "FIX_FEATURE_TEST" ) . is_ok ( ) ;
149
- verify_feature_contracts_compatibility ( fix_features, cairo_version)
139
+ let fix_features = is_env_var_set ( "FIX_FEATURE_TEST" ) ;
140
+ let legacy_mode = is_env_var_set ( "LEGACY" ) ;
141
+ let ci_mode = is_env_var_set ( "CI" ) ;
142
+
143
+ let contracts_to_test = FeatureContract :: all_feature_contracts ( ) . filter ( |contract| {
144
+ // If called with LEGACY environment variable set, only test legacy contracts (from CI
145
+ // or not).
146
+ // If tested from the CI *without* the LEGACY environment variable set, test only
147
+ // non-legacy contracts of the respective cairo version.
148
+ // If not tested from CI, test all contracts of the requested cairo version.
149
+ contract. cairo_version ( ) == cairo_version
150
+ && ( if legacy_mode { contract. is_legacy ( ) } else { !ci_mode || !contract. is_legacy ( ) } )
151
+ } ) ;
152
+
153
+ verify_feature_contracts_compatibility ( fix_features, contracts_to_test)
150
154
}
0 commit comments