leo/compiler/tests/address/mod.rs

124 lines
3.1 KiB
Rust
Raw Normal View History

2020-08-01 05:39:30 +03:00
use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program};
2020-08-03 06:56:22 +03:00
use leo_typed::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_prefix() {
let bytes = include_bytes!("invalid_prefix.leo");
let syntax_error = parse_program(bytes).is_err();
assert!(syntax_error);
}
2020-07-06 14:59:06 +03:00
#[test]
fn test_invalid_length() {
let bytes = include_bytes!("invalid_length.leo");
let syntax_error = parse_program(bytes).is_err();
assert!(syntax_error);
2020-07-06 14:59:06 +03:00
}
2020-08-03 22:01:09 +03:00
#[test]
fn test_empty() {
let bytes = include_bytes!("empty.leo");
let syntax_error = parse_program(bytes).is_err();
assert!(syntax_error);
}
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 21:11:54 +03:00
let _output = expect_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 21:11:54 +03:00
let _output = expect_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-08-01 06:59:50 +03:00
let main_input = generate_main_input(vec![
2020-07-30 10:15:14 +03:00
("s", Some(InputValue::Boolean(true))),
("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
]);
2020-07-06 16:17:08 +03:00
2020-08-01 06:59:50 +03:00
program.set_main_input(main_input);
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-08-01 06:59:50 +03:00
let main_input = generate_main_input(vec![
2020-07-30 10:15:14 +03:00
("s", Some(InputValue::Boolean(false))),
("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
]);
2020-08-01 06:59:50 +03:00
program.set_main_input(main_input);
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-08-01 06:59:50 +03:00
let main_input = generate_main_input(vec![
2020-07-30 10:15:14 +03:00
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("c", Some(InputValue::Boolean(true))),
]);
2020-08-01 06:59:50 +03:00
program.set_main_input(main_input);
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-08-01 06:59:50 +03:00
let main_input = generate_main_input(vec![
2020-07-30 10:15:14 +03:00
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
("c", Some(InputValue::Boolean(false))),
]);
2020-08-01 06:59:50 +03:00
program.set_main_input(main_input);
2020-07-30 10:15:14 +03:00
assert_satisfied(program);
}