2020-06-06 00:09:12 +03:00
|
|
|
use crate::{
|
2020-06-06 01:34:06 +03:00
|
|
|
boolean::{output_expected_boolean, output_false, output_true},
|
2020-06-14 03:43:59 +03:00
|
|
|
get_error,
|
2020-06-08 09:30:39 +03:00
|
|
|
get_output,
|
2020-06-21 01:24:46 +03:00
|
|
|
integers::{fail_integer, IntegerTester},
|
2020-06-09 05:13:47 +03:00
|
|
|
parse_program,
|
2020-06-08 09:30:39 +03:00
|
|
|
EdwardsConstrainedValue,
|
|
|
|
EdwardsTestCompiler,
|
2020-06-06 00:09:12 +03:00
|
|
|
};
|
2020-06-26 00:27:19 +03:00
|
|
|
use leo_compiler::{ConstrainedValue, Integer};
|
2020-06-11 03:53:38 +03:00
|
|
|
use leo_inputs::types::{IntegerType, U32Type};
|
2020-06-26 00:27:19 +03:00
|
|
|
use leo_types::InputValue;
|
2020-05-20 01:45:40 +03:00
|
|
|
|
2020-06-06 00:09:12 +03:00
|
|
|
use snarkos_curves::edwards_bls12::Fq;
|
2020-06-08 09:30:39 +03:00
|
|
|
use snarkos_models::gadgets::{
|
|
|
|
r1cs::TestConstraintSystem,
|
|
|
|
utilities::{alloc::AllocGadget, uint::UInt32},
|
|
|
|
};
|
2020-05-20 01:45:40 +03:00
|
|
|
|
2020-06-06 00:09:12 +03:00
|
|
|
fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt32) {
|
|
|
|
let output = get_output(program);
|
|
|
|
|
|
|
|
match output {
|
|
|
|
EdwardsConstrainedValue::Return(vec) => match vec.as_slice() {
|
|
|
|
[ConstrainedValue::Integer(Integer::U32(actual))] => assert_eq!(*actual, expected),
|
|
|
|
_ => panic!("program output unknown return value"),
|
|
|
|
},
|
|
|
|
_ => panic!("program output unknown return value"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-13 12:04:31 +03:00
|
|
|
pub(crate) fn output_number(program: EdwardsTestCompiler, number: u32) {
|
2020-05-20 01:45:40 +03:00
|
|
|
let output = get_output(program);
|
|
|
|
assert_eq!(
|
2020-06-13 12:04:31 +03:00
|
|
|
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Integer(Integer::U32(UInt32::constant(number)))])
|
2020-06-08 09:30:39 +03:00
|
|
|
.to_string(),
|
2020-05-30 03:34:31 +03:00
|
|
|
output.to_string()
|
2020-05-20 01:45:40 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-13 12:04:31 +03:00
|
|
|
pub(crate) fn output_zero(program: EdwardsTestCompiler) {
|
|
|
|
output_number(program, 0u32);
|
|
|
|
}
|
|
|
|
|
2020-05-30 03:34:31 +03:00
|
|
|
pub(crate) fn output_one(program: EdwardsTestCompiler) {
|
2020-06-13 12:04:31 +03:00
|
|
|
output_number(program, 1u32);
|
2020-05-20 01:45:40 +03:00
|
|
|
}
|
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
#[test]
|
|
|
|
fn test_u32() {
|
2020-06-11 03:53:38 +03:00
|
|
|
test_uint!(TestU32, u32, IntegerType::U32Type(U32Type {}), UInt32);
|
2020-06-09 05:13:47 +03:00
|
|
|
|
|
|
|
TestU32::test_min(std::u32::MIN);
|
|
|
|
TestU32::test_max(std::u32::MAX);
|
|
|
|
|
|
|
|
TestU32::test_input();
|
|
|
|
|
|
|
|
TestU32::test_add();
|
|
|
|
// TestU32::test_sub(); //Todo: Catch subtraction overflow error in gadget
|
|
|
|
TestU32::test_mul();
|
|
|
|
TestU32::test_div();
|
|
|
|
TestU32::test_pow(); // takes about 2 mins
|
|
|
|
|
|
|
|
TestU32::test_eq();
|
|
|
|
TestU32::test_ge();
|
|
|
|
TestU32::test_gt();
|
|
|
|
TestU32::test_le();
|
|
|
|
TestU32::test_gt();
|
|
|
|
|
|
|
|
TestU32::test_assert_eq();
|
|
|
|
TestU32::test_ternary();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_zero() {
|
|
|
|
let bytes = include_bytes!("zero.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
output_zero(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_one() {
|
|
|
|
let bytes = include_bytes!("one.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
output_one(program);
|
|
|
|
}
|