console + definition + core

This commit is contained in:
damirka 2021-05-03 16:47:33 +03:00
parent 534f36a077
commit 0b798dc950
77 changed files with 533 additions and 354 deletions

View File

@ -16,7 +16,14 @@
//! Compiles a Leo program from a file path. //! Compiles a Leo program from a file path.
use crate::{CompilerOptions, GroupType, Output, OutputFile, constraints::{generate_constraints, generate_test_constraints}, errors::CompilerError}; use crate::{
constraints::{generate_constraints, generate_test_constraints},
errors::CompilerError,
CompilerOptions,
GroupType,
Output,
OutputFile,
};
pub use leo_asg::{new_context, AsgContext as Context, AsgContext}; pub use leo_asg::{new_context, AsgContext as Context, AsgContext};
use leo_asg::{Asg, AsgPass, FormattedError, Program as AsgProgram}; use leo_asg::{Asg, AsgPass, FormattedError, Program as AsgProgram};
use leo_ast::{Input, MainInput, Program as AstProgram}; use leo_ast::{Input, MainInput, Program as AstProgram};
@ -322,7 +329,9 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<'
// Write results to file // Write results to file
let output_file = OutputFile::new(&package_name); let output_file = OutputFile::new(&package_name);
output_file.write(&output_directory, result.to_string().as_bytes()).unwrap(); output_file
.write(&output_directory, result.to_string().as_bytes())
.unwrap();
Ok(()) Ok(())
} }

View File

@ -121,7 +121,9 @@ pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType<F>>(
let output = result?; let output = result?;
let output_file = OutputFile::new(&output_file_name); let output_file = OutputFile::new(&output_file_name);
output_file.write(output_directory, output.to_string().as_bytes()).unwrap(); output_file
.write(output_directory, output.to_string().as_bytes())
.unwrap();
// increment passed tests // increment passed tests
passed += 1; passed += 1;

View File

@ -110,8 +110,6 @@ impl Output {
}); });
} }
Ok(Output { Ok(Output { registers })
registers,
})
} }
} }

View File

@ -14,18 +14,21 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use std::{path::{Path, PathBuf}}; use std::path::{Path, PathBuf};
use leo_asg::*; use leo_asg::*;
use leo_synthesizer::{CircuitSynthesizer, SerializedCircuit, SummarizedCircuit}; use leo_synthesizer::{CircuitSynthesizer, SerializedCircuit, SummarizedCircuit};
use leo_test_framework::{Test, runner::{Namespace, ParseType, Runner}}; use leo_test_framework::{
runner::{Namespace, ParseType, Runner},
Test,
};
use serde_yaml::Value; use serde_yaml::Value;
use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq}; use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq};
use crate::{ConstrainedValue, Output, compiler::Compiler, errors::CompilerError, targets::edwards_bls12::EdwardsGroupType}; use crate::{compiler::Compiler, errors::CompilerError, targets::edwards_bls12::EdwardsGroupType, Output};
pub type EdwardsTestCompiler = Compiler<'static, Fq, EdwardsGroupType>; pub type EdwardsTestCompiler = Compiler<'static, Fq, EdwardsGroupType>;
pub type EdwardsConstrainedValue = ConstrainedValue<'static, Fq, EdwardsGroupType>; // pub type EdwardsConstrainedValue = ConstrainedValue<'static, Fq, EdwardsGroupType>;
//convenience function for tests, leaks memory //convenience function for tests, leaks memory
pub(crate) fn make_test_context() -> AsgContext<'static> { pub(crate) fn make_test_context() -> AsgContext<'static> {
@ -74,17 +77,40 @@ impl Namespace for CompileNamespace {
// (name, content) // (name, content)
let mut inputs = vec![]; let mut inputs = vec![];
if let Some(input) = test.config.get("inputs") {
if let Value::Sequence(field) = input {
for map in field {
for (name, value) in map.as_mapping().unwrap().iter() {
// Try to parse string from 'inputs' map, else fail
let value = if let serde_yaml::Value::String(value) = value {
value
} else {
return Err("Expected string in 'inputs' map".to_string());
};
inputs.push((name.as_str().unwrap().to_string(), value.clone()));
}
}
}
}
if let Some(input) = test.config.get("input_file") { if let Some(input) = test.config.get("input_file") {
let input_file: PathBuf = test.path.parent().expect("no test parent dir").into(); let input_file: PathBuf = test.path.parent().expect("no test parent dir").into();
if let Some(name) = input.as_str() { if let Some(name) = input.as_str() {
let mut input_file = input_file; let mut input_file = input_file;
input_file.push(input.as_str().expect("input_file was not a string or array")); input_file.push(input.as_str().expect("input_file was not a string or array"));
inputs.push((name.to_string(), std::fs::read_to_string(&input_file).expect("failed to read test input file"))); inputs.push((
name.to_string(),
std::fs::read_to_string(&input_file).expect("failed to read test input file"),
));
} else if let Some(seq) = input.as_sequence() { } else if let Some(seq) = input.as_sequence() {
for name in seq { for name in seq {
let mut input_file = input_file.clone(); let mut input_file = input_file.clone();
input_file.push(name.as_str().expect("input_file was not a string")); input_file.push(name.as_str().expect("input_file was not a string"));
inputs.push((name.as_str().expect("input_file item was not a string").to_string(), std::fs::read_to_string(&input_file).expect("failed to read test input file"))); inputs.push((
name.as_str().expect("input_file item was not a string").to_string(),
std::fs::read_to_string(&input_file).expect("failed to read test input file"),
));
} }
} }
} }
@ -105,13 +131,19 @@ impl Namespace for CompileNamespace {
let mut last_circuit = None; let mut last_circuit = None;
for input in inputs { for input in inputs {
let mut parsed = parsed.clone(); let mut parsed = parsed.clone();
parsed.parse_input(&input.1, Path::new("input"), &state, Path::new("state")).map_err(|x| x.to_string())?; parsed
.parse_input(&input.1, Path::new("input"), &state, Path::new("state"))
.map_err(|x| x.to_string())?;
let mut cs: CircuitSynthesizer<Bls12_377> = Default::default(); let mut cs: CircuitSynthesizer<Bls12_377> = Default::default();
let output = parsed.compile_constraints(&mut cs).map_err(|x| x.to_string())?; let output = parsed.compile_constraints(&mut cs).map_err(|x| x.to_string())?;
let circuit: SummarizedCircuit = SerializedCircuit::from(cs).into(); let circuit: SummarizedCircuit = SerializedCircuit::from(cs).into();
if let Some(last_circuit) = last_circuit.as_ref() { if let Some(last_circuit) = last_circuit.as_ref() {
if last_circuit != &circuit { if last_circuit != &circuit {
eprintln!("{}\n{}", serde_yaml::to_string(last_circuit).unwrap(), serde_yaml::to_string(&circuit).unwrap()); eprintln!(
"{}\n{}",
serde_yaml::to_string(last_circuit).unwrap(),
serde_yaml::to_string(&circuit).unwrap()
);
return Err("circuit changed on different input files".to_string()); return Err("circuit changed on different input files".to_string());
} }
} else { } else {
@ -123,9 +155,6 @@ impl Namespace for CompileNamespace {
}); });
} }
let final_output = CompileOutput { let final_output = CompileOutput {
circuit: last_circuit.unwrap(), circuit: last_circuit.unwrap(),
output: output_items, output: output_items,

View File

@ -15,7 +15,10 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::{Expression, ExpressionStatement, Span, Statement, ValueExpression}; use leo_ast::{Expression, ExpressionStatement, Span, Statement, ValueExpression};
use leo_test_framework::{Test, runner::{Namespace, ParseType, Runner}}; use leo_test_framework::{
runner::{Namespace, ParseType, Runner},
Test,
};
use serde_yaml::Value; use serde_yaml::Value;
use tokenizer::Token; use tokenizer::Token;

View File

@ -1,3 +1,19 @@
// 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 serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
@ -11,7 +27,6 @@ pub struct SummarizedCircuit {
// pub public_variables: String, // pub public_variables: String,
// pub private_variables: String, // pub private_variables: String,
pub at: String, pub at: String,
pub bt: String, pub bt: String,
pub ct: String, pub ct: String,
@ -34,12 +49,9 @@ impl From<SerializedCircuit> for SummarizedCircuit {
// .expect("failed to serialize public_variables")), // .expect("failed to serialize public_variables")),
// private_variables: hash_field(&serde_json::to_string(&other.private_variables) // private_variables: hash_field(&serde_json::to_string(&other.private_variables)
// .expect("failed to serialize private_variables")), // .expect("failed to serialize private_variables")),
at: hash_field(&serde_json::to_string(&other.at) at: hash_field(&serde_json::to_string(&other.at).expect("failed to serialize at")),
.expect("failed to serialize at")), bt: hash_field(&serde_json::to_string(&other.bt).expect("failed to serialize bt")),
bt: hash_field(&serde_json::to_string(&other.bt) ct: hash_field(&serde_json::to_string(&other.ct).expect("failed to serialize ct")),
.expect("failed to serialize bt")),
ct: hash_field(&serde_json::to_string(&other.ct)
.expect("failed to serialize ct")),
} }
} }
} }

View File

@ -15,7 +15,10 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use serde_yaml::Value; use serde_yaml::Value;
use std::{collections::BTreeMap, path::{Path, PathBuf}}; use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};
use crate::{error::*, fetch::find_tests, output::TestExpectation, test::*}; use crate::{error::*, fetch::find_tests, output::TestExpectation, test::*};
@ -87,7 +90,7 @@ pub fn run_tests<T: Runner>(runner: &T, expectation_category: &str) {
.to_str() .to_str()
.unwrap() .unwrap()
.to_string(); .to_string();
expectation_name += ".out"; expectation_name += ".out";
expectation_path.push(&expectation_name); expectation_path.push(&expectation_name);
let test_name = relative_path let test_name = relative_path
@ -135,11 +138,7 @@ pub fn run_tests<T: Runner>(runner: &T, expectation_category: &str) {
let mut expected_output = expectations.as_ref().map(|x| x.outputs.iter()); let mut expected_output = expectations.as_ref().map(|x| x.outputs.iter());
for (i, test) in tests.into_iter().enumerate() { for (i, test) in tests.into_iter().enumerate() {
let expected_output = expected_output let expected_output = expected_output.as_mut().map(|x| x.next()).flatten().cloned();
.as_mut()
.map(|x| x.next())
.flatten()
.cloned();
let output = namespace.run_test(Test { let output = namespace.run_test(Test {
name: test_name.clone(), name: test_name.clone(),
content: test.clone(), content: test.clone(),

View File

@ -1,5 +1,3 @@
use std::collections::BTreeMap;
// Copyright (C) 2019-2021 Aleo Systems Inc. // Copyright (C) 2019-2021 Aleo Systems Inc.
// This file is part of the Leo library. // This file is part of the Leo library.
@ -16,6 +14,8 @@ use std::collections::BTreeMap;
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use std::collections::BTreeMap;
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug, Clone)] #[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug, Clone)]
pub enum TestExpectationMode { pub enum TestExpectationMode {
Pass, Pass,

View File

@ -2,8 +2,8 @@
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input_file:
- address1.in - inputs/address1.in
- address2.in - inputs/address2.in
*/ */
function main(x: address) -> bool { function main(x: address) -> bool {

View File

@ -2,8 +2,8 @@
namespace: Compile namespace: Compile
expectation: Pass expectation: Pass
input_file: input_file:
- address1.in - inputs/address1.in
- address2.in - inputs/address2.in
*/ */
function main(x: address) -> bool { function main(x: address) -> bool {

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
circuit Foo { circuit Foo {
a: u8, a: u8,

View File

@ -1,3 +1,16 @@
function main(a: bool) { /*
namespace: Compile
expectation: Pass
inputs:
- assert.in: |
[main]
a: bool = true;
[registers]
r0: bool = false;
*/
function main(a: bool) -> bool {
console.assert(a == true); console.assert(a == true);
return a == true;
} }

View File

@ -1,3 +1,15 @@
/*
namespace: Compile
expectation: Pass
inputs:
- cond.in: |
[main]
a: bool = true;
- cond_2.in: |
[main]
a: bool = false;
*/
function main(a: bool) { function main(a: bool) {
if a { if a {
console.assert(a == true); console.assert(a == true);

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Pass
*/
function main() { function main() {
console.debug("hello debug"); console.debug("hello debug");
} }

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Pass
*/
function main() { function main() {
console.error("hello error"); console.error("hello error");
} }

View File

@ -1,6 +1,14 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/input_unequal.in
- inputs/input_equal.in
*/
// Conditionally add two u32 integers and log the result to the console. // Conditionally add two u32 integers and log the result to the console.
function main(a: u32, b: u32) { function main(a: u32, b: u32) {
if a == b { if a == b {
console.log("{}=={}",a,b); // This line should not fail. console.log("{}=={}", a, b); // This line should not fail.
} }
} }

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
function main() { function main() {
console.log( hello ); console.log( hello );
} }

View File

@ -1,3 +1,12 @@
/*
namespace: Compile
expectation: Pass
inputs:
- log.in: |
[main]
a: bool = true;
*/
function main(a: bool) { function main(a: bool) {
console.log("a = {}", a); console.log("a = {}", a);
} }

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Pass
*/
function main() { function main() {
console.log("{}", 1u32); console.log("{}", 1u32);
} }

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
function main() { function main() {
console.log("{}"); console.log("{}");
} }

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
function main() { function main() {
console.log("", 1u32); console.log("", 1u32);
} }

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
function main() { function main() {
console.log("{}", a); console.log("{}", a);
} }

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Pass
*/
function main() { function main() {
console.log("{} {}", 1u32, true); console.log("{} {}", 1u32, true);
} }

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Fail
input_files:
- input/dummy.in
*/
import core.unstable.blake2s.BadCircuit; // `BadCircuit` is not included in the blake2s package
function main() -> bool {
return false;
}

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
import core.unstable.blake2s.BadCircuit; // `BadCircuit` is not included in the blake2s package import core.unstable.blake2s.BadCircuit; // `BadCircuit` is not included in the blake2s package
function main() {} function main() {}

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
import core.*; // You cannot import all dependencies from core at once import core.*; // You cannot import all dependencies from core at once
function main() {} function main() {}

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
import core.bad_circuit; // `bad_circuit` is not a core package import core.bad_circuit; // `bad_circuit` is not a core package
function main() {} function main() {}

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
import core.unstable.bad_circuit; // `bad_circuit` is not a core unstable package import core.unstable.bad_circuit; // `bad_circuit` is not a core unstable package
function main() {} function main() {}

View File

@ -1,59 +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/>.
pub mod packages;
use crate::{assert_satisfied, expect_asg_error, parse_program};
#[test]
fn test_core_circuit_invalid() {
let program_string = include_str!("core_package_invalid.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_core_circuit_star_fail() {
let program_string = include_str!("core_circuit_star_fail.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_core_package_invalid() {
let program_string = include_str!("core_package_invalid.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_core_unstable_package_invalid() {
let program_string = include_str!("core_unstable_package_invalid.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_unstable_blake2s_sanity() {
let program_string = include_str!("unstable_blake2s.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}

View File

@ -1,17 +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/>.
pub mod unstable;

View File

@ -1,17 +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/>.
pub mod blake2s;

View File

@ -1,10 +1,22 @@
/*
namespace: Compile
expectation: Pass
inputs:
- blake.in: |
[constants]
message: [u8; 32] = [0; 32];
[registers]
r0: [u8; 32] = [0; 32];
*/
import core.unstable.blake2s.Blake2s; import core.unstable.blake2s.Blake2s;
function main() { function main(const message: [u8; 32]) -> [u8; 32] {
const seed: [u8; 32] = [0; 32]; const seed: [u8; 32] = [1; 32];
const message: [u8; 32] = [0; 32];
const result = Blake2s::hash(seed, message); const result = Blake2s::hash(seed, message);
console.log("Result: {}", result); console.log("Result: {}", result);
return result;
} }

View File

@ -1,38 +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, import::set_local_dir, parse_program};
#[test]
fn test_out_of_order() {
let program_string = include_str!("out_of_order.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
#[ignore]
fn test_out_of_order_with_import() {
set_local_dir();
let program_string = include_str!("out_of_order_with_import.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Pass
*/
@test @test
function fake_test() {} function fake_test() {}

View File

@ -1,7 +1,14 @@
test function fake_test() {} /*
namespace: Compile
expectation: Pass
*/
@test
function fake_test() {}
function main() {} function main() {}
import test_import.foo; // use core import to test import order
import core.unstable.blake2s.Blake2s;
circuit Foo {} circuit Foo {}

View File

@ -1,3 +1,8 @@
/*
namespace: Compile
expectation: Fail
*/
// Variables are immutable by default. // Variables are immutable by default.
function main() { function main() {
const a = 1u32; const a = 1u32;

View File

@ -1,7 +1,12 @@
/*
namespace: Compile
expectation: Fail
*/
// Adding the `mut` keyword makes a variable mutable. // Adding the `mut` keyword makes a variable mutable.
function main() { function main() {
let a = 1u32; let a = 1u32;
a = 0; a = 0;
console.assert(a == 0u32); return a == 0u32;
} }

View File

@ -1,157 +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, expect_asg_error, generate_main_input, parse_program};
use leo_ast::InputValue;
#[test]
fn test_let() {
let program_string = include_str!("let.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_let_mut() {
let program_string = include_str!("let_mut.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_let_mut_nested() {
let program_string = include_str!("let_mut_nested.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_const_fail() {
let program_string = include_str!("const.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_cond_mut() {
let program_string = include_str!("cond_mut.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_array() {
let program_string = include_str!("array.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_array_mut() {
let program_string = include_str!("array_mut.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_array_tuple_mut() {
let bytes = include_str!("array_tuple_mut.leo");
let program = parse_program(bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_array_splice_mut() {
let bytes = include_str!("array_splice_mut.leo");
let program = parse_program(bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_circuit() {
let program_string = include_str!("circuit.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_circuit_mut() {
let program_string = include_str!("circuit_mut.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_circuit_variable_mut() {
let program_string = include_str!("circuit_variable_mut.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_circuit_function_mut() {
let program_string = include_str!("circuit_function_mut.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_circuit_static_function_mut() {
let program_string = include_str!("circuit_static_function_mut.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_function_input() {
let program_string = include_str!("function_input.leo");
let error = parse_program(program_string).err().unwrap();
expect_asg_error(error);
}
#[test]
fn test_function_input_mut() {
let program_string = include_str!("function_input_mut.leo");
let mut program = parse_program(program_string).unwrap();
let main_input = generate_main_input(vec![("a", Some(InputValue::Boolean(true)))]);
program.set_main_input(main_input);
assert_satisfied(program);
}
#[test]
fn test_swap() {
let program_string = include_str!("swap.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}

View File

@ -1,3 +1,15 @@
/*
namespace: Compile
expectation: Pass
inputs:
- swap.in: |
[main]
arr: [u32; 2] = [10, 8];
[registers]
r0: bool = false;
*/
// Swap two elements of an array. // Swap two elements of an array.
function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] {
const t = a[i]; const t = a[i];
@ -6,15 +18,10 @@ function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] {
return a; return a;
} }
function main() { function main(arr: [u32; 2]) -> bool {
let arr: [u32; 2] = [0, 1];
const expected: [u32; 2] = [1, 0]; const expected: [u32; 2] = [1, 0];
// Do swap.
const actual = swap(arr, 0, 1); const actual = swap(arr, 0, 1);
// Check result. // Do swap.
for i in 0..2 { return expected[0] == actual[0] && expected[1] == actual[1];
console.assert(expected[i] == actual[i]);
}
} }

View File

@ -10,13 +10,13 @@ outputs:
bt: 2194515882da93c79fa24d47c40fddc44f0284da25da7b89efb935c0ea7382f8 bt: 2194515882da93c79fa24d47c40fddc44f0284da25da7b89efb935c0ea7382f8
ct: a0736e8c8f3bb1c39a147348754e53dfd31fd76a1df9cd9960472841bcc531df ct: a0736e8c8f3bb1c39a147348754e53dfd31fd76a1df9cd9960472841bcc531df
output: output:
- input_file: address1.in - input_file: inputs/address1.in
output: output:
registers: registers:
a: a:
type: bool type: bool
value: "true" value: "true"
- input_file: address2.in - input_file: inputs/address2.in
output: output:
registers: registers:
a: a:

View File

@ -10,13 +10,13 @@ outputs:
bt: 15054154626f1ae748008fc4ed9a650c3873b608988ff31312fe4049957dfffb bt: 15054154626f1ae748008fc4ed9a650c3873b608988ff31312fe4049957dfffb
ct: dbda9de51fe9897456cbbcc3b450ed7d66185fb6018c7a0c72414784f29b2ad4 ct: dbda9de51fe9897456cbbcc3b450ed7d66185fb6018c7a0c72414784f29b2ad4
output: output:
- input_file: address1.in - input_file: inputs/address1.in
output: output:
registers: registers:
a: a:
type: bool type: bool
value: "false" value: "false"
- input_file: address2.in - input_file: inputs/address2.in
output: output:
registers: registers:
a: a:

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:7:9\n |\n 7 | self.a = new;\n | ^^^^^^^^^^^^\n |\n = illegal assignment to immutable variable 'self'"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: assert.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: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: cond.in
output:
registers: {}
- input_file: cond_2.in
output:
registers: {}

View File

@ -0,0 +1,15 @@
---
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: empty
output:
registers: {}

View File

@ -0,0 +1,15 @@
---
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: empty
output:
registers: {}

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 127
num_constraints: 127
at: e0e639bf48906da80759e2f98e3205a68a63ae175dcd7c198fe3bf6b1650a84e
bt: 6b92443726163ac0fc32f7c9edace0ec8369e793d24105d93d121cb0bd5c3128
ct: 7cb2d3f0ccfb9a2e747c6a05bdb52812c4539c836ff62c4e555fac13ef2084d4
output:
- input_file: inputs/input_unequal.in
output:
registers: {}
- input_file: inputs/input_equal.in
output:
registers: {}

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:4:18\n |\n 4 | console.log( hello );\n | ^^^^^\n |\n = expected 'formatted string', got 'hello'"

View File

@ -0,0 +1,15 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: log.in
output:
registers: {}

View File

@ -0,0 +1,15 @@
---
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: empty
output:
registers: {}

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:4:17\n |\n 4 | console.log(\"{}\");\n | ^^^^\n |\n = function call expected 2 arguments, got 1"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:4:17\n |\n 4 | console.log(\"\", 1u32);\n | ^^^^^^^^\n |\n = function call expected 1 arguments, got 2"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:4:23\n |\n 4 | console.log(\"{}\", a);\n | ^\n |\n = failed to resolve variable reference 'a'"

View File

@ -0,0 +1,15 @@
---
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: empty
output:
registers: {}

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:3:30\n |\n 3 | import core.unstable.blake2s.BadCircuit; // `BadCircuit` is not included in the blake2s package\n | ^^^^^^^^^^\n |\n = failed to resolve import: 'core.unstable.blake2s.BadCircuit'"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:3:30\n |\n 3 | import core.unstable.blake2s.BadCircuit; // `BadCircuit` is not included in the blake2s package\n | ^^^^^^^^^^\n |\n = failed to resolve import: 'core.unstable.blake2s.BadCircuit'"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> :0:0\n |\n |\n |\n = failed to resolve import: 'core'"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> :0:0\n |\n |\n |\n = failed to resolve import: 'core'"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> :0:0\n |\n |\n |\n = failed to resolve import: 'core.unstable'"

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: blake.in
output:
registers:
r0:
type: "[u8; 32]"
value: "[213, 24, 235, 180, 216, 116, 28, 65, 88, 162, 204, 6, 23, 8, 66, 112, 214, 239, 242, 134, 165, 39, 172, 247, 65, 130, 155, 2, 97, 147, 14, 57]"

View File

@ -0,0 +1,15 @@
---
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: empty
output:
registers: {}

View File

@ -0,0 +1,15 @@
---
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: empty
output:
registers: {}

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:6:5\n |\n 6 | a = 0;\n | ^^^^^\n |\n = illegal assignment to immutable variable 'a'"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> /test/src/main.leo:8:12\n |\n 8 | return a == 0u32;\n | ^^^^^^^^^\n |\n = unexpected type, expected: '()', received: 'bool'"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 127
num_constraints: 127
at: e89e71bb78cba20472e8ebfaeb36e6a9564861cf2b14846eb695a5937149dbfb
bt: 16d04f802c27d778734e07a0126cae3f096bc4e2e0b4362fe5687a338f1dece5
ct: acfbc6fdb7a3696d43be3cd62939a9731cb8b11c215564c52b3c67343cbda41f
output:
- input_file: swap.in
output:
registers:
r0:
type: bool
value: "false"