2020-05-20 03:08:38 +03:00
|
|
|
pub mod array;
|
2020-05-20 01:45:40 +03:00
|
|
|
pub mod boolean;
|
2020-05-20 07:59:00 +03:00
|
|
|
pub mod circuit;
|
2020-05-20 03:08:38 +03:00
|
|
|
pub mod field_element;
|
2020-05-21 01:51:57 +03:00
|
|
|
pub mod function;
|
2020-05-30 01:55:57 +03:00
|
|
|
pub mod group;
|
2020-05-21 01:51:57 +03:00
|
|
|
pub mod import;
|
2020-05-20 03:08:38 +03:00
|
|
|
pub mod integer;
|
2020-05-19 22:01:19 +03:00
|
|
|
pub mod mutability;
|
2020-05-21 03:08:32 +03:00
|
|
|
pub mod statement;
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-02 04:35:43 +03:00
|
|
|
use leo_compiler::{
|
|
|
|
compiler::Compiler, errors::CompilerError, group::edwards_bls12::EdwardsGroupType,
|
|
|
|
ConstrainedValue,
|
|
|
|
};
|
2020-05-19 22:01:19 +03:00
|
|
|
|
2020-06-02 03:52:33 +03:00
|
|
|
use snarkos_curves::edwards_bls12::Fq;
|
2020-05-20 01:45:40 +03:00
|
|
|
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
2020-05-19 22:01:19 +03:00
|
|
|
use std::env::current_dir;
|
|
|
|
|
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();
|
2020-05-20 01:45:40 +03:00
|
|
|
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();
|
2020-05-20 01:45:40 +03:00
|
|
|
program.compile_constraints(&mut cs).unwrap_err()
|
|
|
|
}
|
|
|
|
|
2020-05-19 22:01:19 +03:00
|
|
|
pub(crate) fn compile_program(
|
|
|
|
directory_name: &str,
|
|
|
|
file_name: &str,
|
2020-05-30 03:34:31 +03:00
|
|
|
) -> Result<EdwardsTestCompiler, CompilerError> {
|
2020-05-19 22:01:19 +03:00
|
|
|
let path = current_dir().map_err(|error| CompilerError::DirectoryError(error))?;
|
|
|
|
|
|
|
|
// Sanitize the package path to the test directory
|
|
|
|
let mut package_path = path.clone();
|
|
|
|
if package_path.is_file() {
|
|
|
|
package_path.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the path to the test file in the test directory
|
|
|
|
let mut main_file_path = package_path.clone();
|
|
|
|
main_file_path.push(directory_name);
|
|
|
|
main_file_path.push(file_name);
|
|
|
|
|
|
|
|
println!("Compiling file - {:?}", main_file_path);
|
|
|
|
|
|
|
|
// Compile from the main file path
|
2020-05-30 03:34:31 +03:00
|
|
|
EdwardsTestCompiler::init(file_name.to_string(), main_file_path)
|
2020-05-19 22:01:19 +03:00
|
|
|
}
|