Skip to content

Commit

Permalink
Fix prover test
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Oct 2, 2023
1 parent c2180f4 commit bfb63a0
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions kzg_prover/src/constraint_system.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use serde::Deserialize;

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, PartialEq)]
pub struct Wire {
pub row: usize,
pub col: usize,
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, PartialEq)]
pub struct ConstraintSystemElem {
pub r#type: String,
pub wires: [Wire; 7],
pub coeffs: Vec<String>,
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, PartialEq)]
pub struct ConstraintSystem(pub Vec<ConstraintSystemElem>);

impl From<&str> for ConstraintSystem {
Expand All @@ -25,11 +25,33 @@ impl From<&str> for ConstraintSystem {

#[cfg(test)]
mod test {
use crate::constraint_system::{ConstraintSystem, ConstraintSystemElem, Wire};

#[test]
fn test_parse_json() {
let s = std::fs::read_to_string("./test_data/constraint_system.json").unwrap();
let cs = super::ConstraintSystem::from(s.as_str());
println!("{:?}", cs);
let cs_test = "[{\"type\":\"Generic\",\"wires\":[{\"row\":259,\"col\":0},{\"row\":0,\"col\":1},{\"row\":0,\"col\":2},{\"row\":0,\"col\":3},{\"row\":0,\"col\":4},{\"row\":0,\"col\":5},{\"row\":0,\"col\":6}],\"coeffs\":[\"1\",\"0\",\"0\",\"0\",\"0\"]}]";

let actual_cs = ConstraintSystem::from(cs_test);

let expected_cs = ConstraintSystem(vec![ConstraintSystemElem {
r#type: "Generic".to_string(),
wires: [
Wire { row: 259, col: 0 },
Wire { row: 0, col: 1 },
Wire { row: 0, col: 2 },
Wire { row: 0, col: 3 },
Wire { row: 0, col: 4 },
Wire { row: 0, col: 5 },
Wire { row: 0, col: 6 },
],
coeffs: vec![
"1".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
],
}]);
assert_eq!(actual_cs, expected_cs);
}
}

0 comments on commit bfb63a0

Please sign in to comment.