leo/compiler/tests/mod.rs

54 lines
1.5 KiB
Rust
Raw Normal View History

2020-06-09 03:51:06 +03:00
pub mod array;
pub mod boolean;
2020-06-09 04:12:40 +03:00
pub mod circuits;
2020-06-09 04:27:11 +03:00
pub mod field;
2020-06-09 04:31:21 +03:00
pub mod function;
2020-06-09 04:39:10 +03:00
pub mod group;
2020-06-09 04:52:35 +03:00
pub mod import;
2020-06-09 04:12:40 +03:00
pub mod integers;
2020-06-09 04:55:44 +03:00
pub mod mutability;
2020-06-09 04:58:41 +03:00
pub mod statements;
2020-06-05 01:44:38 +03:00
pub mod syntax;
2020-06-02 04:35:43 +03:00
use leo_compiler::{
2020-06-03 02:06:25 +03:00
compiler::Compiler,
2020-06-09 04:39:10 +03:00
errors::{CompilerError, FunctionError, StatementError},
2020-06-03 02:06:25 +03:00
group::edwards_bls12::EdwardsGroupType,
2020-06-02 04:35:43 +03:00
ConstrainedValue,
};
2020-06-02 03:52:33 +03:00
use snarkos_curves::edwards_bls12::Fq;
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
2020-06-02 03:52:33 +03:00
pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>;
pub type EdwardsConstrainedValue = ConstrainedValue<Fq, EdwardsGroupType>;
2020-05-30 03:34:31 +03:00
pub(crate) fn get_output(program: EdwardsTestCompiler) -> EdwardsConstrainedValue {
2020-05-30 02:43:39 +03:00
let mut cs = TestConstraintSystem::<Fq>::new();
let output = program.compile_constraints(&mut cs).unwrap();
assert!(cs.is_satisfied());
output
}
2020-05-30 03:34:31 +03:00
pub(crate) fn get_error(program: EdwardsTestCompiler) -> CompilerError {
2020-05-30 02:43:39 +03:00
let mut cs = TestConstraintSystem::<Fq>::new();
program.compile_constraints(&mut cs).unwrap_err()
}
2020-06-09 04:39:10 +03:00
pub(crate) fn fail_enforce(program: EdwardsTestCompiler) {
match get_error(program) {
CompilerError::FunctionError(FunctionError::StatementError(StatementError::AssertionFailed(_, _))) => {}
error => panic!("Expected evaluate error, got {}", error),
}
}
2020-06-09 03:28:09 +03:00
pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
let program_string = String::from_utf8_lossy(bytes);
2020-06-09 03:28:09 +03:00
let mut compiler = EdwardsTestCompiler::new();
2020-06-09 03:28:09 +03:00
compiler.parse_program(&program_string)?;
2020-06-09 03:28:09 +03:00
Ok(compiler)
}