program state

This commit is contained in:
damirka 2021-05-05 17:48:33 +03:00
parent 72648c993c
commit 032341089b
72 changed files with 211 additions and 153 deletions

View File

@ -1,2 +1,5 @@
[main]
x: [i16; 1] = [0i16; 1];
[registers]
r0: bool = true;

View File

@ -4,7 +4,6 @@ expectation: Pass
input_file: input/main_array.in
*/
function main(x: [i16; 1]) {
console.log("{}", x);
console.assert(x[0] == 0);
function main(x: [i16; 1]) -> bool{
return x[0] == 0;
}

View File

@ -1,2 +1,5 @@
[constants]
x: [i16; 1] = [0i16; 1];
[registers]
r0: bool = true;

View File

@ -4,7 +4,7 @@ expectation: Pass
input_file: input/main_array.in
*/
function main(const x: [i16; 1]) {
function main(const x: [i16; 1]) -> bool {
console.log("{}", x);
console.assert(x[0] == 0);
return x[0] == 0;
}

View File

@ -1,53 +0,0 @@
// Copyright (C) 2019-2021 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/>.
use crate::{expect_compiler_error, get_output, parse_program_with_input};
#[test]
fn test_registers_pass() {
let program_string = include_str!("registers_pass.leo");
let input_string = include_str!("input/main.in");
let expected = include_bytes!("output/registers_pass.out");
let program = parse_program_with_input(program_string, input_string).unwrap();
let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice()));
}
#[test]
fn test_registers_fail() {
let program_string = include_str!("registers_fail.leo");
let input_string = include_str!("input/main.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_registers_array() {
let program_string = include_str!("registers_array.leo");
let input_string = include_str!("input/array.in");
let expected = include_bytes!("output/registers_array.out");
let program = parse_program_with_input(program_string, input_string).unwrap();
let actual = get_output(program);
assert!(expected.eq(actual.bytes().as_slice()));
}

View File

@ -1,2 +0,0 @@
[registers]
r2: [[u8; 4]; 2] = [[1, 2, 3, 4], [5, 6, 7, 8]];

View File

@ -1,2 +0,0 @@
[registers]
r: u8 = 1;

View File

@ -1,3 +1,9 @@
/*
namespace: Compile
expectation: Pass
input_file: input/array.in
*/
function main () -> [[u8; 4]; 2] {
return [[1u8, 2u8, 3u8, 4u8], [5u8, 6u8, 7u8, 8u8]];
}

View File

@ -1,3 +1,9 @@
/*
namespace: Compile
expectation: Fail
input_file: input/main.in
*/
function main() -> bool {
return false;
}

View File

@ -1,3 +1,9 @@
/*
namespace: Compile
expectation: Pass
input_file: input/main.in
*/
function main() -> u8 {
return 1u8;
}

View File

@ -1,8 +1,13 @@
function main() {
console.assert(input.state.root == [0u8; 32]);
/*
namespace: Compile
expectation: Pass
state_file: input/token_withdraw.state
input_file: input/dummy.in
*/
function main() -> bool {
const expected: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
//console.assert(input.record.owner, expected);
console.assert(input.state_leaf.network_id == 0u8);
return input.state.root == [0u8; 32]
&& input.state_leaf.network_id == 0u8;
}

View File

@ -1,3 +1,10 @@
function main() {
console.assert(input.state.root == [0u8; 32]);
/*
namespace: Compile
expectation: Pass
state_file: input/token_withdraw.state
input_file: input/dummy.in
*/
function main() -> bool {
return input.state.root == [0u8; 32];
}

View File

@ -0,0 +1,10 @@
/*
namespace: Compile
expectation: Pass
state_file: input/basic.state
input_file: input/dummy.in
*/
function main() -> bool {
return true;
}

View File

@ -0,0 +1,2 @@
[registers]
r0: bool = false;

View File

@ -1,78 +0,0 @@
// Copyright (C) 2019-2021 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/>.
use crate::{assert_satisfied, parse_program_with_state, parse_state};
#[test]
fn test_basic() {
let state_string = include_str!("input/basic.state");
parse_state(state_string).unwrap();
}
#[test]
fn test_token_withdraw() {
let state_string = include_str!("input/token_withdraw.state");
parse_state(state_string).unwrap();
}
#[test]
fn test_access_state() {
let program_string = include_str!("access_state.leo");
let state_string = include_str!("input/token_withdraw.state");
let program = parse_program_with_state(program_string, state_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_access_all() {
let program_string = include_str!("access_all.leo");
let state_string = include_str!("input/token_withdraw.state");
let program = parse_program_with_state(program_string, state_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_visibility_fail() {
let state_string = include_str!("input/visibility_fail.state");
let is_err = parse_state(state_string).is_err();
assert!(is_err);
}
#[test]
fn test_section_undefined() {
let state_string = include_str!("input/section_undefined.state");
let is_err = parse_state(state_string).is_err();
assert!(is_err);
}
#[test]
fn test_section_invalid() {
let state_string = include_str!("input/section_invalid.state");
let is_err = parse_state(state_string).is_err();
assert!(is_err);
}

View File

@ -0,0 +1,10 @@
/*
namespace: Compile
expectation: Fail
state_file: input/section_invalid.state
input_file: input/dummy.in
*/
function main() -> bool {
return true;
}

View File

@ -0,0 +1,10 @@
/*
namespace: Compile
expectation: Fail
state_file: input/section_undefined.state
input_file: input/dummy.in
*/
function main() -> bool {
return true;
}

View File

@ -0,0 +1,10 @@
/*
namespace: Compile
expectation: Fail
state_file: input/visibility_fail.state
input_file: input/dummy.in
*/
function main() -> bool {
return true;
}

View File

@ -12,4 +12,7 @@ outputs:
output:
- input_file: input/main_array.in
output:
registers: {}
registers:
r0:
type: bool
value: "true"

View File

@ -12,4 +12,7 @@ outputs:
output:
- input_file: input/main_array.in
output:
registers: {}
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 0
num_constraints: 0
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
output:
- input_file: input/array.in
output:
registers:
r2:
type: "[[u8; 4]; 2]"
value: "[[1, 2, 3, 4], [5, 6, 7, 8]]"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:3:1\n |\n 3 | function main() -> bool {\n 4 | ...\n 5 | }\n | ^\n |\n = Mismatched types. Expected register output type `u8`, found type `bool`."

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 0
num_constraints: 0
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
output:
- input_file: input/main.in
output:
registers:
r:
type: u8
value: "1"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 527
num_constraints: 527
at: 7f6c7713392a44fa83a3fbffafd830d6e20356d72aff3d67f78c70ea5439a735
bt: b21f2049f4ae8c11dff5de8b33d532f3ea7637bfdbd09395d056495472c1853a
ct: 096693f8f4f40acd0e3f82bd256738e157f33989bcc68a7b8eabe44e8449bbb0
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 511
num_constraints: 511
at: bb121a0b56bee9895a337644cf8ece2f09dcf9113cd75c29f9bf26d635ba6d22
bt: 4a54bb6ffc0c9de1f8f349449b9071745f3db6985adb9b1d657e8aaa4309cc41
ct: a0736e8c8f3bb1c39a147348754e53dfd31fd76a1df9cd9960472841bcc531df
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 0
num_constraints: 0
at: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
bt: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
ct: 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- aborting due to syntax error

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- aborting due to syntax error

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- aborting due to syntax error