add optional field, use it on one test
This commit is contained in:
parent
fd8ca86ae0
commit
91c0b6e8e5
4 changed files with 30 additions and 14 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1832,7 +1832,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_test"
|
||||
version = "0.1.1"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fs_extra",
|
||||
"glob 0.3.0",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"entry_point": "./tests/tests/spread_slice.zok",
|
||||
"max_constraint_count": 9,
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "zokrates_test"
|
||||
version = "0.1.1"
|
||||
version = "0.1.0"
|
||||
authors = ["schaeff <thibaut@schaeff.fr>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use zokrates_field::field::{Field, FieldPrime};
|
|||
#[derive(Serialize, Deserialize)]
|
||||
struct Tests {
|
||||
pub entry_point: PathBuf,
|
||||
pub max_constraint_count: Option<usize>,
|
||||
pub tests: Vec<Test>,
|
||||
}
|
||||
|
||||
|
@ -34,6 +35,18 @@ struct Output {
|
|||
|
||||
type Val = String;
|
||||
|
||||
fn parse_val<T: Field>(s: String) -> T {
|
||||
let s = if s.starts_with("0x") {
|
||||
u32::from_str_radix(s.trim_start_matches("0x"), 16)
|
||||
.unwrap()
|
||||
.to_string()
|
||||
} else {
|
||||
s
|
||||
};
|
||||
|
||||
T::try_from_dec_str(&s).unwrap()
|
||||
}
|
||||
|
||||
impl From<ir::ExecutionResult<FieldPrime>> for ComparableResult {
|
||||
fn from(r: ir::ExecutionResult<FieldPrime>) -> ComparableResult {
|
||||
ComparableResult(r.map(|v| v.return_values()))
|
||||
|
@ -42,12 +55,7 @@ impl From<ir::ExecutionResult<FieldPrime>> for ComparableResult {
|
|||
|
||||
impl From<TestResult> for ComparableResult {
|
||||
fn from(r: TestResult) -> ComparableResult {
|
||||
ComparableResult(r.map(|v| {
|
||||
v.values
|
||||
.iter()
|
||||
.map(|v| FieldPrime::try_from_dec_str(v).unwrap())
|
||||
.collect()
|
||||
}))
|
||||
ComparableResult(r.map(|v| v.values.into_iter().map(parse_val).collect()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,14 +89,21 @@ pub fn test_inner(test_path: &str) {
|
|||
|
||||
let bin = artifacts.prog();
|
||||
|
||||
match t.max_constraint_count {
|
||||
Some(count) => assert!(
|
||||
bin.constraint_count() <= count,
|
||||
"Expected at the most {} constraints, found {}:\n{}",
|
||||
count,
|
||||
bin.constraint_count(),
|
||||
bin
|
||||
),
|
||||
_ => {}
|
||||
};
|
||||
|
||||
for test in t.tests.into_iter() {
|
||||
let input = &test.input.values;
|
||||
let output = bin.execute(
|
||||
&input
|
||||
.iter()
|
||||
.map(|v| FieldPrime::try_from_dec_str(&v.clone()).unwrap())
|
||||
.collect(),
|
||||
);
|
||||
|
||||
let output = bin.execute(&(input.iter().cloned().map(parse_val).collect()));
|
||||
|
||||
match compare(output, test.output) {
|
||||
Err(e) => {
|
||||
|
|
Loading…
Reference in a new issue