mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-18 15:31:32 +03:00
fix int tests
This commit is contained in:
parent
2f983180b7
commit
63342e7b10
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(x: i128) -> i128 {
|
||||
return x
|
||||
function main(a: i128, b: i128) {
|
||||
assert_eq!(a, b);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i128 {
|
||||
return 170141183460469231731687303715884105727
|
||||
function main() {
|
||||
let a: i128 = 170141183460469231731687303715884105727;
|
||||
}
|
3
compiler/tests/integers/i128/max_fail.leo
Normal file
3
compiler/tests/integers/i128/max_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i128 = 170141183460469231731687303715884105728;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i128 {
|
||||
return -170141183460469231731687303715884105728
|
||||
function main() {
|
||||
let a: i128 = -170141183460469231731687303715884105728;
|
||||
}
|
3
compiler/tests/integers/i128/min_fail.leo
Normal file
3
compiler/tests/integers/i128/min_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i128 = -170141183460469231731687303715884105729;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i128 {
|
||||
return 1
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i128 {
|
||||
return 0
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(x: i16) -> i16 {
|
||||
return x
|
||||
function main(a: i16, b: i16) {
|
||||
assert_eq!(a, b);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i16 {
|
||||
return 32767
|
||||
function main() {
|
||||
let a: i16 = 32767;
|
||||
}
|
3
compiler/tests/integers/i16/max_fail.leo
Normal file
3
compiler/tests/integers/i16/max_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i16 = 32768;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i16 {
|
||||
return -32768
|
||||
function main() {
|
||||
let a: i16 = -32768;
|
||||
}
|
3
compiler/tests/integers/i16/min_fail.leo
Normal file
3
compiler/tests/integers/i16/min_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i16 = -32769;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i16 {
|
||||
return 1
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i16 {
|
||||
return 0
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(x: i32) -> i32 {
|
||||
return x
|
||||
function main(a: i32, b: i32) {
|
||||
assert_eq!(a, b);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i32 {
|
||||
return 2147483647
|
||||
function main() {
|
||||
let a: i32 = 2147483647;
|
||||
}
|
3
compiler/tests/integers/i32/max_fail.leo
Normal file
3
compiler/tests/integers/i32/max_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i32 = 2147483648;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i32 {
|
||||
return -2147483648
|
||||
function main() {
|
||||
let a: i32 = -2147483648;
|
||||
}
|
3
compiler/tests/integers/i32/min_fail.leo
Normal file
3
compiler/tests/integers/i32/min_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i32 = -2147483649;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i32 {
|
||||
return 1
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i32 {
|
||||
return 0
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(x: i64) -> i64 {
|
||||
return x
|
||||
function main(a: i64, b: i64) {
|
||||
assert_eq!(a, b);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i64 {
|
||||
return 9223372036854775807
|
||||
function main() {
|
||||
let a: i64 = 9223372036854775807;
|
||||
}
|
3
compiler/tests/integers/i64/max_fail.leo
Normal file
3
compiler/tests/integers/i64/max_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i64 = 9223372036854775808;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i64 {
|
||||
return -9223372036854775808
|
||||
function main() {
|
||||
let a: i64 = -9223372036854775808;
|
||||
}
|
3
compiler/tests/integers/i64/min_fail.leo
Normal file
3
compiler/tests/integers/i64/min_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i64 = -9223372036854775809;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i64 {
|
||||
return 1
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i64 {
|
||||
return 0
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(x: i8) -> i8 {
|
||||
return x
|
||||
function main(a: i8, b: i8) {
|
||||
assert_eq!(a, b);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i8 {
|
||||
return 127
|
||||
function main() {
|
||||
let a: i8 = 127;
|
||||
}
|
3
compiler/tests/integers/i8/max_fail.leo
Normal file
3
compiler/tests/integers/i8/max_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i8 = 128;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() -> i8 {
|
||||
return -128
|
||||
function main() {
|
||||
let a: i8 = -128;
|
||||
}
|
3
compiler/tests/integers/i8/min_fail.leo
Normal file
3
compiler/tests/integers/i8/min_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: i8 = -129;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i8 {
|
||||
return 1
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> i8 {
|
||||
return 0
|
||||
}
|
@ -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::<Fq>::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::<Fq>::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::<Fq>::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::<Fq>::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::<Fq>::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::<Fq>::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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u32 = 0;
|
||||
let a: u128 = 0;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main() {
|
||||
let a: u32 = -1;
|
||||
let a: u128 = -1;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user