From 63342e7b1022742e210a86fb927040798db35e20 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 30 Jul 2020 16:20:31 -0700 Subject: [PATCH] fix int tests --- compiler/tests/integers/i128/add.leo | 4 +- compiler/tests/integers/i128/div.leo | 4 +- compiler/tests/integers/i128/eq.leo | 4 +- compiler/tests/integers/i128/ge.leo | 4 +- compiler/tests/integers/i128/gt.leo | 4 +- compiler/tests/integers/i128/input.leo | 4 +- compiler/tests/integers/i128/le.leo | 4 +- compiler/tests/integers/i128/lt.leo | 4 +- compiler/tests/integers/i128/max.leo | 4 +- compiler/tests/integers/i128/max_fail.leo | 3 + compiler/tests/integers/i128/min.leo | 4 +- compiler/tests/integers/i128/min_fail.leo | 3 + compiler/tests/integers/i128/mod.rs | 67 ++-- compiler/tests/integers/i128/mul.leo | 4 +- compiler/tests/integers/i128/one.leo | 3 - compiler/tests/integers/i128/pow.leo | 4 +- compiler/tests/integers/i128/sub.leo | 4 +- compiler/tests/integers/i128/ternary.leo | 6 +- compiler/tests/integers/i128/zero.leo | 3 - compiler/tests/integers/i16/add.leo | 4 +- compiler/tests/integers/i16/div.leo | 4 +- compiler/tests/integers/i16/eq.leo | 4 +- compiler/tests/integers/i16/ge.leo | 4 +- compiler/tests/integers/i16/gt.leo | 4 +- compiler/tests/integers/i16/input.leo | 4 +- compiler/tests/integers/i16/le.leo | 4 +- compiler/tests/integers/i16/lt.leo | 4 +- compiler/tests/integers/i16/max.leo | 4 +- compiler/tests/integers/i16/max_fail.leo | 3 + compiler/tests/integers/i16/min.leo | 4 +- compiler/tests/integers/i16/min_fail.leo | 3 + compiler/tests/integers/i16/mod.rs | 66 ++-- compiler/tests/integers/i16/mul.leo | 4 +- compiler/tests/integers/i16/one.leo | 3 - compiler/tests/integers/i16/pow.leo | 4 +- compiler/tests/integers/i16/sub.leo | 4 +- compiler/tests/integers/i16/ternary.leo | 6 +- compiler/tests/integers/i16/zero.leo | 3 - compiler/tests/integers/i32/add.leo | 4 +- compiler/tests/integers/i32/div.leo | 4 +- compiler/tests/integers/i32/eq.leo | 4 +- compiler/tests/integers/i32/ge.leo | 4 +- compiler/tests/integers/i32/gt.leo | 4 +- compiler/tests/integers/i32/input.leo | 4 +- compiler/tests/integers/i32/le.leo | 4 +- compiler/tests/integers/i32/lt.leo | 4 +- compiler/tests/integers/i32/max.leo | 4 +- compiler/tests/integers/i32/max_fail.leo | 3 + compiler/tests/integers/i32/min.leo | 4 +- compiler/tests/integers/i32/min_fail.leo | 3 + compiler/tests/integers/i32/mod.rs | 66 ++-- compiler/tests/integers/i32/mul.leo | 4 +- compiler/tests/integers/i32/one.leo | 3 - compiler/tests/integers/i32/pow.leo | 4 +- compiler/tests/integers/i32/sub.leo | 4 +- compiler/tests/integers/i32/ternary.leo | 6 +- compiler/tests/integers/i32/zero.leo | 3 - compiler/tests/integers/i64/add.leo | 4 +- compiler/tests/integers/i64/div.leo | 4 +- compiler/tests/integers/i64/eq.leo | 4 +- compiler/tests/integers/i64/ge.leo | 4 +- compiler/tests/integers/i64/gt.leo | 4 +- compiler/tests/integers/i64/input.leo | 4 +- compiler/tests/integers/i64/le.leo | 4 +- compiler/tests/integers/i64/lt.leo | 4 +- compiler/tests/integers/i64/max.leo | 4 +- compiler/tests/integers/i64/max_fail.leo | 3 + compiler/tests/integers/i64/min.leo | 4 +- compiler/tests/integers/i64/min_fail.leo | 3 + compiler/tests/integers/i64/mod.rs | 68 ++-- compiler/tests/integers/i64/mul.leo | 4 +- compiler/tests/integers/i64/one.leo | 3 - compiler/tests/integers/i64/pow.leo | 4 +- compiler/tests/integers/i64/sub.leo | 4 +- compiler/tests/integers/i64/ternary.leo | 6 +- compiler/tests/integers/i64/zero.leo | 3 - compiler/tests/integers/i8/add.leo | 4 +- compiler/tests/integers/i8/div.leo | 4 +- compiler/tests/integers/i8/eq.leo | 4 +- compiler/tests/integers/i8/ge.leo | 4 +- compiler/tests/integers/i8/gt.leo | 4 +- compiler/tests/integers/i8/input.leo | 4 +- compiler/tests/integers/i8/le.leo | 4 +- compiler/tests/integers/i8/lt.leo | 4 +- compiler/tests/integers/i8/max.leo | 4 +- compiler/tests/integers/i8/max_fail.leo | 3 + compiler/tests/integers/i8/min.leo | 4 +- compiler/tests/integers/i8/min_fail.leo | 3 + compiler/tests/integers/i8/mod.rs | 66 ++-- compiler/tests/integers/i8/mul.leo | 4 +- compiler/tests/integers/i8/one.leo | 3 - compiler/tests/integers/i8/pow.leo | 4 +- compiler/tests/integers/i8/sub.leo | 4 +- compiler/tests/integers/i8/ternary.leo | 6 +- compiler/tests/integers/i8/zero.leo | 3 - compiler/tests/integers/int_macro.rs | 414 ++++++++++++---------- compiler/tests/integers/integer_tester.rs | 2 +- compiler/tests/integers/mod.rs | 10 +- compiler/tests/integers/u128/min.leo | 2 +- compiler/tests/integers/u128/min_fail.leo | 2 +- compiler/tests/integers/u16/min.leo | 2 +- compiler/tests/integers/u16/min_fail.leo | 2 +- compiler/tests/integers/u64/min.leo | 2 +- compiler/tests/integers/u64/min_fail.leo | 2 +- compiler/tests/integers/u8/min.leo | 2 +- compiler/tests/integers/u8/min_fail.leo | 2 +- 106 files changed, 549 insertions(+), 576 deletions(-) create mode 100644 compiler/tests/integers/i128/max_fail.leo create mode 100644 compiler/tests/integers/i128/min_fail.leo delete mode 100644 compiler/tests/integers/i128/one.leo delete mode 100644 compiler/tests/integers/i128/zero.leo create mode 100644 compiler/tests/integers/i16/max_fail.leo create mode 100644 compiler/tests/integers/i16/min_fail.leo delete mode 100644 compiler/tests/integers/i16/one.leo delete mode 100644 compiler/tests/integers/i16/zero.leo create mode 100644 compiler/tests/integers/i32/max_fail.leo create mode 100644 compiler/tests/integers/i32/min_fail.leo delete mode 100644 compiler/tests/integers/i32/one.leo delete mode 100644 compiler/tests/integers/i32/zero.leo create mode 100644 compiler/tests/integers/i64/max_fail.leo create mode 100644 compiler/tests/integers/i64/min_fail.leo delete mode 100644 compiler/tests/integers/i64/one.leo delete mode 100644 compiler/tests/integers/i64/zero.leo create mode 100644 compiler/tests/integers/i8/max_fail.leo create mode 100644 compiler/tests/integers/i8/min_fail.leo delete mode 100644 compiler/tests/integers/i8/one.leo delete mode 100644 compiler/tests/integers/i8/zero.leo diff --git a/compiler/tests/integers/i128/add.leo b/compiler/tests/integers/i128/add.leo index 1a90ea377d..868354c66a 100644 --- a/compiler/tests/integers/i128/add.leo +++ b/compiler/tests/integers/i128/add.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> i128 { - return a + b +function main(a: i128, b: i128, c: i128) { + assert_eq!(a + b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/div.leo b/compiler/tests/integers/i128/div.leo index e2f9f2853e..3674db9571 100644 --- a/compiler/tests/integers/i128/div.leo +++ b/compiler/tests/integers/i128/div.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> i128 { - return a / b +function main(a: i128, b: i128, c: i128) { + assert_eq!(a / b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/eq.leo b/compiler/tests/integers/i128/eq.leo index 5681aa7263..c1662f7ef9 100644 --- a/compiler/tests/integers/i128/eq.leo +++ b/compiler/tests/integers/i128/eq.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> bool { - return a == b +function main(a: i128, b: i128, c: bool) { + assert_eq!(a == b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/ge.leo b/compiler/tests/integers/i128/ge.leo index 05949082f4..f9b17623a9 100644 --- a/compiler/tests/integers/i128/ge.leo +++ b/compiler/tests/integers/i128/ge.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> bool { - return a >= b +function main(a: i128, b: i128, c: bool) { + assert_eq!(a >= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/gt.leo b/compiler/tests/integers/i128/gt.leo index 5eedfa3ec0..4c45bf6605 100644 --- a/compiler/tests/integers/i128/gt.leo +++ b/compiler/tests/integers/i128/gt.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> bool { - return a > b +function main(a: i128, b: i128, c: bool) { + assert_eq!(a > b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/input.leo b/compiler/tests/integers/i128/input.leo index aa49ca84f8..a6dc495a84 100644 --- a/compiler/tests/integers/i128/input.leo +++ b/compiler/tests/integers/i128/input.leo @@ -1,3 +1,3 @@ -function main(x: i128) -> i128 { - return x +function main(a: i128, b: i128) { + assert_eq!(a, b); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/le.leo b/compiler/tests/integers/i128/le.leo index 472e1f53ce..2f9d100793 100644 --- a/compiler/tests/integers/i128/le.leo +++ b/compiler/tests/integers/i128/le.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> bool { - return a <= b +function main(a: i128, b: i128, c: bool) { + assert_eq!(a <= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/lt.leo b/compiler/tests/integers/i128/lt.leo index 610a51e55f..766024aaac 100644 --- a/compiler/tests/integers/i128/lt.leo +++ b/compiler/tests/integers/i128/lt.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> bool { - return a < b +function main(a: i128, b: i128, c: bool) { + assert_eq!(a < b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/max.leo b/compiler/tests/integers/i128/max.leo index 06bf685187..46c0a32599 100644 --- a/compiler/tests/integers/i128/max.leo +++ b/compiler/tests/integers/i128/max.leo @@ -1,3 +1,3 @@ -function main() -> i128 { - return 170141183460469231731687303715884105727 +function main() { + let a: i128 = 170141183460469231731687303715884105727; } \ No newline at end of file diff --git a/compiler/tests/integers/i128/max_fail.leo b/compiler/tests/integers/i128/max_fail.leo new file mode 100644 index 0000000000..820eda8759 --- /dev/null +++ b/compiler/tests/integers/i128/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i128 = 170141183460469231731687303715884105728; +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/min.leo b/compiler/tests/integers/i128/min.leo index 1f90232344..5f32e5add5 100644 --- a/compiler/tests/integers/i128/min.leo +++ b/compiler/tests/integers/i128/min.leo @@ -1,3 +1,3 @@ -function main() -> i128 { - return -170141183460469231731687303715884105728 +function main() { + let a: i128 = -170141183460469231731687303715884105728; } \ No newline at end of file diff --git a/compiler/tests/integers/i128/min_fail.leo b/compiler/tests/integers/i128/min_fail.leo new file mode 100644 index 0000000000..9035444fa9 --- /dev/null +++ b/compiler/tests/integers/i128/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i128 = -170141183460469231731687303715884105729; +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/mod.rs b/compiler/tests/integers/i128/mod.rs index 6b9f332e3e..a48c981ed4 100644 --- a/compiler/tests/integers/i128/mod.rs +++ b/compiler/tests/integers/i128/mod.rs @@ -1,105 +1,92 @@ use crate::{ - boolean::{output_expected_boolean, output_false, output_true}, - get_error, - get_output, - integers::{fail_integer, IntegerTester}, + assert_satisfied, + expect_synthesis_error, + generate_main_inputs, + integers::{expect_fail, IntegerTester}, parse_program, - EdwardsConstrainedValue, - EdwardsTestCompiler, }; -use leo_compiler::{ConstrainedValue, Integer}; -use leo_gadgets::*; use leo_inputs::types::{I128Type, IntegerType}; use leo_types::InputValue; -use snarkos_curves::edwards_bls12::Fq; -use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; - -fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int128) { - let output = get_output(program); - - match output { - EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { - [ConstrainedValue::Integer(Integer::I128(actual))] => assert_eq!(*actual, expected), - _ => panic!("program output unknown return value"), - }, - _ => panic!("program output unknown return value"), - } -} - -test_int!(TestI128, i128, IntegerType::I128Type(I128Type {}), Int128); +test_int!(Testi128, i128, IntegerType::I128Type(I128Type {}), Int128); #[test] fn test_i128_min() { - TestI128::test_min(std::i128::MIN); + Testi128::test_min(); +} + +#[test] +fn test_i128_min_fail() { + Testi128::test_min_fail(); } #[test] fn test_i128_max() { - TestI128::test_max(std::i128::MAX); + Testi128::test_max(); } #[test] -fn test_i128_input() { - TestI128::test_input(); +fn test_i128_max_fail() { + Testi128::test_max_fail(); } #[test] fn test_i128_add() { - TestI128::test_add(); + Testi128::test_add(); } #[test] fn test_i128_sub() { - TestI128::test_sub(); + Testi128::test_sub(); } #[test] fn test_i128_mul() { - TestI128::test_mul(); + Testi128::test_mul(); } #[test] +#[ignore] // takes several minutes fn test_i128_div() { - TestI128::test_div(); + Testi128::test_div(); } #[test] fn test_i128_pow() { - TestI128::test_pow(); + Testi128::test_pow(); } #[test] fn test_i128_eq() { - TestI128::test_eq(); + Testi128::test_eq(); } #[test] fn test_i128_ge() { - TestI128::test_ge(); + Testi128::test_ge(); } #[test] fn test_i128_gt() { - TestI128::test_gt(); + Testi128::test_gt(); } #[test] fn test_i128_le() { - TestI128::test_le(); + Testi128::test_le(); } #[test] fn test_i128_lt() { - TestI128::test_lt(); + Testi128::test_lt(); } #[test] fn test_i128_assert_eq() { - TestI128::test_assert_eq(); + Testi128::test_assert_eq(); } #[test] fn test_i128_ternary() { - TestI128::test_ternary(); + Testi128::test_ternary(); } diff --git a/compiler/tests/integers/i128/mul.leo b/compiler/tests/integers/i128/mul.leo index 1d2595ca16..f03ca57dd1 100644 --- a/compiler/tests/integers/i128/mul.leo +++ b/compiler/tests/integers/i128/mul.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> i128 { - return a * b +function main(a: i128, b: i128, c: i128) { + assert_eq!(a * b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/one.leo b/compiler/tests/integers/i128/one.leo deleted file mode 100644 index 94313ac666..0000000000 --- a/compiler/tests/integers/i128/one.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i128 { - return 1 -} diff --git a/compiler/tests/integers/i128/pow.leo b/compiler/tests/integers/i128/pow.leo index c98bdcfe0d..dde3d48fe7 100644 --- a/compiler/tests/integers/i128/pow.leo +++ b/compiler/tests/integers/i128/pow.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> i128 { - return a ** b +function main(a: i128, b: i128, c: i128) { + assert_eq!(a ** b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/sub.leo b/compiler/tests/integers/i128/sub.leo index 87e617798f..bb473336c7 100644 --- a/compiler/tests/integers/i128/sub.leo +++ b/compiler/tests/integers/i128/sub.leo @@ -1,3 +1,3 @@ -function main(a: i128, b: i128) -> i128 { - return a - b +function main(a: i128, b: i128, c: i128) { + assert_eq!(a - b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/ternary.leo b/compiler/tests/integers/i128/ternary.leo index cb1ff53c68..a0e207d69b 100644 --- a/compiler/tests/integers/i128/ternary.leo +++ b/compiler/tests/integers/i128/ternary.leo @@ -1,3 +1,5 @@ -function main(b: bool, x: i128, y: i128) -> i128 { - return if b ? x : y +function main(s: bool, a: i128, b: i128, c: i128) { + let r = if s ? a : b; + + assert_eq!(r, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/zero.leo b/compiler/tests/integers/i128/zero.leo deleted file mode 100644 index e58cdfd4ff..0000000000 --- a/compiler/tests/integers/i128/zero.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i128 { - return 0 -} diff --git a/compiler/tests/integers/i16/add.leo b/compiler/tests/integers/i16/add.leo index 44486b97ee..ac0bfd8127 100644 --- a/compiler/tests/integers/i16/add.leo +++ b/compiler/tests/integers/i16/add.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> i16 { - return a + b +function main(a: i16, b: i16, c: i16) { + assert_eq!(a + b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/div.leo b/compiler/tests/integers/i16/div.leo index ea4d4ecded..7facede4fb 100644 --- a/compiler/tests/integers/i16/div.leo +++ b/compiler/tests/integers/i16/div.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> i16 { - return a / b +function main(a: i16, b: i16, c: i16) { + assert_eq!(a / b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/eq.leo b/compiler/tests/integers/i16/eq.leo index 1ea29bd65e..7cdea269f3 100644 --- a/compiler/tests/integers/i16/eq.leo +++ b/compiler/tests/integers/i16/eq.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> bool { - return a == b +function main(a: i16, b: i16, c: bool) { + assert_eq!(a == b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/ge.leo b/compiler/tests/integers/i16/ge.leo index 51bb45b725..b4e27b787b 100644 --- a/compiler/tests/integers/i16/ge.leo +++ b/compiler/tests/integers/i16/ge.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> bool { - return a >= b +function main(a: i16, b: i16, c: bool) { + assert_eq!(a >= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/gt.leo b/compiler/tests/integers/i16/gt.leo index 2a6eeac47a..2132a8aa6b 100644 --- a/compiler/tests/integers/i16/gt.leo +++ b/compiler/tests/integers/i16/gt.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> bool { - return a > b +function main(a: i16, b: i16, c: bool) { + assert_eq!(a > b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/input.leo b/compiler/tests/integers/i16/input.leo index c4cb048ff6..4bc5fffcad 100644 --- a/compiler/tests/integers/i16/input.leo +++ b/compiler/tests/integers/i16/input.leo @@ -1,3 +1,3 @@ -function main(x: i16) -> i16 { - return x +function main(a: i16, b: i16) { + assert_eq!(a, b); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/le.leo b/compiler/tests/integers/i16/le.leo index cd6d0eb87b..e33b3212f1 100644 --- a/compiler/tests/integers/i16/le.leo +++ b/compiler/tests/integers/i16/le.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> bool { - return a <= b +function main(a: i16, b: i16, c: bool) { + assert_eq!(a <= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/lt.leo b/compiler/tests/integers/i16/lt.leo index cfdfd24bcb..2a93c04ae3 100644 --- a/compiler/tests/integers/i16/lt.leo +++ b/compiler/tests/integers/i16/lt.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> bool { - return a < b +function main(a: i16, b: i16, c: bool) { + assert_eq!(a < b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/max.leo b/compiler/tests/integers/i16/max.leo index df19a40dd2..084fe4969a 100644 --- a/compiler/tests/integers/i16/max.leo +++ b/compiler/tests/integers/i16/max.leo @@ -1,3 +1,3 @@ -function main() -> i16 { - return 32767 +function main() { + let a: i16 = 32767; } \ No newline at end of file diff --git a/compiler/tests/integers/i16/max_fail.leo b/compiler/tests/integers/i16/max_fail.leo new file mode 100644 index 0000000000..8dd2b7f50a --- /dev/null +++ b/compiler/tests/integers/i16/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i16 = 32768; +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/min.leo b/compiler/tests/integers/i16/min.leo index 3d5949f073..3331281fcf 100644 --- a/compiler/tests/integers/i16/min.leo +++ b/compiler/tests/integers/i16/min.leo @@ -1,3 +1,3 @@ -function main() -> i16 { - return -32768 +function main() { + let a: i16 = -32768; } \ No newline at end of file diff --git a/compiler/tests/integers/i16/min_fail.leo b/compiler/tests/integers/i16/min_fail.leo new file mode 100644 index 0000000000..380848381a --- /dev/null +++ b/compiler/tests/integers/i16/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i16 = -32769; +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/mod.rs b/compiler/tests/integers/i16/mod.rs index bddaeb84be..2bf5c104f8 100644 --- a/compiler/tests/integers/i16/mod.rs +++ b/compiler/tests/integers/i16/mod.rs @@ -1,105 +1,91 @@ use crate::{ - boolean::{output_expected_boolean, output_false, output_true}, - get_error, - get_output, - integers::{fail_integer, IntegerTester}, + assert_satisfied, + expect_synthesis_error, + generate_main_inputs, + integers::{expect_fail, IntegerTester}, parse_program, - EdwardsConstrainedValue, - EdwardsTestCompiler, }; -use leo_compiler::{ConstrainedValue, Integer}; -use leo_gadgets::*; use leo_inputs::types::{I16Type, IntegerType}; use leo_types::InputValue; -use snarkos_curves::edwards_bls12::Fq; -use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; - -fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int16) { - let output = get_output(program); - - match output { - EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { - [ConstrainedValue::Integer(Integer::I16(actual))] => assert_eq!(*actual, expected), - _ => panic!("program output unknown return value"), - }, - _ => panic!("program output unknown return value"), - } -} - -test_int!(TestI16, i16, IntegerType::I16Type(I16Type {}), Int16); +test_int!(Testi16, i16, IntegerType::I16Type(I16Type {}), Int16); #[test] fn test_i16_min() { - TestI16::test_min(std::i16::MIN); + Testi16::test_min(); +} + +#[test] +fn test_i16_min_fail() { + Testi16::test_min_fail(); } #[test] fn test_i16_max() { - TestI16::test_max(std::i16::MAX); + Testi16::test_max(); } #[test] -fn test_i16_input() { - TestI16::test_input(); +fn test_i16_max_fail() { + Testi16::test_max_fail(); } #[test] fn test_i16_add() { - TestI16::test_add(); + Testi16::test_add(); } #[test] fn test_i16_sub() { - TestI16::test_sub(); + Testi16::test_sub(); } #[test] fn test_i16_mul() { - TestI16::test_mul(); + Testi16::test_mul(); } #[test] fn test_i16_div() { - TestI16::test_div(); + Testi16::test_div(); } #[test] fn test_i16_pow() { - TestI16::test_pow(); + Testi16::test_pow(); } #[test] fn test_i16_eq() { - TestI16::test_eq(); + Testi16::test_eq(); } #[test] fn test_i16_ge() { - TestI16::test_ge(); + Testi16::test_ge(); } #[test] fn test_i16_gt() { - TestI16::test_gt(); + Testi16::test_gt(); } #[test] fn test_i16_le() { - TestI16::test_le(); + Testi16::test_le(); } #[test] fn test_i16_lt() { - TestI16::test_lt(); + Testi16::test_lt(); } #[test] fn test_i16_assert_eq() { - TestI16::test_assert_eq(); + Testi16::test_assert_eq(); } #[test] fn test_i16_ternary() { - TestI16::test_ternary(); + Testi16::test_ternary(); } diff --git a/compiler/tests/integers/i16/mul.leo b/compiler/tests/integers/i16/mul.leo index ce0eb504fc..314381d199 100644 --- a/compiler/tests/integers/i16/mul.leo +++ b/compiler/tests/integers/i16/mul.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> i16 { - return a * b +function main(a: i16, b: i16, c: i16) { + assert_eq!(a * b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/one.leo b/compiler/tests/integers/i16/one.leo deleted file mode 100644 index 40af477ea3..0000000000 --- a/compiler/tests/integers/i16/one.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i16 { - return 1 -} diff --git a/compiler/tests/integers/i16/pow.leo b/compiler/tests/integers/i16/pow.leo index ca18827873..22bd4baa5d 100644 --- a/compiler/tests/integers/i16/pow.leo +++ b/compiler/tests/integers/i16/pow.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> i16 { - return a ** b +function main(a: i16, b: i16, c: i16) { + assert_eq!(a ** b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/sub.leo b/compiler/tests/integers/i16/sub.leo index 608aac1793..ef1143d3f5 100644 --- a/compiler/tests/integers/i16/sub.leo +++ b/compiler/tests/integers/i16/sub.leo @@ -1,3 +1,3 @@ -function main(a: i16, b: i16) -> i16 { - return a - b +function main(a: i16, b: i16, c: i16) { + assert_eq!(a - b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/ternary.leo b/compiler/tests/integers/i16/ternary.leo index 21d92e0818..0ef5670781 100644 --- a/compiler/tests/integers/i16/ternary.leo +++ b/compiler/tests/integers/i16/ternary.leo @@ -1,3 +1,5 @@ -function main(b: bool, x: i16, y: i16) -> i16 { - return if b ? x : y +function main(s: bool, a: i16, b: i16, c: i16) { + let r = if s ? a : b; + + assert_eq!(r, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/zero.leo b/compiler/tests/integers/i16/zero.leo deleted file mode 100644 index 781030f10a..0000000000 --- a/compiler/tests/integers/i16/zero.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i16 { - return 0 -} diff --git a/compiler/tests/integers/i32/add.leo b/compiler/tests/integers/i32/add.leo index 9c7e8f6433..d670593866 100644 --- a/compiler/tests/integers/i32/add.leo +++ b/compiler/tests/integers/i32/add.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> i32 { - return a + b +function main(a: i32, b: i32, c: i32) { + assert_eq!(a + b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/div.leo b/compiler/tests/integers/i32/div.leo index 3b1392a921..c183f43ea0 100644 --- a/compiler/tests/integers/i32/div.leo +++ b/compiler/tests/integers/i32/div.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> i32 { - return a / b +function main(a: i32, b: i32, c: i32) { + assert_eq!(a / b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/eq.leo b/compiler/tests/integers/i32/eq.leo index b3284a07d0..09a3c69f73 100644 --- a/compiler/tests/integers/i32/eq.leo +++ b/compiler/tests/integers/i32/eq.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> bool { - return a == b +function main(a: i32, b: i32, c: bool) { + assert_eq!(a == b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/ge.leo b/compiler/tests/integers/i32/ge.leo index 073955b53f..99ca610acd 100644 --- a/compiler/tests/integers/i32/ge.leo +++ b/compiler/tests/integers/i32/ge.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> bool { - return a >= b +function main(a: i32, b: i32, c: bool) { + assert_eq!(a >= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/gt.leo b/compiler/tests/integers/i32/gt.leo index acf027eade..be6645354d 100644 --- a/compiler/tests/integers/i32/gt.leo +++ b/compiler/tests/integers/i32/gt.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> bool { - return a > b +function main(a: i32, b: i32, c: bool) { + assert_eq!(a > b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/input.leo b/compiler/tests/integers/i32/input.leo index ea6d7f9d30..326cca12b6 100644 --- a/compiler/tests/integers/i32/input.leo +++ b/compiler/tests/integers/i32/input.leo @@ -1,3 +1,3 @@ -function main(x: i32) -> i32 { - return x +function main(a: i32, b: i32) { + assert_eq!(a, b); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/le.leo b/compiler/tests/integers/i32/le.leo index 5f2615cd0a..37682aeda2 100644 --- a/compiler/tests/integers/i32/le.leo +++ b/compiler/tests/integers/i32/le.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> bool { - return a <= b +function main(a: i32, b: i32, c: bool) { + assert_eq!(a <= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/lt.leo b/compiler/tests/integers/i32/lt.leo index aea55410fa..90965ae47a 100644 --- a/compiler/tests/integers/i32/lt.leo +++ b/compiler/tests/integers/i32/lt.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> bool { - return a < b +function main(a: i32, b: i32, c: bool) { + assert_eq!(a < b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/max.leo b/compiler/tests/integers/i32/max.leo index d5e3a94dd4..a9c707eb7f 100644 --- a/compiler/tests/integers/i32/max.leo +++ b/compiler/tests/integers/i32/max.leo @@ -1,3 +1,3 @@ -function main() -> i32 { - return 2147483647 +function main() { + let a: i32 = 2147483647; } \ No newline at end of file diff --git a/compiler/tests/integers/i32/max_fail.leo b/compiler/tests/integers/i32/max_fail.leo new file mode 100644 index 0000000000..f3fd81815f --- /dev/null +++ b/compiler/tests/integers/i32/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i32 = 2147483648; +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/min.leo b/compiler/tests/integers/i32/min.leo index 1625435322..a29d591029 100644 --- a/compiler/tests/integers/i32/min.leo +++ b/compiler/tests/integers/i32/min.leo @@ -1,3 +1,3 @@ -function main() -> i32 { - return -2147483648 +function main() { + let a: i32 = -2147483648; } \ No newline at end of file diff --git a/compiler/tests/integers/i32/min_fail.leo b/compiler/tests/integers/i32/min_fail.leo new file mode 100644 index 0000000000..1462d207e9 --- /dev/null +++ b/compiler/tests/integers/i32/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i32 = -2147483649; +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/mod.rs b/compiler/tests/integers/i32/mod.rs index 940379ad8d..8339a93968 100644 --- a/compiler/tests/integers/i32/mod.rs +++ b/compiler/tests/integers/i32/mod.rs @@ -1,105 +1,91 @@ use crate::{ - boolean::{output_expected_boolean, output_false, output_true}, - get_error, - get_output, - integers::{fail_integer, IntegerTester}, + assert_satisfied, + expect_synthesis_error, + generate_main_inputs, + integers::{expect_fail, IntegerTester}, parse_program, - EdwardsConstrainedValue, - EdwardsTestCompiler, }; -use leo_compiler::{ConstrainedValue, Integer}; -use leo_gadgets::*; use leo_inputs::types::{I32Type, IntegerType}; use leo_types::InputValue; -use snarkos_curves::edwards_bls12::Fq; -use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; - -fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int32) { - let output = get_output(program); - - match output { - EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { - [ConstrainedValue::Integer(Integer::I32(actual))] => assert_eq!(*actual, expected), - _ => panic!("program output unknown return value"), - }, - _ => panic!("program output unknown return value"), - } -} - -test_int!(TestI32, i32, IntegerType::I32Type(I32Type {}), Int32); +test_int!(Testi32, i32, IntegerType::I32Type(I32Type {}), Int32); #[test] fn test_i32_min() { - TestI32::test_min(std::i32::MIN); + Testi32::test_min(); +} + +#[test] +fn test_i32_min_fail() { + Testi32::test_min_fail(); } #[test] fn test_i32_max() { - TestI32::test_max(std::i32::MAX); + Testi32::test_max(); } #[test] -fn test_i32_input() { - TestI32::test_input(); +fn test_i32_max_fail() { + Testi32::test_max_fail(); } #[test] fn test_i32_add() { - TestI32::test_add(); + Testi32::test_add(); } #[test] fn test_i32_sub() { - TestI32::test_sub(); + Testi32::test_sub(); } #[test] fn test_i32_mul() { - TestI32::test_mul(); + Testi32::test_mul(); } #[test] fn test_i32_div() { - TestI32::test_div(); + Testi32::test_div(); } #[test] fn test_i32_pow() { - TestI32::test_pow(); + Testi32::test_pow(); } #[test] fn test_i32_eq() { - TestI32::test_eq(); + Testi32::test_eq(); } #[test] fn test_i32_ge() { - TestI32::test_ge(); + Testi32::test_ge(); } #[test] fn test_i32_gt() { - TestI32::test_gt(); + Testi32::test_gt(); } #[test] fn test_i32_le() { - TestI32::test_le(); + Testi32::test_le(); } #[test] fn test_i32_lt() { - TestI32::test_lt(); + Testi32::test_lt(); } #[test] fn test_i32_assert_eq() { - TestI32::test_assert_eq(); + Testi32::test_assert_eq(); } #[test] fn test_i32_ternary() { - TestI32::test_ternary(); + Testi32::test_ternary(); } diff --git a/compiler/tests/integers/i32/mul.leo b/compiler/tests/integers/i32/mul.leo index 8ab0c36205..029aa60758 100644 --- a/compiler/tests/integers/i32/mul.leo +++ b/compiler/tests/integers/i32/mul.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> i32 { - return a * b +function main(a: i32, b: i32, c: i32) { + assert_eq!(a * b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/one.leo b/compiler/tests/integers/i32/one.leo deleted file mode 100644 index 5ef3894d5e..0000000000 --- a/compiler/tests/integers/i32/one.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i32 { - return 1 -} diff --git a/compiler/tests/integers/i32/pow.leo b/compiler/tests/integers/i32/pow.leo index 790da91ead..65a840cf26 100644 --- a/compiler/tests/integers/i32/pow.leo +++ b/compiler/tests/integers/i32/pow.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> i32 { - return a ** b +function main(a: i32, b: i32, c: i32) { + assert_eq!(a ** b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/sub.leo b/compiler/tests/integers/i32/sub.leo index c446484173..03179a547d 100644 --- a/compiler/tests/integers/i32/sub.leo +++ b/compiler/tests/integers/i32/sub.leo @@ -1,3 +1,3 @@ -function main(a: i32, b: i32) -> i32 { - return a - b +function main(a: i32, b: i32, c: i32) { + assert_eq!(a - b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/ternary.leo b/compiler/tests/integers/i32/ternary.leo index fbff679a00..211065cea2 100644 --- a/compiler/tests/integers/i32/ternary.leo +++ b/compiler/tests/integers/i32/ternary.leo @@ -1,3 +1,5 @@ -function main(b: bool, x: i32, y: i32) -> i32 { - return if b ? x : y +function main(s: bool, a: i32, b: i32, c: i32) { + let r = if s ? a : b; + + assert_eq!(r, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/zero.leo b/compiler/tests/integers/i32/zero.leo deleted file mode 100644 index 53922fcf02..0000000000 --- a/compiler/tests/integers/i32/zero.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i32 { - return 0 -} diff --git a/compiler/tests/integers/i64/add.leo b/compiler/tests/integers/i64/add.leo index 67d83b4193..edd5137eae 100644 --- a/compiler/tests/integers/i64/add.leo +++ b/compiler/tests/integers/i64/add.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> i64 { - return a + b +function main(a: i64, b: i64, c: i64) { + assert_eq!(a + b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/div.leo b/compiler/tests/integers/i64/div.leo index e61e6f0850..5fd9b5929e 100644 --- a/compiler/tests/integers/i64/div.leo +++ b/compiler/tests/integers/i64/div.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> i64 { - return a / b +function main(a: i64, b: i64, c: i64) { + assert_eq!(a / b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/eq.leo b/compiler/tests/integers/i64/eq.leo index af2017d361..736b94efd2 100644 --- a/compiler/tests/integers/i64/eq.leo +++ b/compiler/tests/integers/i64/eq.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> bool { - return a == b +function main(a: i64, b: i64, c: bool) { + assert_eq!(a == b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/ge.leo b/compiler/tests/integers/i64/ge.leo index cbe7fe0635..00ea4e716b 100644 --- a/compiler/tests/integers/i64/ge.leo +++ b/compiler/tests/integers/i64/ge.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> bool { - return a >= b +function main(a: i64, b: i64, c: bool) { + assert_eq!(a >= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/gt.leo b/compiler/tests/integers/i64/gt.leo index 77286d5c82..c39799fb2c 100644 --- a/compiler/tests/integers/i64/gt.leo +++ b/compiler/tests/integers/i64/gt.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> bool { - return a > b +function main(a: i64, b: i64, c: bool) { + assert_eq!(a > b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/input.leo b/compiler/tests/integers/i64/input.leo index b9e90054a6..a9e7b44750 100644 --- a/compiler/tests/integers/i64/input.leo +++ b/compiler/tests/integers/i64/input.leo @@ -1,3 +1,3 @@ -function main(x: i64) -> i64 { - return x +function main(a: i64, b: i64) { + assert_eq!(a, b); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/le.leo b/compiler/tests/integers/i64/le.leo index e2d31dcac5..e8b1f47478 100644 --- a/compiler/tests/integers/i64/le.leo +++ b/compiler/tests/integers/i64/le.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> bool { - return a <= b +function main(a: i64, b: i64, c: bool) { + assert_eq!(a <= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/lt.leo b/compiler/tests/integers/i64/lt.leo index c46123fc42..a908b8b0f7 100644 --- a/compiler/tests/integers/i64/lt.leo +++ b/compiler/tests/integers/i64/lt.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> bool { - return a < b +function main(a: i64, b: i64, c: bool) { + assert_eq!(a < b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/max.leo b/compiler/tests/integers/i64/max.leo index 0173b80e94..e0d19881e6 100644 --- a/compiler/tests/integers/i64/max.leo +++ b/compiler/tests/integers/i64/max.leo @@ -1,3 +1,3 @@ -function main() -> i64 { - return 9223372036854775807 +function main() { + let a: i64 = 9223372036854775807; } \ No newline at end of file diff --git a/compiler/tests/integers/i64/max_fail.leo b/compiler/tests/integers/i64/max_fail.leo new file mode 100644 index 0000000000..3e6603e4be --- /dev/null +++ b/compiler/tests/integers/i64/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i64 = 9223372036854775808; +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/min.leo b/compiler/tests/integers/i64/min.leo index 3a1817a736..d7e99a87f8 100644 --- a/compiler/tests/integers/i64/min.leo +++ b/compiler/tests/integers/i64/min.leo @@ -1,3 +1,3 @@ -function main() -> i64 { - return -9223372036854775808 +function main() { + let a: i64 = -9223372036854775808; } \ No newline at end of file diff --git a/compiler/tests/integers/i64/min_fail.leo b/compiler/tests/integers/i64/min_fail.leo new file mode 100644 index 0000000000..11e43646b0 --- /dev/null +++ b/compiler/tests/integers/i64/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i64 = -9223372036854775809; +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/mod.rs b/compiler/tests/integers/i64/mod.rs index e0774f4a85..b8407b393e 100644 --- a/compiler/tests/integers/i64/mod.rs +++ b/compiler/tests/integers/i64/mod.rs @@ -1,105 +1,91 @@ use crate::{ - boolean::{output_expected_boolean, output_false, output_true}, - get_error, - get_output, - integers::{fail_integer, IntegerTester}, + assert_satisfied, + expect_synthesis_error, + generate_main_inputs, + integers::{expect_fail, IntegerTester}, parse_program, - EdwardsConstrainedValue, - EdwardsTestCompiler, }; -use leo_compiler::{ConstrainedValue, Integer}; -use leo_gadgets::*; use leo_inputs::types::{I64Type, IntegerType}; use leo_types::InputValue; -use snarkos_curves::edwards_bls12::Fq; -use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; - -fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int64) { - let output = get_output(program); - - match output { - EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { - [ConstrainedValue::Integer(Integer::I64(actual))] => assert_eq!(*actual, expected), - _ => panic!("program output unknown return value"), - }, - _ => panic!("program output unknown return value"), - } -} - -test_int!(TestI64, i64, IntegerType::I64Type(I64Type {}), Int64); +test_int!(Testi64, i64, IntegerType::I64Type(I64Type {}), Int64); #[test] fn test_i64_min() { - TestI64::test_min(std::i64::MIN); + Testi64::test_min(); +} + +#[test] +fn test_i64_min_fail() { + Testi64::test_min_fail(); } #[test] fn test_i64_max() { - TestI64::test_max(std::i64::MAX); + Testi64::test_max(); } #[test] -fn test_i64_input() { - TestI64::test_input(); +fn test_i64_max_fail() { + Testi64::test_max_fail(); } #[test] fn test_i64_add() { - TestI64::test_add(); + Testi64::test_add(); } #[test] fn test_i64_sub() { - TestI64::test_sub(); + Testi64::test_sub(); } #[test] fn test_i64_mul() { - TestI64::test_mul(); + Testi64::test_mul(); } -#[test] +#[test] // takes 90 seconds fn test_i64_div() { - TestI64::test_div(); + Testi64::test_div(); } #[test] fn test_i64_pow() { - TestI64::test_pow(); + Testi64::test_pow(); } #[test] fn test_i64_eq() { - TestI64::test_eq(); + Testi64::test_eq(); } #[test] fn test_i64_ge() { - TestI64::test_ge(); + Testi64::test_ge(); } #[test] fn test_i64_gt() { - TestI64::test_gt(); + Testi64::test_gt(); } #[test] fn test_i64_le() { - TestI64::test_le(); + Testi64::test_le(); } #[test] fn test_i64_lt() { - TestI64::test_lt(); + Testi64::test_lt(); } #[test] fn test_i64_assert_eq() { - TestI64::test_assert_eq(); + Testi64::test_assert_eq(); } #[test] fn test_i64_ternary() { - TestI64::test_ternary(); + Testi64::test_ternary(); } diff --git a/compiler/tests/integers/i64/mul.leo b/compiler/tests/integers/i64/mul.leo index f9d415009b..cbff5a9cc8 100644 --- a/compiler/tests/integers/i64/mul.leo +++ b/compiler/tests/integers/i64/mul.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> i64 { - return a * b +function main(a: i64, b: i64, c: i64) { + assert_eq!(a * b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/one.leo b/compiler/tests/integers/i64/one.leo deleted file mode 100644 index c3fd8abc72..0000000000 --- a/compiler/tests/integers/i64/one.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i64 { - return 1 -} diff --git a/compiler/tests/integers/i64/pow.leo b/compiler/tests/integers/i64/pow.leo index efad660c04..99e71b1968 100644 --- a/compiler/tests/integers/i64/pow.leo +++ b/compiler/tests/integers/i64/pow.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> i64 { - return a ** b +function main(a: i64, b: i64, c: i64) { + assert_eq!(a ** b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/sub.leo b/compiler/tests/integers/i64/sub.leo index bc5be06b7a..98af2e973a 100644 --- a/compiler/tests/integers/i64/sub.leo +++ b/compiler/tests/integers/i64/sub.leo @@ -1,3 +1,3 @@ -function main(a: i64, b: i64) -> i64 { - return a - b +function main(a: i64, b: i64, c: i64) { + assert_eq!(a - b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/ternary.leo b/compiler/tests/integers/i64/ternary.leo index dc7bf1f81e..049e1d8d4e 100644 --- a/compiler/tests/integers/i64/ternary.leo +++ b/compiler/tests/integers/i64/ternary.leo @@ -1,3 +1,5 @@ -function main(b: bool, x: i64, y: i64) -> i64 { - return if b ? x : y +function main(s: bool, a: i64, b: i64, c: i64) { + let r = if s ? a : b; + + assert_eq!(r, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/zero.leo b/compiler/tests/integers/i64/zero.leo deleted file mode 100644 index ce0a3bd9c2..0000000000 --- a/compiler/tests/integers/i64/zero.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i64 { - return 0 -} diff --git a/compiler/tests/integers/i8/add.leo b/compiler/tests/integers/i8/add.leo index 47cd676483..054c46374a 100644 --- a/compiler/tests/integers/i8/add.leo +++ b/compiler/tests/integers/i8/add.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> i8 { - return a + b +function main(a: i8, b: i8, c: i8) { + assert_eq!(a + b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/div.leo b/compiler/tests/integers/i8/div.leo index 7382b985e9..02cbcb6ee8 100644 --- a/compiler/tests/integers/i8/div.leo +++ b/compiler/tests/integers/i8/div.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> i8 { - return a / b +function main(a: i8, b: i8, c: i8) { + assert_eq!(a / b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/eq.leo b/compiler/tests/integers/i8/eq.leo index 2b8c3c11bd..6dee94580b 100644 --- a/compiler/tests/integers/i8/eq.leo +++ b/compiler/tests/integers/i8/eq.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> bool { - return a == b +function main(a: i8, b: i8, c: bool) { + assert_eq!(a == b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/ge.leo b/compiler/tests/integers/i8/ge.leo index 69d9808a09..df95a325bd 100644 --- a/compiler/tests/integers/i8/ge.leo +++ b/compiler/tests/integers/i8/ge.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> bool { - return a >= b +function main(a: i8, b: i8, c: bool) { + assert_eq!(a >= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/gt.leo b/compiler/tests/integers/i8/gt.leo index 6346b285cd..70c59e398c 100644 --- a/compiler/tests/integers/i8/gt.leo +++ b/compiler/tests/integers/i8/gt.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> bool { - return a > b +function main(a: i8, b: i8, c: bool) { + assert_eq!(a > b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/input.leo b/compiler/tests/integers/i8/input.leo index ae50705338..c397ca8c07 100644 --- a/compiler/tests/integers/i8/input.leo +++ b/compiler/tests/integers/i8/input.leo @@ -1,3 +1,3 @@ -function main(x: i8) -> i8 { - return x +function main(a: i8, b: i8) { + assert_eq!(a, b); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/le.leo b/compiler/tests/integers/i8/le.leo index 791e64d793..dba7694960 100644 --- a/compiler/tests/integers/i8/le.leo +++ b/compiler/tests/integers/i8/le.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> bool { - return a <= b +function main(a: i8, b: i8, c: bool) { + assert_eq!(a <= b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/lt.leo b/compiler/tests/integers/i8/lt.leo index 00c6e61324..0385ce1c49 100644 --- a/compiler/tests/integers/i8/lt.leo +++ b/compiler/tests/integers/i8/lt.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> bool { - return a < b +function main(a: i8, b: i8, c: bool) { + assert_eq!(a < b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/max.leo b/compiler/tests/integers/i8/max.leo index ed57f26a33..b51126da59 100644 --- a/compiler/tests/integers/i8/max.leo +++ b/compiler/tests/integers/i8/max.leo @@ -1,3 +1,3 @@ -function main() -> i8 { - return 127 +function main() { + let a: i8 = 127; } \ No newline at end of file diff --git a/compiler/tests/integers/i8/max_fail.leo b/compiler/tests/integers/i8/max_fail.leo new file mode 100644 index 0000000000..4892505915 --- /dev/null +++ b/compiler/tests/integers/i8/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i8 = 128; +} \ No newline at end of file diff --git a/compiler/tests/integers/i8/min.leo b/compiler/tests/integers/i8/min.leo index d334e0ad4c..d3c1bff5e4 100644 --- a/compiler/tests/integers/i8/min.leo +++ b/compiler/tests/integers/i8/min.leo @@ -1,3 +1,3 @@ -function main() -> i8 { - return -128 +function main() { + let a: i8 = -128; } \ No newline at end of file diff --git a/compiler/tests/integers/i8/min_fail.leo b/compiler/tests/integers/i8/min_fail.leo new file mode 100644 index 0000000000..051468ea70 --- /dev/null +++ b/compiler/tests/integers/i8/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i8 = -129; +} \ No newline at end of file diff --git a/compiler/tests/integers/i8/mod.rs b/compiler/tests/integers/i8/mod.rs index 94c1dde76a..f9a8deea57 100644 --- a/compiler/tests/integers/i8/mod.rs +++ b/compiler/tests/integers/i8/mod.rs @@ -1,105 +1,91 @@ use crate::{ - boolean::{output_expected_boolean, output_false, output_true}, - get_error, - get_output, - integers::{fail_integer, IntegerTester}, + assert_satisfied, + expect_synthesis_error, + generate_main_inputs, + integers::{expect_fail, IntegerTester}, parse_program, - EdwardsConstrainedValue, - EdwardsTestCompiler, }; -use leo_compiler::{ConstrainedValue, Integer}; -use leo_gadgets::*; use leo_inputs::types::{I8Type, IntegerType}; use leo_types::InputValue; -use snarkos_curves::edwards_bls12::Fq; -use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; - -fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int8) { - let output = get_output(program); - - match output { - EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { - [ConstrainedValue::Integer(Integer::I8(actual))] => assert_eq!(*actual, expected), - _ => panic!("program output unknown return value"), - }, - _ => panic!("program output unknown return value"), - } -} - -test_int!(TestI8, i8, IntegerType::I8Type(I8Type {}), Int8); +test_int!(Testi8, i8, IntegerType::I8Type(I8Type {}), Int8); #[test] fn test_i8_min() { - TestI8::test_min(std::i8::MIN); + Testi8::test_min(); +} + +#[test] +fn test_i8_min_fail() { + Testi8::test_min_fail(); } #[test] fn test_i8_max() { - TestI8::test_max(std::i8::MAX); + Testi8::test_max(); } #[test] -fn test_i8_input() { - TestI8::test_input(); +fn test_i8_max_fail() { + Testi8::test_max_fail(); } #[test] fn test_i8_add() { - TestI8::test_add(); + Testi8::test_add(); } #[test] fn test_i8_sub() { - TestI8::test_sub(); + Testi8::test_sub(); } #[test] fn test_i8_mul() { - TestI8::test_mul(); + Testi8::test_mul(); } #[test] fn test_i8_div() { - TestI8::test_div(); + Testi8::test_div(); } #[test] fn test_i8_pow() { - TestI8::test_pow(); + Testi8::test_pow(); } #[test] fn test_i8_eq() { - TestI8::test_eq(); + Testi8::test_eq(); } #[test] fn test_i8_ge() { - TestI8::test_ge(); + Testi8::test_ge(); } #[test] fn test_i8_gt() { - TestI8::test_gt(); + Testi8::test_gt(); } #[test] fn test_i8_le() { - TestI8::test_le(); + Testi8::test_le(); } #[test] fn test_i8_lt() { - TestI8::test_lt(); + Testi8::test_lt(); } #[test] fn test_i8_assert_eq() { - TestI8::test_assert_eq(); + Testi8::test_assert_eq(); } #[test] fn test_i8_ternary() { - TestI8::test_ternary(); + Testi8::test_ternary(); } diff --git a/compiler/tests/integers/i8/mul.leo b/compiler/tests/integers/i8/mul.leo index 88c4fa5b5d..3542bc092c 100644 --- a/compiler/tests/integers/i8/mul.leo +++ b/compiler/tests/integers/i8/mul.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> i8 { - return a * b +function main(a: i8, b: i8, c: i8) { + assert_eq!(a * b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/one.leo b/compiler/tests/integers/i8/one.leo deleted file mode 100644 index 2e0ffefa27..0000000000 --- a/compiler/tests/integers/i8/one.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i8 { - return 1 -} diff --git a/compiler/tests/integers/i8/pow.leo b/compiler/tests/integers/i8/pow.leo index 68837dda70..c66bb67b7a 100644 --- a/compiler/tests/integers/i8/pow.leo +++ b/compiler/tests/integers/i8/pow.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> i8 { - return a ** b +function main(a: i8, b: i8, c: i8) { + assert_eq!(a ** b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/sub.leo b/compiler/tests/integers/i8/sub.leo index 234a4f4fee..b4a4ad01d9 100644 --- a/compiler/tests/integers/i8/sub.leo +++ b/compiler/tests/integers/i8/sub.leo @@ -1,3 +1,3 @@ -function main(a: i8, b: i8) -> i8 { - return a - b +function main(a: i8, b: i8, c: i8) { + assert_eq!(a - b, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/ternary.leo b/compiler/tests/integers/i8/ternary.leo index 68bcbd1a03..1de75a7b99 100644 --- a/compiler/tests/integers/i8/ternary.leo +++ b/compiler/tests/integers/i8/ternary.leo @@ -1,3 +1,5 @@ -function main(b: bool, x: i8, y: i8) -> i8 { - return if b ? x : y +function main(s: bool, a: i8, b: i8, c: i8) { + let r = if s ? a : b; + + assert_eq!(r, c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/zero.leo b/compiler/tests/integers/i8/zero.leo deleted file mode 100644 index d58befa8b9..0000000000 --- a/compiler/tests/integers/i8/zero.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> i8 { - return 0 -} diff --git a/compiler/tests/integers/int_macro.rs b/compiler/tests/integers/int_macro.rs index 0c40e783ee..9314634584 100644 --- a/compiler/tests/integers/int_macro.rs +++ b/compiler/tests/integers/int_macro.rs @@ -2,405 +2,437 @@ macro_rules! test_int { ($name: ident, $type_: ty, $integer_type: expr, $gadget: ty) => { pub struct $name {} - impl $name { - fn test_min(min: $type_) { - let min_allocated = <$gadget>::constant(min); - + impl IntegerTester for $name { + fn test_min() { let bytes = include_bytes!("min.leo"); let program = parse_program(bytes).unwrap(); - output_expected_allocated(program, min_allocated); + assert_satisfied(program); } - fn test_max(max: $type_) { - let max_allocated = <$gadget>::constant(max); + fn test_min_fail() { + let bytes = include_bytes!("min_fail.leo"); + let program = parse_program(bytes).unwrap(); + expect_fail(program); + } + + fn test_max() { let bytes = include_bytes!("max.leo"); let program = parse_program(bytes).unwrap(); - output_expected_allocated(program, max_allocated); + assert_satisfied(program); } - } - impl IntegerTester for $name { - fn test_input() { - // valid input - let num: $type_ = rand::random(); - let expected = <$gadget>::constant(num); + fn test_max_fail() { + let bytes = include_bytes!("max_fail.leo"); + let program = parse_program(bytes).unwrap(); - let bytes = include_bytes!("input.leo"); - let mut program = parse_program(bytes).unwrap(); - - program.set_inputs(vec![Some(InputValue::Integer($integer_type, num.to_string()))]); - - output_expected_allocated(program, expected); - - // invalid input - let mut program = parse_program(bytes).unwrap(); - - program.set_inputs(vec![Some(InputValue::Boolean(true))]); - fail_integer(program); - - // None input - let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![None]); - fail_integer(program); + expect_fail(program); } fn test_add() { for _ in 0..10 { - let r1: $type_ = rand::random(); - let r2: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); - let sum = match r1.checked_add(r2) { + let c = match a.checked_add(b) { Some(valid) => valid, None => continue, }; - let cs = TestConstraintSystem::::new(); - let sum_allocated = <$gadget>::alloc(cs, || Ok(sum)).unwrap(); - let bytes = include_bytes!("add.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, c.to_string()))), ]); - output_expected_allocated(program, sum_allocated); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_sub() { for _ in 0..10 { - let r1: $type_ = rand::random(); - let r2: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); - if r2.checked_neg().is_none() { + if b.checked_neg().is_none() { continue; } - let difference = match r1.checked_sub(r2) { + let c = match a.checked_sub(b) { Some(valid) => valid, None => continue, }; - let cs = TestConstraintSystem::::new(); - let difference_allocated = <$gadget>::alloc(cs, || Ok(difference)).unwrap(); - let bytes = include_bytes!("sub.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, c.to_string()))), ]); - output_expected_allocated(program, difference_allocated); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_mul() { for _ in 0..10 { - let r1: $type_ = rand::random(); - let r2: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); - let product = match r1.checked_mul(r2) { + let c = match a.checked_mul(b) { Some(valid) => valid, None => continue, }; - let cs = TestConstraintSystem::::new(); - let product_allocated = <$gadget>::alloc(cs, || Ok(product)).unwrap(); - let bytes = include_bytes!("mul.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, c.to_string()))), ]); - output_expected_allocated(program, product_allocated); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_div() { - // for _ in 0..10 {// these loops take an excessive amount of time - let r1: $type_ = rand::random(); - let r2: $type_ = rand::random(); + for _ in 0..10 { + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); - let bytes = include_bytes!("div.leo"); - let mut program = parse_program(bytes).unwrap(); + let bytes = include_bytes!("div.leo"); + let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), - ]); + // expect an error when dividing by zero + if b == 0 { + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, b.to_string()))), + ]); - // expect an error when dividing by zero - if r2 == 0 { - let _err = get_error(program); - } else { - let cs = TestConstraintSystem::::new(); + program.set_main_inputs(main_inputs); - let quotient = match r1.checked_div(r2) { - Some(valid) => valid, - None => return, - }; - let quotient_allocated = <$gadget>::alloc(cs, || Ok(quotient)).unwrap(); + expect_fail(program); + } else { + let c = match a.checked_div(b) { + Some(valid) => valid, + None => return, + }; - output_expected_allocated(program, quotient_allocated); + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, c.to_string()))), + ]); + + program.set_main_inputs(main_inputs); + + assert_satisfied(program); + } } - // } } fn test_pow() { - // for _ in 0..10 {// these loops take an excessive amount of time - let r1: $type_ = rand::random(); - let r2: $type_ = rand::random(); - let r2 = r2 as u32; // we cast to u32 here because of rust pow() requirements + for _ in 0..10 { + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); - let result = match r1.checked_pow(r2) { - Some(valid) => valid, - None => return, - }; + // rust specific conversion see https://doc.rust-lang.org/std/primitive.u8.html#method.checked_pow + let c = match a.checked_pow(b as u32) { + Some(valid) => valid, + None => continue, + }; - let cs = TestConstraintSystem::::new(); - let result_allocated = <$gadget>::alloc(cs, || Ok(result)).unwrap(); + let bytes = include_bytes!("pow.leo"); + let mut program = parse_program(bytes).unwrap(); - let bytes = include_bytes!("pow.leo"); - let mut program = parse_program(bytes).unwrap(); + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, c.to_string()))), + ]); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), - ]); + program.set_main_inputs(main_inputs); - output_expected_allocated(program, result_allocated); - // } + assert_satisfied(program); + } } fn test_eq() { for _ in 0..10 { - let r1: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); // test equal + let bytes = include_bytes!("eq.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r1.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, a.to_string()))), + ("c", Some(InputValue::Boolean(true))), ]); - output_true(program); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); // test not equal - let r2: $type_ = rand::random(); - let result = r1.eq(&r2); + let c = a.eq(&b); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Boolean(c))), ]); - output_expected_boolean(program, result); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_ge() { for _ in 0..10 { - let r1: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); // test equal + let bytes = include_bytes!("ge.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r1.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, a.to_string()))), + ("c", Some(InputValue::Boolean(true))), ]); - output_true(program); + program.set_main_inputs(main_inputs); - // test not equal - let r2: $type_ = rand::random(); + assert_satisfied(program); - let result = r1.ge(&r2); + // test greater or equal + + let c = a.ge(&b); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Boolean(c))), ]); - output_expected_boolean(program, result); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_gt() { for _ in 0..10 { - let r1: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); // test equal + let bytes = include_bytes!("gt.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r1.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, a.to_string()))), + ("c", Some(InputValue::Boolean(false))), ]); - output_false(program); + program.set_main_inputs(main_inputs); - // test not equal - let r2: $type_ = rand::random(); + assert_satisfied(program); - let result = r1.gt(&r2); + // test greater than + + let c = a.gt(&b); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Boolean(c))), ]); - output_expected_boolean(program, result); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_le() { for _ in 0..10 { - let r1: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); // test equal + let bytes = include_bytes!("le.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r1.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, a.to_string()))), + ("c", Some(InputValue::Boolean(true))), ]); - output_true(program); + program.set_main_inputs(main_inputs); - // test not equal - let r2: $type_ = rand::random(); + assert_satisfied(program); - let result = r1.le(&r2); + // test less or equal + + let c = a.le(&b); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Boolean(c))), ]); - output_expected_boolean(program, result); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_lt() { for _ in 0..10 { - let r1: $type_ = rand::random(); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); // test equal + let bytes = include_bytes!("lt.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r1.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, a.to_string()))), + ("c", Some(InputValue::Boolean(false))), ]); - output_false(program); + program.set_main_inputs(main_inputs); - // test not equal - let r2: $type_ = rand::random(); + assert_satisfied(program); - let result = r1.lt(&r2); + // test less or equal + + let c = a.lt(&b); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Boolean(c))), ]); - output_expected_boolean(program, result); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } fn test_assert_eq() { for _ in 0..10 { - let r1: $type_ = rand::random(); + let a: $type_ = rand::random(); // test equal let bytes = include_bytes!("assert_eq.leo"); let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r1.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, a.to_string()))), ]); - let _ = get_output(program); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); // test not equal - let r2: $type_ = rand::random(); + let b: $type_ = rand::random(); - if r1 == r2 { + if a == b { continue; } let mut program = parse_program(bytes).unwrap(); - program.set_inputs(vec![ - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), ]); - let mut cs = TestConstraintSystem::::new(); - let _ = program.compile_constraints(&mut cs).unwrap(); - assert!(!cs.is_satisfied()); + program.set_main_inputs(main_inputs); + + expect_synthesis_error(program); } } fn test_ternary() { - let r1: $type_ = rand::random(); - let r2: $type_ = rand::random(); - - let g1 = <$gadget>::constant(r1); - let g2 = <$gadget>::constant(r2); + let a: $type_ = rand::random(); + let b: $type_ = rand::random(); let bytes = include_bytes!("ternary.leo"); - let mut program_1 = parse_program(bytes).unwrap(); - - let mut program_2 = program_1.clone(); + let mut program = parse_program(bytes).unwrap(); // true -> field 1 - program_1.set_inputs(vec![ - Some(InputValue::Boolean(true)), - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let main_inputs = generate_main_inputs(vec![ + ("s", Some(InputValue::Boolean(true))), + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, a.to_string()))), ]); - output_expected_allocated(program_1, g1); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); // false -> field 2 - program_2.set_inputs(vec![ - Some(InputValue::Boolean(false)), - Some(InputValue::Integer($integer_type, r1.to_string())), - Some(InputValue::Integer($integer_type, r2.to_string())), + let mut program = parse_program(bytes).unwrap(); + + let main_inputs = generate_main_inputs(vec![ + ("s", Some(InputValue::Boolean(false))), + ("a", Some(InputValue::Integer($integer_type, a.to_string()))), + ("b", Some(InputValue::Integer($integer_type, b.to_string()))), + ("c", Some(InputValue::Integer($integer_type, b.to_string()))), ]); - output_expected_allocated(program_2, g2); + program.set_main_inputs(main_inputs); + + assert_satisfied(program); } } }; diff --git a/compiler/tests/integers/integer_tester.rs b/compiler/tests/integers/integer_tester.rs index f62f31c84a..23e87515e5 100644 --- a/compiler/tests/integers/integer_tester.rs +++ b/compiler/tests/integers/integer_tester.rs @@ -56,6 +56,6 @@ pub(crate) fn expect_fail(program: EdwardsTestCompiler) { CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError( ExpressionError::ValueError(ValueError::IntegerError(IntegerError::Error(_))), ))) => {} - error => panic!("Expected invalid boolean error, got {:?}", error), + error => panic!("Expected invalid integer error, got {:?}", error), } } diff --git a/compiler/tests/integers/mod.rs b/compiler/tests/integers/mod.rs index c3b3cd01dc..2abbeacf2e 100644 --- a/compiler/tests/integers/mod.rs +++ b/compiler/tests/integers/mod.rs @@ -14,8 +14,8 @@ pub mod u32; pub mod u64; pub mod u8; -// pub mod i128; -// pub mod i16; -// pub mod i32; -// pub mod i64; -// pub mod i8; +pub mod i128; +pub mod i16; +pub mod i32; +pub mod i64; +pub mod i8; diff --git a/compiler/tests/integers/u128/min.leo b/compiler/tests/integers/u128/min.leo index 0f1c080938..044bda9e1c 100644 --- a/compiler/tests/integers/u128/min.leo +++ b/compiler/tests/integers/u128/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 0; + let a: u128 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u128/min_fail.leo b/compiler/tests/integers/u128/min_fail.leo index a8d41c475a..df2390c576 100644 --- a/compiler/tests/integers/u128/min_fail.leo +++ b/compiler/tests/integers/u128/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = -1; + let a: u128 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u16/min.leo b/compiler/tests/integers/u16/min.leo index 0f1c080938..ab1bd7db48 100644 --- a/compiler/tests/integers/u16/min.leo +++ b/compiler/tests/integers/u16/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 0; + let a: u16 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u16/min_fail.leo b/compiler/tests/integers/u16/min_fail.leo index a8d41c475a..99b7310362 100644 --- a/compiler/tests/integers/u16/min_fail.leo +++ b/compiler/tests/integers/u16/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = -1; + let a: u16 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u64/min.leo b/compiler/tests/integers/u64/min.leo index 0f1c080938..aa9b72fc8a 100644 --- a/compiler/tests/integers/u64/min.leo +++ b/compiler/tests/integers/u64/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 0; + let a: u64 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u64/min_fail.leo b/compiler/tests/integers/u64/min_fail.leo index a8d41c475a..81b90cc74a 100644 --- a/compiler/tests/integers/u64/min_fail.leo +++ b/compiler/tests/integers/u64/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = -1; + let a: u64 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u8/min.leo b/compiler/tests/integers/u8/min.leo index 0f1c080938..a88e33c5a6 100644 --- a/compiler/tests/integers/u8/min.leo +++ b/compiler/tests/integers/u8/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 0; + let a: u8 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u8/min_fail.leo b/compiler/tests/integers/u8/min_fail.leo index a8d41c475a..7b91dc6e1a 100644 --- a/compiler/tests/integers/u8/min_fail.leo +++ b/compiler/tests/integers/u8/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = -1; + let a: u8 = -1; } \ No newline at end of file