mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-22 20:48:17 +03:00
update tests and leo cli
This commit is contained in:
parent
31ec24670c
commit
8a5d3e7718
@ -1,60 +1,50 @@
|
||||
use crate::{compile_program, get_error, get_output};
|
||||
use crate::{compile_program, get_error, get_output, EdwardsConstrainedValue, EdwardsTestCompiler};
|
||||
|
||||
use leo_compiler::errors::IntegerError;
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use leo_compiler::{
|
||||
compiler::Compiler,
|
||||
errors::{CompilerError, FunctionError},
|
||||
ConstrainedValue, InputValue, Integer,
|
||||
};
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use snarkos_models::gadgets::utilities::uint32::UInt32;
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/array/";
|
||||
|
||||
// [1, 1, 1]
|
||||
fn output_ones(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_ones(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Array(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Array(
|
||||
vec![ConstrainedValue::Integer(Integer::U32(UInt32::constant(1u32))); 3]
|
||||
)]),
|
||||
output
|
||||
)])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
// [[0, 0, 0],
|
||||
// [0, 0, 0]]
|
||||
fn output_multi(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_multi(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Array(vec![
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Array(vec![
|
||||
ConstrainedValue::Array(
|
||||
vec![ConstrainedValue::Integer(Integer::U32(UInt32::constant(0u32))); 3]
|
||||
);
|
||||
2
|
||||
])]),
|
||||
output
|
||||
])])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
)
|
||||
}
|
||||
|
||||
fn fail_array(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_array(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::InvalidArray(_string)) => {}
|
||||
error => panic!("Expected invalid array error, got {}", error),
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_synthesis(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_synthesis(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::IntegerError(
|
||||
IntegerError::SynthesisError(_string),
|
||||
|
@ -1,41 +1,33 @@
|
||||
use crate::{compile_program, get_error, get_output};
|
||||
use crate::{compile_program, get_error, get_output, EdwardsConstrainedValue, EdwardsTestCompiler};
|
||||
|
||||
use leo_compiler::errors::{BooleanError, ExpressionError};
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use leo_compiler::{
|
||||
compiler::Compiler,
|
||||
errors::{CompilerError, FunctionError, StatementError},
|
||||
ConstrainedValue, InputValue,
|
||||
};
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use snarkos_models::gadgets::utilities::boolean::Boolean;
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/boolean/";
|
||||
|
||||
fn output_true(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_true(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Boolean(Boolean::Constant(true))]),
|
||||
output
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Boolean(Boolean::Constant(true))])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
fn output_false(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_false(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Boolean(Boolean::Constant(false))]),
|
||||
output
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Boolean(Boolean::Constant(false))])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
fn fail_evaluate(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_evaluate(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::StatementError(
|
||||
StatementError::ExpressionError(ExpressionError::BooleanError(
|
||||
@ -46,9 +38,7 @@ fn fail_evaluate(
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_enforce(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_enforce(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::StatementError(
|
||||
StatementError::ExpressionError(ExpressionError::BooleanError(
|
||||
@ -59,9 +49,7 @@ fn fail_enforce(
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_boolean(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_boolean(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::BooleanError(
|
||||
BooleanError::InvalidBoolean(_string),
|
||||
@ -70,9 +58,7 @@ fn fail_boolean(
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_synthesis(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_synthesis(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::BooleanError(
|
||||
BooleanError::SynthesisError(_string),
|
||||
|
@ -1,44 +1,34 @@
|
||||
use crate::{
|
||||
compile_program,
|
||||
get_error,
|
||||
get_output,
|
||||
integer::u32::output_one,
|
||||
// group_element::output_zero
|
||||
compile_program, get_error, get_output, integer::u32::output_one, EdwardsConstrainedValue,
|
||||
EdwardsTestCompiler,
|
||||
};
|
||||
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use leo_compiler::{
|
||||
compiler::Compiler,
|
||||
errors::{CompilerError, ExpressionError, FunctionError, StatementError},
|
||||
ConstrainedCircuitMember, ConstrainedValue, Expression, Function, Identifier, Integer,
|
||||
Statement, Type,
|
||||
};
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use snarkos_models::gadgets::utilities::uint32::UInt32;
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/circuit/";
|
||||
|
||||
// Circ { x: 1u32 }
|
||||
fn output_circuit(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_circuit(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::CircuitExpression(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::CircuitExpression(
|
||||
Identifier::new("Circ".into()),
|
||||
vec![ConstrainedCircuitMember(
|
||||
Identifier::new("x".into()),
|
||||
ConstrainedValue::Integer(Integer::U32(UInt32::constant(1u32)))
|
||||
)]
|
||||
)]),
|
||||
output
|
||||
)])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
fn fail_expected_member(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_expected_member(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::StatementError(
|
||||
StatementError::ExpressionError(ExpressionError::ExpectedCircuitMember(_string)),
|
||||
@ -47,9 +37,7 @@ fn fail_expected_member(
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_undefined_member(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_undefined_member(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::StatementError(
|
||||
StatementError::ExpressionError(ExpressionError::UndefinedMemberAccess(_, _)),
|
||||
@ -159,7 +147,7 @@ fn test_self() {
|
||||
// }
|
||||
// }
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::CircuitExpression(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::CircuitExpression(
|
||||
Identifier::new("Circ".into()),
|
||||
vec![ConstrainedCircuitMember(
|
||||
Identifier::new("new".into()),
|
||||
@ -176,8 +164,9 @@ fn test_self() {
|
||||
}
|
||||
)))
|
||||
)]
|
||||
)]),
|
||||
output
|
||||
)])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,44 +1,38 @@
|
||||
use crate::{compile_program, get_error, get_output};
|
||||
use crate::{compile_program, get_error, get_output, EdwardsConstrainedValue, EdwardsTestCompiler};
|
||||
|
||||
use leo_compiler::errors::FieldElementError;
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use leo_compiler::{
|
||||
compiler::Compiler,
|
||||
errors::{CompilerError, FunctionError},
|
||||
ConstrainedValue, FieldElement, InputValue,
|
||||
};
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::{Field, ModelParameters};
|
||||
use snarkos_curves::edwards_bls12::Fq;
|
||||
use snarkos_models::curves::Field;
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/field_element/";
|
||||
|
||||
fn output_zero(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_zero(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::FieldElement(
|
||||
FieldElement::Constant(Fr::zero())
|
||||
)]),
|
||||
output
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::FieldElement(
|
||||
FieldElement::Constant(Fq::zero())
|
||||
)])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
fn output_one(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_one(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::FieldElement(
|
||||
FieldElement::Constant(Fr::one())
|
||||
)]),
|
||||
output
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::FieldElement(
|
||||
FieldElement::Constant(Fq::one())
|
||||
)])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
fn fail_field(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_field(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::FieldElementError(
|
||||
FieldElementError::InvalidField(_string),
|
||||
@ -47,9 +41,7 @@ fn fail_field(
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_synthesis(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_synthesis(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::FieldElementError(
|
||||
FieldElementError::SynthesisError(_string),
|
||||
|
@ -1,41 +1,38 @@
|
||||
use crate::{compile_program, get_error, get_output, integer::u32::output_one};
|
||||
use crate::{
|
||||
compile_program, get_error, get_output, integer::u32::output_one, EdwardsConstrainedValue,
|
||||
EdwardsTestCompiler,
|
||||
};
|
||||
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use leo_compiler::{
|
||||
compiler::Compiler,
|
||||
errors::{CompilerError, ExpressionError, FunctionError, StatementError},
|
||||
ConstrainedValue,
|
||||
};
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use snarkos_models::gadgets::utilities::boolean::Boolean;
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/function/";
|
||||
|
||||
pub(crate) fn output_empty(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
pub(crate) fn output_empty(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(ConstrainedValue::<Fq>::Return(vec![]), output);
|
||||
assert_eq!(
|
||||
EdwardsConstrainedValue::Return(vec![]).to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
// (true, false)
|
||||
pub(crate) fn output_multiple(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
pub(crate) fn output_multiple(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![
|
||||
EdwardsConstrainedValue::Return(vec![
|
||||
ConstrainedValue::Boolean(Boolean::Constant(true)),
|
||||
ConstrainedValue::Boolean(Boolean::Constant(false))
|
||||
]),
|
||||
output
|
||||
])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
)
|
||||
}
|
||||
|
||||
fn fail_undefined_identifier(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_undefined_identifier(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::StatementError(
|
||||
StatementError::ExpressionError(ExpressionError::UndefinedIdentifier(_)),
|
||||
|
@ -1,54 +1,46 @@
|
||||
use crate::{compile_program, get_error, get_output};
|
||||
use crate::{compile_program, get_error, get_output, EdwardsConstrainedValue, EdwardsTestCompiler};
|
||||
|
||||
use leo_compiler::{compiler::Compiler, types::Integer, ConstrainedValue, InputValue};
|
||||
use leo_compiler::{types::Integer, ConstrainedValue, InputValue};
|
||||
|
||||
use leo_compiler::errors::{CompilerError, FunctionError, IntegerError};
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use snarkos_models::gadgets::utilities::uint32::UInt32;
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/integer/u32/";
|
||||
|
||||
pub(crate) fn output_zero(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
pub(crate) fn output_zero(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
UInt32::constant(0u32)
|
||||
))]),
|
||||
output
|
||||
))])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn output_one(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
pub(crate) fn output_one(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
UInt32::constant(1u32)
|
||||
))]),
|
||||
output
|
||||
))])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
)
|
||||
}
|
||||
|
||||
fn output_two(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn output_two(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
UInt32::constant(2u32)
|
||||
))]),
|
||||
output
|
||||
))])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
)
|
||||
}
|
||||
|
||||
fn fail_integer(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_integer(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::IntegerError(
|
||||
IntegerError::InvalidInteger(_string),
|
||||
@ -57,9 +49,7 @@ fn fail_integer(
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_synthesis(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn fail_synthesis(program: EdwardsTestCompiler) {
|
||||
match get_error(program) {
|
||||
CompilerError::FunctionError(FunctionError::IntegerError(
|
||||
IntegerError::SynthesisError(_string),
|
||||
|
@ -17,18 +17,19 @@ use snarkos_models::curves::ModelParameters;
|
||||
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
||||
use std::env::current_dir;
|
||||
|
||||
pub(crate) fn get_output(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) -> ConstrainedValue<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType> {
|
||||
pub type EdwardsTestCompiler =
|
||||
Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>;
|
||||
pub type EdwardsConstrainedValue =
|
||||
ConstrainedValue<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>;
|
||||
|
||||
pub(crate) fn get_output(program: EdwardsTestCompiler) -> EdwardsConstrainedValue {
|
||||
let mut cs = TestConstraintSystem::<Fq>::new();
|
||||
let output = program.compile_constraints(&mut cs).unwrap();
|
||||
assert!(cs.is_satisfied());
|
||||
output
|
||||
}
|
||||
|
||||
pub(crate) fn get_error(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) -> CompilerError {
|
||||
pub(crate) fn get_error(program: EdwardsTestCompiler) -> CompilerError {
|
||||
let mut cs = TestConstraintSystem::<Fq>::new();
|
||||
program.compile_constraints(&mut cs).unwrap_err()
|
||||
}
|
||||
@ -36,10 +37,7 @@ pub(crate) fn get_error(
|
||||
pub(crate) fn compile_program(
|
||||
directory_name: &str,
|
||||
file_name: &str,
|
||||
) -> Result<
|
||||
Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
CompilerError,
|
||||
> {
|
||||
) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||
let path = current_dir().map_err(|error| CompilerError::DirectoryError(error))?;
|
||||
|
||||
// Sanitize the package path to the test directory
|
||||
@ -56,5 +54,5 @@ pub(crate) fn compile_program(
|
||||
println!("Compiling file - {:?}", main_file_path);
|
||||
|
||||
// Compile from the main file path
|
||||
Compiler::<Fq>::init(file_name.to_string(), main_file_path)
|
||||
EdwardsTestCompiler::init(file_name.to_string(), main_file_path)
|
||||
}
|
||||
|
@ -1,36 +1,30 @@
|
||||
use crate::compile_program;
|
||||
use crate::{compile_program, EdwardsConstrainedValue, EdwardsTestCompiler};
|
||||
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use leo_compiler::{
|
||||
compiler::Compiler,
|
||||
errors::{CompilerError, FunctionError, StatementError},
|
||||
types::{InputValue, Integer},
|
||||
ConstrainedValue,
|
||||
};
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use snarkos_curves::edwards_bls12::Fq;
|
||||
use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::uint32::UInt32};
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/mutability/";
|
||||
|
||||
fn mut_success(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn mut_success(program: EdwardsTestCompiler) {
|
||||
let mut cs = TestConstraintSystem::<Fq>::new();
|
||||
let output = program.compile_constraints(&mut cs).unwrap();
|
||||
|
||||
assert!(cs.is_satisfied());
|
||||
assert_eq!(
|
||||
ConstrainedValue::<Fq>::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Integer(Integer::U32(
|
||||
UInt32::constant(0)
|
||||
))]),
|
||||
output
|
||||
))])
|
||||
.to_string(),
|
||||
output.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
fn mut_fail(
|
||||
program: Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
) {
|
||||
fn mut_fail(program: EdwardsTestCompiler) {
|
||||
let mut cs = TestConstraintSystem::<Fq>::new();
|
||||
let err = program.compile_constraints(&mut cs).unwrap_err();
|
||||
|
||||
|
@ -3,7 +3,7 @@ use crate::{
|
||||
integer::u32::{output_one, output_zero},
|
||||
};
|
||||
use leo_compiler::InputValue;
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_curves::edwards_bls12::Fq;
|
||||
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
||||
|
||||
const DIRECTORY_NAME: &str = "tests/statement/";
|
||||
|
@ -5,9 +5,12 @@ use crate::{cli::*, cli_types::*};
|
||||
use leo_compiler::compiler::Compiler;
|
||||
|
||||
use snarkos_algorithms::snark::KeypairAssembly;
|
||||
use snarkos_curves::bls12_377::{Bls12_377, Fr};
|
||||
use snarkos_curves::bls12_377::Bls12_377;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use std::convert::TryFrom;
|
||||
use std::env::current_dir;
|
||||
|
||||
@ -16,7 +19,10 @@ pub struct BuildCommand;
|
||||
|
||||
impl CLI for BuildCommand {
|
||||
type Options = ();
|
||||
type Output = (Compiler<Fr>, bool);
|
||||
type Output = (
|
||||
Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
bool,
|
||||
);
|
||||
|
||||
const NAME: NameType = "build";
|
||||
const ABOUT: AboutType = "Compile the current package as a program";
|
||||
@ -60,7 +66,11 @@ impl CLI for BuildCommand {
|
||||
main_file_path.push(MAIN_FILE_NAME);
|
||||
|
||||
// Compute the current program checksum
|
||||
let program = Compiler::<Fr>::init(package_name.clone(), main_file_path.clone())?;
|
||||
let program = Compiler::<
|
||||
<EdwardsParameters as ModelParameters>::BaseField,
|
||||
Fq,
|
||||
EdwardsGroupType,
|
||||
>::init(package_name.clone(), main_file_path.clone())?;
|
||||
let program_checksum = program.checksum()?;
|
||||
|
||||
// Generate the program on the constraint system and verify correctness
|
||||
|
@ -7,11 +7,14 @@ use leo_compiler::compiler::Compiler;
|
||||
use snarkos_algorithms::snark::{
|
||||
generate_random_parameters, prepare_verifying_key, Parameters, PreparedVerifyingKey,
|
||||
};
|
||||
use snarkos_curves::bls12_377::{Bls12_377, Fr};
|
||||
use snarkos_curves::bls12_377::Bls12_377;
|
||||
use snarkos_utilities::bytes::ToBytes;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use leo_compiler::group::edwards_bls12::EdwardsGroupType;
|
||||
use rand::thread_rng;
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use std::convert::TryFrom;
|
||||
use std::env::current_dir;
|
||||
use std::time::Instant;
|
||||
@ -22,7 +25,7 @@ pub struct SetupCommand;
|
||||
impl CLI for SetupCommand {
|
||||
type Options = ();
|
||||
type Output = (
|
||||
Compiler<Fr>,
|
||||
Compiler<<EdwardsParameters as ModelParameters>::BaseField, Fq, EdwardsGroupType>,
|
||||
Parameters<Bls12_377>,
|
||||
PreparedVerifyingKey<Bls12_377>,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user