Skip to content

Commit

Permalink
Add C++ test for k size and Rust tests for proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Aug 15, 2024
1 parent 4853507 commit 59292bd
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rust-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ link-cplusplus = "1.0.9"
[build-dependencies]
bindgen = "0.69.4"
cmake = "0.1.50"

[dev-dependencies]
hex = "0.4.3"
28 changes: 28 additions & 0 deletions rust-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ pub fn validate_proof(
mod tests {
use super::*;

#[test]
fn test_proofs() {
/*
* Generated by printing the inputs to validate_proof in tests/test_python_bindings.py
* Specifically, the test_k_21 function was adapted to append 100 lines to the file.
*/
let proofs = include_str!("../test_proofs.txt");

for line in proofs.lines() {
let mut parts = line.split(", ");
let seed = hex::decode(parts.next().unwrap()).unwrap();
let k = parts.next().unwrap().parse().unwrap();
let challenge = hex::decode(parts.next().unwrap()).unwrap();
let proof = hex::decode(parts.next().unwrap()).unwrap();
let quality = hex::decode(parts.next().unwrap()).unwrap();

let mut actual_quality = [0; 32];
assert!(validate_proof(
&seed.try_into().unwrap(),
k,
&challenge.try_into().unwrap(),
&proof,
&mut actual_quality
));
assert_eq!(actual_quality.as_slice(), quality);
}
}

#[test]
fn test_empty_proof() {
let mut quality = [0; 32];
Expand Down
Loading

0 comments on commit 59292bd

Please sign in to comment.