leo/compiler/tests/address/mod.rs

108 lines
2.8 KiB
Rust
Raw Normal View History

2020-07-30 10:15:14 +03:00
use crate::{assert_satisfied, generate_main_inputs, get_compiler_error, parse_program};
2020-07-06 16:17:08 +03:00
use leo_types::InputValue;
2020-07-06 14:59:06 +03:00
static TEST_ADDRESS_1: &'static str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8";
static TEST_ADDRESS_2: &'static str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r";
2020-07-06 14:59:06 +03:00
#[test]
fn test_valid() {
let bytes = include_bytes!("valid.leo");
let program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
assert_satisfied(program)
2020-07-06 14:59:06 +03:00
}
#[test]
fn test_invalid() {
let bytes = include_bytes!("invalid.leo");
let program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
let _output = get_compiler_error(program);
2020-07-06 14:59:06 +03:00
}
#[test]
fn test_implicit_valid() {
let bytes = include_bytes!("implicit_valid.leo");
let program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
assert_satisfied(program);
2020-07-06 14:59:06 +03:00
}
#[test]
fn test_implicit_invalid() {
let bytes = include_bytes!("implicit_invalid.leo");
let program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
let _output = get_compiler_error(program);
2020-07-06 14:59:06 +03:00
}
#[test]
fn test_assert_eq_pass() {
let bytes = include_bytes!("assert_eq_pass.leo");
let program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
assert_satisfied(program);
2020-07-06 14:59:06 +03:00
}
#[test]
fn test_assert_eq_fail() {
let bytes = include_bytes!("assert_eq_fail.leo");
let program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
let _output = get_compiler_error(program);
2020-07-06 14:59:06 +03:00
}
2020-07-06 16:17:08 +03:00
#[test]
2020-07-30 10:15:14 +03:00
fn test_ternary() {
let bytes = include_bytes!("ternary.leo");
2020-07-06 16:17:08 +03:00
let mut program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
let main_inputs = generate_main_inputs(vec![
("s", Some(InputValue::Boolean(true))),
("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
]);
2020-07-06 16:17:08 +03:00
2020-07-30 10:15:14 +03:00
program.set_main_inputs(main_inputs);
2020-07-30 10:15:14 +03:00
assert_satisfied(program);
2020-07-30 10:15:14 +03:00
let mut program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
let main_inputs = generate_main_inputs(vec![
("s", Some(InputValue::Boolean(false))),
("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
]);
2020-07-30 10:15:14 +03:00
program.set_main_inputs(main_inputs);
2020-07-30 10:15:14 +03:00
assert_satisfied(program);
}
#[test]
fn test_equal() {
let bytes = include_bytes!("equal.leo");
2020-07-30 10:15:14 +03:00
let mut program = parse_program(bytes).unwrap();
2020-07-30 10:15:14 +03:00
let main_inputs = generate_main_inputs(vec![
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("c", Some(InputValue::Boolean(true))),
]);
2020-07-30 10:15:14 +03:00
program.set_main_inputs(main_inputs);
assert_satisfied(program);
2020-07-30 10:15:14 +03:00
let mut program = parse_program(bytes).unwrap();
let main_inputs = generate_main_inputs(vec![
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
("c", Some(InputValue::Boolean(false))),
]);
2020-07-30 10:15:14 +03:00
program.set_main_inputs(main_inputs);
assert_satisfied(program);
}