diff --git a/compiler/tests/field/mod.rs b/compiler/tests/field/mod.rs index e1294f3c01..1c2c9f889b 100644 --- a/compiler/tests/field/mod.rs +++ b/compiler/tests/field/mod.rs @@ -1,8 +1,8 @@ use crate::{ boolean::{output_expected_boolean, output_false, output_true}, - compile_program, get_error, get_output, + parse_program, EdwardsConstrainedValue, EdwardsTestCompiler, }; @@ -24,8 +24,6 @@ use snarkos_models::{ }; use snarkos_utilities::biginteger::BigInteger256; -const DIRECTORY_NAME: &str = "tests/field/"; - fn output_expected_constant(program: EdwardsTestCompiler, expected: Fq) { let output = get_output(program); assert_eq!( @@ -70,19 +68,25 @@ fn fail_synthesis(program: EdwardsTestCompiler) { #[test] fn test_zero() { - let program = compile_program(DIRECTORY_NAME, "zero.leo").unwrap(); + let bytes = include_bytes!("zero.leo"); + let program = parse_program(bytes).unwrap(); + output_zero(program); } #[test] fn test_one() { - let program = compile_program(DIRECTORY_NAME, "one.leo").unwrap(); + let bytes = include_bytes!("one.leo"); + let program = parse_program(bytes).unwrap(); + output_one(program); } #[test] fn test_input_pass() { - let mut program = compile_program(DIRECTORY_NAME, "input.leo").unwrap(); + let bytes = include_bytes!("input.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![Some(InputValue::Field("1".into()))]); let cs = TestConstraintSystem::::new(); @@ -93,14 +97,18 @@ fn test_input_pass() { #[test] fn test_input_fail_bool() { - let mut program = compile_program(DIRECTORY_NAME, "input.leo").unwrap(); + let bytes = include_bytes!("input.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![Some(InputValue::Boolean(true))]); fail_field(program); } #[test] fn test_input_fail_none() { - let mut program = compile_program(DIRECTORY_NAME, "input.leo").unwrap(); + let bytes = include_bytes!("input.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![None]); fail_synthesis(program); } @@ -124,7 +132,9 @@ fn test_add() { let cs = TestConstraintSystem::::new(); let sum_allocated = FqGadget::from(cs, &sum); - let mut program = compile_program(DIRECTORY_NAME, "add.leo").unwrap(); + let bytes = include_bytes!("add.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -153,7 +163,9 @@ fn test_sub() { let cs = TestConstraintSystem::::new(); let difference_allocated = FqGadget::from(cs, &difference); - let mut program = compile_program(DIRECTORY_NAME, "sub.leo").unwrap(); + let bytes = include_bytes!("sub.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -182,7 +194,9 @@ fn test_mul() { let cs = TestConstraintSystem::::new(); let product_allocated = FqGadget::from(cs, &product); - let mut program = compile_program(DIRECTORY_NAME, "mul.leo").unwrap(); + let bytes = include_bytes!("mul.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -211,7 +225,9 @@ fn test_div() { let cs = TestConstraintSystem::::new(); let quotient_allocated = FqGadget::from(cs, "ient); - let mut program = compile_program(DIRECTORY_NAME, "div.leo").unwrap(); + let bytes = include_bytes!("div.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -227,7 +243,9 @@ fn test_eq() { let r1: u64 = rand::random(); // test equal - let mut program = compile_program(DIRECTORY_NAME, "eq.leo").unwrap(); + let bytes = include_bytes!("eq.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r1.to_string())), @@ -240,7 +258,8 @@ fn test_eq() { let result = r1.eq(&r2); - let mut program = compile_program(DIRECTORY_NAME, "eq.leo").unwrap(); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -256,7 +275,9 @@ fn test_ge() { let r1: u64 = rand::random(); // test equal - let mut program = compile_program(DIRECTORY_NAME, "ge.leo").unwrap(); + let bytes = include_bytes!("ge.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r1.to_string())), @@ -269,7 +290,8 @@ fn test_ge() { let result = r1.ge(&r2); - let mut program = compile_program(DIRECTORY_NAME, "ge.leo").unwrap(); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -285,7 +307,9 @@ fn test_gt() { let r1: u64 = rand::random(); // test equal - let mut program = compile_program(DIRECTORY_NAME, "gt.leo").unwrap(); + let bytes = include_bytes!("gt.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r1.to_string())), @@ -298,7 +322,8 @@ fn test_gt() { let result = r1.gt(&r2); - let mut program = compile_program(DIRECTORY_NAME, "gt.leo").unwrap(); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -314,7 +339,9 @@ fn test_le() { let r1: u64 = rand::random(); // test equal - let mut program = compile_program(DIRECTORY_NAME, "le.leo").unwrap(); + let bytes = include_bytes!("le.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r1.to_string())), @@ -327,7 +354,8 @@ fn test_le() { let result = r1.le(&r2); - let mut program = compile_program(DIRECTORY_NAME, "le.leo").unwrap(); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -343,7 +371,9 @@ fn test_lt() { let r1: u64 = rand::random(); // test equal - let mut program = compile_program(DIRECTORY_NAME, "lt.leo").unwrap(); + let bytes = include_bytes!("lt.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r1.to_string())), @@ -356,7 +386,8 @@ fn test_lt() { let result = r1.lt(&r2); - let mut program = compile_program(DIRECTORY_NAME, "lt.leo").unwrap(); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -371,7 +402,9 @@ fn test_assert_eq_pass() { for _ in 0..10 { let r1: u64 = rand::random(); - let mut program = compile_program(DIRECTORY_NAME, "assert_eq.leo").unwrap(); + let bytes = include_bytes!("assert_eq.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r1.to_string())), @@ -391,7 +424,9 @@ fn test_assert_eq_fail() { continue; } - let mut program = compile_program(DIRECTORY_NAME, "assert_eq.leo").unwrap(); + let bytes = include_bytes!("assert_eq.leo"); + let mut program = parse_program(bytes).unwrap(); + program.set_inputs(vec![ Some(InputValue::Field(r1.to_string())), Some(InputValue::Field(r2.to_string())), @@ -418,7 +453,8 @@ fn test_ternary() { let g1 = FqGadget::from(cs.ns(|| "g1"), &f1); let g2 = FqGadget::from(cs.ns(|| "g2"), &f2); - let mut program_1 = compile_program(DIRECTORY_NAME, "ternary.leo").unwrap(); + let bytes = include_bytes!("ternary.leo"); + let mut program_1 = parse_program(bytes).unwrap(); let mut program_2 = program_1.clone(); // true -> field 1 diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index a203a51bf0..a435fbd7d0 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -1,7 +1,7 @@ pub mod array; pub mod boolean; pub mod circuits; -// pub mod field; +pub mod field; // pub mod function; // pub mod group; // pub mod import;