@@ -267,8 +267,17 @@ fn convert_to_acir_field(f: Scalar) -> GenericFieldElement<Fr> {
267267
268268#[ cfg( test) ]
269269mod tests {
270+ use client_side_prover:: bellpepper:: shape_cs:: ShapeCS ;
271+
270272 use super :: * ;
271273
274+ fn add_external ( ) -> NoirProgram {
275+ let json_path = "../target/add_external.json" ;
276+ let json_data = std:: fs:: read ( json_path) . expect ( "Failed to read add_external.json" ) ;
277+
278+ serde_json:: from_slice ( & json_data) . expect ( "Failed to deserialize add_external.json" )
279+ }
280+
272281 #[ test]
273282 fn test_conversions ( ) {
274283 let f = Scalar :: from ( 5 ) ;
@@ -282,30 +291,38 @@ mod tests {
282291
283292 #[ test]
284293 fn test_deserialize_abi ( ) {
285- let json_path = "../examples/add_external/target/add_external.json" ;
286- let json_data = std:: fs:: read ( json_path) . expect ( "Failed to read add_external.json" ) ;
287-
288- let program: NoirProgram =
289- serde_json:: from_slice ( & json_data) . expect ( "Failed to deserialize add_external.json" ) ;
294+ let program = add_external ( ) ;
290295
291296 // Verify basic structure
292297 assert_eq ! ( program. version, "1.0.0-beta.2+1a2a08cbcb68646ff1aaef383cfc1798933c1355" ) ;
293- assert_eq ! ( program. hash, 2789485860577127199 ) ;
298+ assert_eq ! ( program. hash, 4842196402509912449 ) ;
294299
295300 // Verify parameters
296301 assert_eq ! ( program. abi. parameters. len( ) , 3 ) ;
297- assert_eq ! ( program. abi. parameters[ 0 ] . name, "external " ) ;
298- assert_eq ! ( program. abi. parameters[ 1 ] . name, "registers " ) ;
302+ assert_eq ! ( program. abi. parameters[ 0 ] . name, "registers " ) ;
303+ assert_eq ! ( program. abi. parameters[ 1 ] . name, "external " ) ;
299304 assert_eq ! ( program. abi. parameters[ 2 ] . name, "next_pc" ) ;
300305
301306 // Verify return type
302307 if let AbiType :: Struct { fields, path } = & program. abi . return_type . as_ref ( ) . unwrap ( ) . abi_type {
303308 assert_eq ! ( fields. len( ) , 2 ) ;
304- assert_eq ! ( path, "FoldingIO " ) ;
309+ assert_eq ! ( path, "nivc::FoldingOutput " ) ;
305310 assert_eq ! ( fields[ 0 ] . 0 , "registers" ) ;
306311 assert_eq ! ( fields[ 1 ] . 0 , "next_pc" ) ;
307312 } else {
308313 panic ! ( "Expected tuple return type, got {:?}" , program. abi. return_type) ;
309314 }
310315 }
316+
317+ #[ test]
318+ fn test_constraint_system ( ) {
319+ let program = add_external ( ) ;
320+
321+ let mut cs = ShapeCS :: < E1 > :: new ( ) ;
322+ let pc = Some ( AllocatedNum :: alloc ( & mut cs, || Ok ( Scalar :: from ( 0 ) ) ) . unwrap ( ) ) ;
323+ let z = vec ! [ AllocatedNum :: alloc( & mut cs, || Ok ( Scalar :: from( 1 ) ) ) . unwrap( ) ] ;
324+
325+ let _ = program. synthesize ( & mut cs, pc. as_ref ( ) , z. as_ref ( ) ) . unwrap ( ) ;
326+ assert_eq ! ( cs. num_constraints( ) , 3 ) ;
327+ }
311328}
0 commit comments