2020-08-18 13:50:26 +03:00
|
|
|
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
|
|
|
// 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-07-30 21:11:54 +03:00
|
|
|
use crate::{assert_satisfied, expect_compiler_error, parse_program, EdwardsTestCompiler};
|
|
|
|
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError};
|
|
|
|
|
2020-07-03 23:35:46 +03:00
|
|
|
fn expect_fail(program: EdwardsTestCompiler) {
|
2020-07-30 21:11:54 +03:00
|
|
|
match expect_compiler_error(program) {
|
2020-06-08 09:30:39 +03:00
|
|
|
CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
|
2020-06-20 09:02:58 +03:00
|
|
|
ExpressionError::Error(_string),
|
2020-06-08 09:30:39 +03:00
|
|
|
))) => {}
|
2020-05-20 07:59:00 +03:00
|
|
|
error => panic!("Expected invalid circuit member error, got {}", error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expressions
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inline() {
|
2020-06-09 04:12:40 +03:00
|
|
|
let bytes = include_bytes!("inline.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
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-06-09 04:12:40 +03:00
|
|
|
let bytes = include_bytes!("inline_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
expect_fail(program);
|
2020-05-20 07:59:00 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 22:45:40 +03:00
|
|
|
#[test]
|
|
|
|
fn test_inline_undefined() {
|
2020-06-09 04:12:40 +03:00
|
|
|
let bytes = include_bytes!("inline_undefined.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
expect_fail(program);
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 07:59:00 +03:00
|
|
|
// Members
|
|
|
|
|
2020-05-20 22:45:40 +03:00
|
|
|
#[test]
|
2020-09-03 00:15:30 +03:00
|
|
|
fn test_member_variable() {
|
|
|
|
let bytes = include_bytes!("member_variable.leo");
|
2020-06-09 04:12:40 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-09-03 00:15:30 +03:00
|
|
|
fn test_member_variable_fail() {
|
|
|
|
let bytes = include_bytes!("member_variable_fail.leo");
|
2020-06-09 04:12:40 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-03 23:35:46 +03:00
|
|
|
expect_fail(program);
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
|
2020-06-20 11:40:56 +03:00
|
|
|
#[test]
|
2020-09-03 00:15:30 +03:00
|
|
|
fn test_member_variable_and_function() {
|
|
|
|
let bytes = include_bytes!("member_variable_and_function.leo");
|
2020-06-20 11:40:56 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
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-06-09 04:12:40 +03:00
|
|
|
let bytes = include_bytes!("member_function.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 07:59:00 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 22:45:40 +03:00
|
|
|
#[test]
|
|
|
|
fn test_member_function_fail() {
|
2020-06-09 04:12:40 +03:00
|
|
|
let bytes = include_bytes!("member_function_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-03 23:35:46 +03:00
|
|
|
expect_fail(program);
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_member_function_invalid() {
|
2020-06-09 04:12:40 +03:00
|
|
|
let bytes = include_bytes!("member_function_invalid.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-03 23:35:46 +03:00
|
|
|
expect_fail(program);
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
|
2020-07-04 08:44:09 +03:00
|
|
|
#[test]
|
|
|
|
fn test_member_function_nested() {
|
|
|
|
let bytes = include_bytes!("member_function_nested.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
assert_satisfied(program);
|
2020-07-04 08:44:09 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 07:59:00 +03:00
|
|
|
#[test]
|
|
|
|
fn test_member_static_function() {
|
2020-06-09 04:12:40 +03:00
|
|
|
let bytes = include_bytes!("member_static_function.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 07:59:00 +03:00
|
|
|
}
|
2020-05-20 22:45:40 +03:00
|
|
|
|
|
|
|
#[test]
|
2020-07-30 21:11:54 +03:00
|
|
|
fn test_member_static_function_invalid() {
|
|
|
|
let bytes = include_bytes!("member_static_function_invalid.leo");
|
2020-06-09 04:12:40 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-03 23:35:46 +03:00
|
|
|
expect_fail(program)
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
2020-06-09 04:12:40 +03:00
|
|
|
|
2020-05-20 22:45:40 +03:00
|
|
|
#[test]
|
2020-07-30 21:11:54 +03:00
|
|
|
fn test_member_static_function_undefined() {
|
|
|
|
let bytes = include_bytes!("member_static_function_undefined.leo");
|
2020-06-09 04:12:40 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-03 23:35:46 +03:00
|
|
|
expect_fail(program)
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
|
2020-09-07 23:47:50 +03:00
|
|
|
// Mutability
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_function_fail() {
|
|
|
|
let bytes = include_bytes!("mut_function_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
expect_compiler_error(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_self_variable() {
|
|
|
|
let bytes = include_bytes!("mut_self_variable.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
assert_satisfied(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_self_variable_fail() {
|
|
|
|
let bytes = include_bytes!("mut_self_variable_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
expect_compiler_error(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_self_function_fail() {
|
|
|
|
let bytes = include_bytes!("mut_self_function_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
expect_compiler_error(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_self_static_function_fail() {
|
|
|
|
let bytes = include_bytes!("mut_self_static_function_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
expect_compiler_error(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_static_function_fail() {
|
|
|
|
let bytes = include_bytes!("mut_static_function_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
expect_compiler_error(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_variable() {
|
|
|
|
let bytes = include_bytes!("mut_variable.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
assert_satisfied(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mutate_variable_fail() {
|
|
|
|
let bytes = include_bytes!("mut_variable_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
|
|
|
expect_compiler_error(program);
|
|
|
|
}
|
|
|
|
|
2020-05-20 22:45:40 +03:00
|
|
|
// Self
|
|
|
|
#[test]
|
2020-07-30 21:11:54 +03:00
|
|
|
fn test_self_member_pass() {
|
2020-07-03 23:35:46 +03:00
|
|
|
let bytes = include_bytes!("self_member.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
assert_satisfied(program);
|
2020-07-03 23:35:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-30 21:11:54 +03:00
|
|
|
fn test_self_member_invalid() {
|
|
|
|
let bytes = include_bytes!("self_member_invalid.leo");
|
2020-07-03 23:35:46 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
let _err = expect_compiler_error(program);
|
2020-07-03 23:35:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-30 21:11:54 +03:00
|
|
|
fn test_self_member_undefined() {
|
|
|
|
let bytes = include_bytes!("self_member_undefined.leo");
|
2020-07-03 23:35:46 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
let _err = expect_compiler_error(program);
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// All
|
|
|
|
|
2020-06-23 04:28:30 +03:00
|
|
|
#[test]
|
|
|
|
fn test_pedersen_mock() {
|
|
|
|
let bytes = include_bytes!("pedersen_mock.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
assert_satisfied(program);
|
2020-06-23 04:28:30 +03:00
|
|
|
}
|