@@ -24,10 +24,14 @@ fn get_contract_entry_points_hashed(
24
24
} ) ?,
25
25
) ;
26
26
entry_points_flatted. push ( FieldElement :: from ( entry_point. offset ) ) ;
27
- let mut builtins_flatted = Vec :: new ( ) ;
28
- entry_point. builtins . iter ( ) . for_each ( |builtin| {
29
- builtins_flatted. push ( FieldElement :: from_byte_slice_be ( builtin. as_bytes ( ) ) . unwrap ( ) ) ;
30
- } ) ;
27
+ let builtins_flatted = entry_point
28
+ . builtins
29
+ . iter ( )
30
+ . map ( |builtin| FieldElement :: from_byte_slice_be ( builtin. as_bytes ( ) ) )
31
+ . collect :: < Result < Vec < FieldElement > , _ > > ( )
32
+ . map_err ( |_err| {
33
+ ContractAddressError :: Cast ( "Felt252" . to_string ( ) , "FieldElement" . to_string ( ) )
34
+ } ) ?;
31
35
entry_points_flatted. push ( poseidon_hash_many ( & builtins_flatted) ) ;
32
36
}
33
37
@@ -101,90 +105,164 @@ mod tests {
101
105
#[ test]
102
106
fn test_compute_casm_class_hash_contract_a ( ) {
103
107
// Open the file in read-only mode with buffer.
104
- let file = File :: open ( "starknet_programs/cairo1/contract_a.casm" ) . unwrap ( ) ;
108
+ let file;
109
+ let expected_result;
110
+ #[ cfg( not( feature = "cairo_1_tests" ) ) ]
111
+ {
112
+ file = File :: open ( "starknet_programs/cairo2/contract_a.casm" ) . unwrap ( ) ;
113
+ expected_result = felt_str ! (
114
+ "321aadcf42b0a4ad905616598d16c42fa9b87c812dc398e49b57bf77930629f" ,
115
+ 16
116
+ ) ;
117
+ }
118
+ #[ cfg( feature = "cairo_1_tests" ) ]
119
+ {
120
+ file = File :: open ( "starknet_programs/cairo1/contract_a.casm" ) . unwrap ( ) ;
121
+ expected_result = felt_str ! (
122
+ "3a4f00bf75ba3b9230a94f104c7a4605a1901c4bd475beb59eeeeb7aceb9795" ,
123
+ 16
124
+ ) ;
125
+ }
105
126
let reader = BufReader :: new ( file) ;
106
127
107
- // Read the JSON contents of the file as an instance of `User `.
128
+ // Read the JSON contents of the file as an instance of `CasmContractClass `.
108
129
let contract_class: CasmContractClass = serde_json:: from_reader ( reader) . unwrap ( ) ;
109
130
110
131
assert_eq ! (
111
132
compute_casm_class_hash( & contract_class) . unwrap( ) ,
112
- felt_str!(
113
- "3a4f00bf75ba3b9230a94f104c7a4605a1901c4bd475beb59eeeeb7aceb9795" ,
114
- 16
115
- )
133
+ expected_result
116
134
) ;
117
135
}
118
136
119
137
#[ test]
120
138
fn test_compute_casm_class_hash_deploy ( ) {
121
139
// Open the file in read-only mode with buffer.
122
- let file = File :: open ( "starknet_programs/cairo1/deploy.casm" ) . unwrap ( ) ;
140
+ let file;
141
+ let expected_result;
142
+ #[ cfg( not( feature = "cairo_1_tests" ) ) ]
143
+ {
144
+ file = File :: open ( "starknet_programs/cairo2/deploy.casm" ) . unwrap ( ) ;
145
+ expected_result = felt_str ! (
146
+ "53ad3bfb13f39cf1a9940108be4f9c6a8d9cc48a59d5f9b3c73432f877f8cf0" ,
147
+ 16
148
+ ) ;
149
+ }
150
+
151
+ #[ cfg( feature = "cairo_1_tests" ) ]
152
+ {
153
+ file = File :: open ( "starknet_programs/cairo1/deploy.casm" ) . unwrap ( ) ;
154
+ expected_result = felt_str ! (
155
+ "3bd56f1c3c1c595ac2ee6d07bdedc027d09df56235e20374649f0b3535c1f15" ,
156
+ 16
157
+ ) ;
158
+ }
123
159
let reader = BufReader :: new ( file) ;
124
160
125
- // Read the JSON contents of the file as an instance of `User `.
161
+ // Read the JSON contents of the file as an instance of `CasmContractClass `.
126
162
let contract_class: CasmContractClass = serde_json:: from_reader ( reader) . unwrap ( ) ;
127
163
128
164
assert_eq ! (
129
165
compute_casm_class_hash( & contract_class) . unwrap( ) ,
130
- felt_str!(
131
- "3bd56f1c3c1c595ac2ee6d07bdedc027d09df56235e20374649f0b3535c1f15" ,
132
- 16
133
- )
166
+ expected_result
134
167
) ;
135
168
}
136
169
137
170
#[ test]
138
171
fn test_compute_casm_class_hash_fibonacci ( ) {
139
172
// Open the file in read-only mode with buffer.
140
- let file = File :: open ( "starknet_programs/cairo1/fibonacci.casm" ) . unwrap ( ) ;
173
+ let file;
174
+ let expected_result;
175
+ #[ cfg( not( feature = "cairo_1_tests" ) ) ]
176
+ {
177
+ file = File :: open ( "starknet_programs/cairo2/fibonacci.casm" ) . unwrap ( ) ;
178
+ expected_result = felt_str ! (
179
+ "6638ce6c9bf336d1781a388668fa2206d928df5d1fa6b92e4cb41004c7e3f89" ,
180
+ 16
181
+ ) ;
182
+ }
183
+
184
+ #[ cfg( feature = "cairo_1_tests" ) ]
185
+ {
186
+ file = File :: open ( "starknet_programs/cairo1/fibonacci.casm" ) . unwrap ( ) ;
187
+ expected_result = felt_str ! (
188
+ "44f12e6e59232e9909d7428b913b3cc8d9059458e5027740a3ccdbdc4b1ffd2" ,
189
+ 16
190
+ ) ;
191
+ }
141
192
let reader = BufReader :: new ( file) ;
142
193
143
- // Read the JSON contents of the file as an instance of `User `.
194
+ // Read the JSON contents of the file as an instance of `CasmContractClass `.
144
195
let contract_class: CasmContractClass = serde_json:: from_reader ( reader) . unwrap ( ) ;
145
196
146
197
assert_eq ! (
147
198
compute_casm_class_hash( & contract_class) . unwrap( ) ,
148
- felt_str!(
149
- "44f12e6e59232e9909d7428b913b3cc8d9059458e5027740a3ccdbdc4b1ffd2" ,
150
- 16
151
- )
199
+ expected_result
152
200
) ;
153
201
}
154
202
155
203
#[ test]
156
204
fn test_compute_casm_class_hash_factorial ( ) {
157
205
// Open the file in read-only mode with buffer.
158
- let file = File :: open ( "starknet_programs/cairo1/factorial.casm" ) . unwrap ( ) ;
206
+ let file;
207
+ let expected_result;
208
+ #[ cfg( not( feature = "cairo_1_tests" ) ) ]
209
+ {
210
+ file = File :: open ( "starknet_programs/cairo2/factorial.casm" ) . unwrap ( ) ;
211
+ expected_result = felt_str ! (
212
+ "7c48d040ceb3183837a0aff2adf33d879f790e202eb2c4b8622005c12252641" ,
213
+ 16
214
+ ) ;
215
+ }
216
+
217
+ #[ cfg( feature = "cairo_1_tests" ) ]
218
+ {
219
+ file = File :: open ( "starknet_programs/cairo1/factorial.casm" ) . unwrap ( ) ;
220
+ expected_result = felt_str ! (
221
+ "189a9b8b852aedbb225aa28dce9cfc3133145dd623e2d2ca5e962b7d4e61e15" ,
222
+ 16
223
+ ) ;
224
+ }
159
225
let reader = BufReader :: new ( file) ;
160
226
161
- // Read the JSON contents of the file as an instance of `User `.
227
+ // Read the JSON contents of the file as an instance of `CasmContractClass `.
162
228
let contract_class: CasmContractClass = serde_json:: from_reader ( reader) . unwrap ( ) ;
163
229
164
230
assert_eq ! (
165
231
compute_casm_class_hash( & contract_class) . unwrap( ) ,
166
- felt_str!(
167
- "189a9b8b852aedbb225aa28dce9cfc3133145dd623e2d2ca5e962b7d4e61e15" ,
168
- 16
169
- )
232
+ expected_result
170
233
) ;
171
234
}
172
235
173
236
#[ test]
174
237
fn test_compute_casm_class_hash_emit_event ( ) {
175
238
// Open the file in read-only mode with buffer.
176
- let file = File :: open ( "starknet_programs/cairo1/emit_event.casm" ) . unwrap ( ) ;
239
+ let file;
240
+ let expected_result;
241
+ #[ cfg( not( feature = "cairo_1_tests" ) ) ]
242
+ {
243
+ file = File :: open ( "starknet_programs/cairo2/emit_event.casm" ) . unwrap ( ) ;
244
+ expected_result = felt_str ! (
245
+ "3010533bd60cb0e70ac1bf776e171713f0e5229a084989d3894c171c160ace2" ,
246
+ 16
247
+ ) ;
248
+ }
249
+
250
+ #[ cfg( feature = "cairo_1_tests" ) ]
251
+ {
252
+ file = File :: open ( "starknet_programs/cairo1/emit_event.casm" ) . unwrap ( ) ;
253
+ expected_result = felt_str ! (
254
+ "3335fe731ceda1116eda8bbc2e282953ce54618309ad474189e627c59328fff" ,
255
+ 16
256
+ ) ;
257
+ }
177
258
let reader = BufReader :: new ( file) ;
178
259
179
- // Read the JSON contents of the file as an instance of `User `.
260
+ // Read the JSON contents of the file as an instance of `CasmContractClass `.
180
261
let contract_class: CasmContractClass = serde_json:: from_reader ( reader) . unwrap ( ) ;
181
262
182
263
assert_eq ! (
183
264
compute_casm_class_hash( & contract_class) . unwrap( ) ,
184
- felt_str!(
185
- "3335fe731ceda1116eda8bbc2e282953ce54618309ad474189e627c59328fff" ,
186
- 16
187
- )
265
+ expected_result
188
266
) ;
189
267
}
190
268
}
0 commit comments