@@ -62,17 +62,6 @@ fn verify_cairo0_contract(contract: &FeatureContract, fix: bool) {
6262 assert_eq ! ( contract. get_compiled_class_hash( & HashVersion :: V2 ) , CompiledClassHash :: default ( ) ) ;
6363}
6464
65- // ======================== Cairo 1 compilation & hash verification ========================
66-
67- fn verify_contract_casm_hashes ( contract : & FeatureContract ) {
68- let casm_json = contract. get_raw_class ( ) ;
69- let casm: CasmContractClass =
70- serde_json:: from_str ( & casm_json) . expect ( "Failed to deserialize CASM contract class" ) ;
71- let ( casm_hash_v1, casm_hash_v2) = contract. get_compiled_class_hashes_constants ( ) ;
72- casm_hash_v1. assert_eq ( & format ! ( "0x{:x}" , casm. hash( & HashVersion :: V1 ) . 0 ) ) ;
73- casm_hash_v2. assert_eq ( & format ! ( "0x{:x}" , casm. hash( & HashVersion :: V2 ) . 0 ) ) ;
74- }
75-
7665// ======================== Enum <-> filesystem consistency ========================
7766
7867/// For Cairo 0: verifies that each .cairo file has a matching _compiled.json and a matching
@@ -138,15 +127,33 @@ fn verify_feature_contracts_match_enum(
138127 }
139128}
140129
130+ // Verified that the constant casm hashes V1 and V2 in the FeatureContract enum are correct.
131+ // In case of a mismatch, run: `env UPDATE_EXPECT=1 cargo test -p blockifier_test_utils --test
132+ // feature_contracts_compatibility_test -- verify_feature_contracts_cairo1`
133+ fn verify_contract_casm_hashes ( contract : & FeatureContract ) {
134+ let casm_json = contract. get_raw_class ( ) ;
135+ let casm: CasmContractClass =
136+ serde_json:: from_str ( & casm_json) . expect ( "Failed to deserialize CASM contract class" ) ;
137+ let ( casm_hash_v1, casm_hash_v2) = contract. get_compiled_class_hashes_constants ( ) ;
138+ casm_hash_v1. assert_eq ( & format ! ( "0x{:x}" , casm. hash( & HashVersion :: V1 ) . 0 ) ) ;
139+ casm_hash_v2. assert_eq ( & format ! ( "0x{:x}" , casm. hash( & HashVersion :: V2 ) . 0 ) ) ;
140+ }
141+
141142// ======================== Test entrypoints ========================
142143
143144#[ ignore]
144145#[ traced_test]
145146#[ tokio:: test( flavor = "multi_thread" ) ]
146147async fn verify_feature_contracts_cairo0 ( ) {
147148 let fix = std:: env:: var ( "FIX_FEATURE_TEST" ) . is_ok ( ) ;
149+ let contract_filter = std:: env:: var ( "CONTRACT_FILTER" ) . ok ( ) ;
150+ let matches_filter = |contract : & FeatureContract | -> bool {
151+ contract_filter. as_deref ( ) . is_none_or ( |filter| format ! ( "{contract:?}" ) . contains ( filter) )
152+ } ;
153+ // TODO(Dori, 1/10/2024): Parallelize Cairo0 recompilation.
148154 for contract in FeatureContract :: all_feature_contracts ( )
149155 . filter ( |c| c. cairo_version ( ) == CairoVersion :: Cairo0 )
156+ . filter ( |c| matches_filter ( c) )
150157 {
151158 verify_cairo0_contract ( & contract, fix) ;
152159 }
@@ -158,7 +165,13 @@ async fn verify_feature_contracts_cairo0() {
158165/// feature_contracts_compatibility_test -- verify_feature_contracts_cairo1`
159166#[ test]
160167fn verify_feature_contracts_cairo1 ( ) {
161- for contract in FeatureContract :: all_cairo1_casm_feature_contracts ( ) {
168+ let contract_filter = std:: env:: var ( "CONTRACT_FILTER" ) . ok ( ) ;
169+ let matches_filter = |contract : & FeatureContract | -> bool {
170+ contract_filter. as_deref ( ) . is_none_or ( |filter| format ! ( "{contract:?}" ) . contains ( filter) )
171+ } ;
172+ for contract in
173+ FeatureContract :: all_cairo1_casm_feature_contracts ( ) . filter ( |c| matches_filter ( c) )
174+ {
162175 verify_contract_casm_hashes ( & contract) ;
163176 }
164177 // ERC20 uses committed artifacts; just verify its hashes.
0 commit comments