2020-06-21 01:24:46 +03:00
|
|
|
use crate::{
|
|
|
|
get_error,
|
|
|
|
get_output,
|
|
|
|
integers::fail_integer,
|
|
|
|
parse_program,
|
|
|
|
EdwardsConstrainedValue,
|
|
|
|
EdwardsTestCompiler,
|
|
|
|
};
|
2020-05-20 03:08:38 +03:00
|
|
|
use leo_compiler::{
|
2020-06-08 07:26:49 +03:00
|
|
|
errors::{CompilerError, FunctionError},
|
|
|
|
ConstrainedValue,
|
2020-06-26 00:27:19 +03:00
|
|
|
Integer,
|
2020-05-20 03:08:38 +03:00
|
|
|
};
|
2020-06-20 09:02:58 +03:00
|
|
|
use leo_inputs::types::{IntegerType, U32Type};
|
2020-06-26 00:27:19 +03:00
|
|
|
use leo_types::InputValue;
|
2020-06-02 04:35:43 +03:00
|
|
|
|
2020-06-04 23:35:12 +03:00
|
|
|
use snarkos_models::gadgets::utilities::uint::UInt32;
|
2020-05-20 03:08:38 +03:00
|
|
|
|
|
|
|
// [1, 1, 1]
|
2020-05-30 03:34:31 +03:00
|
|
|
fn output_ones(program: EdwardsTestCompiler) {
|
2020-05-20 03:08:38 +03:00
|
|
|
let output = get_output(program);
|
|
|
|
assert_eq!(
|
2020-06-08 09:30:39 +03:00
|
|
|
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Array(vec![
|
|
|
|
ConstrainedValue::Integer(
|
|
|
|
Integer::U32(UInt32::constant(1u32))
|
|
|
|
);
|
|
|
|
3
|
|
|
|
])])
|
2020-05-30 03:34:31 +03:00
|
|
|
.to_string(),
|
|
|
|
output.to_string()
|
2020-05-20 03:08:38 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// [[0, 0, 0],
|
|
|
|
// [0, 0, 0]]
|
2020-05-30 03:34:31 +03:00
|
|
|
fn output_multi(program: EdwardsTestCompiler) {
|
2020-05-20 03:08:38 +03:00
|
|
|
let output = get_output(program);
|
|
|
|
assert_eq!(
|
2020-05-30 03:34:31 +03:00
|
|
|
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Array(vec![
|
2020-05-30 01:55:57 +03:00
|
|
|
ConstrainedValue::Array(
|
|
|
|
vec![ConstrainedValue::Integer(Integer::U32(UInt32::constant(0u32))); 3]
|
|
|
|
);
|
|
|
|
2
|
2020-05-30 03:34:31 +03:00
|
|
|
])])
|
|
|
|
.to_string(),
|
|
|
|
output.to_string()
|
2020-05-20 03:08:38 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-30 03:34:31 +03:00
|
|
|
fn fail_array(program: EdwardsTestCompiler) {
|
2020-05-20 03:08:38 +03:00
|
|
|
match get_error(program) {
|
2020-06-20 09:02:58 +03:00
|
|
|
CompilerError::FunctionError(FunctionError::Error(_string)) => {}
|
2020-06-23 08:32:57 +03:00
|
|
|
error => panic!("Expected function error, found {}", error),
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 02:14:55 +03:00
|
|
|
pub(crate) fn input_value_u32_one() -> InputValue {
|
|
|
|
InputValue::Integer(IntegerType::U32Type(U32Type {}), 1)
|
|
|
|
}
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
// Expressions
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inline() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("inline.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
output_ones(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_initializer() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("initializer.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
output_ones(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_spread() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("spread.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
output_ones(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_slice() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("slice.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
output_ones(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multi() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("multi.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
output_multi(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_input_array() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("input.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-06-11 02:14:55 +03:00
|
|
|
program.set_inputs(vec![Some(InputValue::Array(vec![input_value_u32_one(); 3]))]);
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
output_ones(program)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_input_array_fail() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("input.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-06-11 02:14:55 +03:00
|
|
|
program.set_inputs(vec![Some(input_value_u32_one())]);
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
fail_array(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_input_field_none() {
|
2020-06-09 03:51:06 +03:00
|
|
|
let bytes = include_bytes!("input.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
program.set_inputs(vec![None]);
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-06-21 01:24:46 +03:00
|
|
|
fail_integer(program)
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|