leo/compiler/tests/circuits/mod.rs

286 lines
7.2 KiB
Rust
Raw Normal View History

2021-02-02 07:26:56 +03:00
// Copyright (C) 2019-2021 Aleo Systems Inc.
2020-08-18 13:50:26 +03:00
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
2020-12-17 00:02:31 +03:00
use crate::{assert_satisfied, expect_asg_error, parse_program};
2020-07-30 21:11:54 +03:00
2020-05-20 07:59:00 +03:00
// Expressions
#[test]
fn test_inline() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("inline.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 04:12:40 +03:00
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
2020-05-20 07:59:00 +03:00
}
#[test]
fn test_inline_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("inline_fail.leo");
2020-12-17 00:02:31 +03:00
let error = parse_program(program_string).err().unwrap();
2020-06-09 04:12:40 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-05-20 07:59:00 +03:00
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_inline_undefined() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("inline_undefined.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
2020-05-20 07:59:00 +03:00
// Members
#[test]
fn test_member_variable() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_variable.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 04:12:40 +03:00
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_member_variable_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_variable_fail.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
2020-06-20 11:40:56 +03:00
#[test]
fn test_member_variable_and_function() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_variable_and_function.leo");
let program = parse_program(program_string).unwrap();
2020-06-20 11:40:56 +03:00
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
2020-06-20 11:40:56 +03:00
}
2020-05-20 07:59:00 +03:00
#[test]
fn test_member_function() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_function.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 04:12:40 +03:00
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
2020-05-20 07:59:00 +03:00
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_member_function_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_function_fail.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
#[test]
fn test_member_function_invalid() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_function_invalid.leo");
let error = parse_program(program_string).err().unwrap();
2020-06-09 04:12:40 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
#[test]
fn test_member_function_nested() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_function_nested.leo");
let program = parse_program(program_string).unwrap();
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
}
2020-05-20 07:59:00 +03:00
#[test]
fn test_member_static_function() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_static_function.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 04:12:40 +03:00
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
2020-05-20 07:59:00 +03:00
}
2020-09-08 07:56:39 +03:00
#[test]
fn test_member_static_function_nested() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_static_function_nested.leo");
let program = parse_program(program_string).unwrap();
2020-09-08 07:56:39 +03:00
assert_satisfied(program);
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_member_static_function_invalid() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_static_function_invalid.leo");
let error = parse_program(program_string).err().unwrap();
2020-06-09 04:12:40 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error)
2020-11-12 21:28:24 +03:00
}
#[test]
fn test_member_static_function_undefined() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("member_static_function_undefined.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error)
2020-11-12 21:28:24 +03:00
}
// Mutability
2020-11-12 21:28:24 +03:00
#[test]
fn test_mutate_function_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_function_fail.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
#[test]
fn test_mutate_self_variable() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_self_variable.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
2020-12-17 00:02:31 +03:00
#[test]
fn test_mutate_self_variable_branch() {
let program_string = include_str!("mut_self_variable_branch.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_mutate_self_variable_conditional() {
let program_string = include_str!("mut_self_variable_conditional.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_mutate_self_variable_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_self_variable_fail.leo");
2020-12-17 00:02:31 +03:00
let error = parse_program(program_string).err().unwrap();
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_mutate_self_function_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_self_function_fail.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
#[test]
fn test_mutate_self_static_function_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_self_static_function_fail.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_mutate_static_function_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_static_function_fail.leo");
let error = parse_program(program_string).err().unwrap();
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
#[test]
fn test_mutate_variable() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_variable.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_mutate_variable_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("mut_variable_fail.leo");
2020-12-17 00:02:31 +03:00
let error = parse_program(program_string).err().unwrap();
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
}
// Self
2020-11-12 21:28:24 +03:00
#[test]
fn test_self_fail() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("self_fail.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
#[test]
2020-07-30 21:11:54 +03:00
fn test_self_member_pass() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("self_member.leo");
let program = parse_program(program_string).unwrap();
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
}
#[test]
2020-07-30 21:11:54 +03:00
fn test_self_member_invalid() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("self_member_invalid.leo");
2020-12-08 04:05:15 +03:00
let error = parse_program(program_string).err().unwrap();
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_self_member_undefined() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("self_member_undefined.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
2021-02-05 00:18:28 +03:00
// Inline circuit member
#[test]
fn test_inline_member_pass() {
let program_string = include_str!("inline_member_pass.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_inline_member_fail() {
let program_string = include_str!("inline_member_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
// All
2020-06-23 04:28:30 +03:00
#[test]
fn test_pedersen_mock() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("pedersen_mock.leo");
let program = parse_program(program_string).unwrap();
2020-06-23 04:28:30 +03:00
2020-07-30 21:11:54 +03:00
assert_satisfied(program);
2020-06-23 04:28:30 +03:00
}
#[test]
fn test_define_circuit_inside_circuit_function() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("define_circuit_inside_circuit_function.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}