From f78666661fa7b5cc9d8b891a031c2141218d9f54 Mon Sep 17 00:00:00 2001 From: Sam Tay Date: Mon, 17 Jul 2023 23:24:42 -0400 Subject: [PATCH] Move example run checks into example tests Should speed up CI a bit --- .github/workflows/rust.yml | 27 +++---------------- examples/amm/src/main.rs | 10 +++++++ examples/bigint/src/main.rs | 10 +++++++ examples/chi_sq/src/main.rs | 10 +++++++ examples/dot_prod/src/main.rs | 10 +++++++ examples/mean_variance/src/main.rs | 10 +++++++ examples/ordering_zkp/src/main.rs | 5 ++++ examples/pir/src/main.rs | 10 +++++++ examples/polynomial_zkp/src/main.rs | 5 ++++ examples/simple_multiply/src/main.rs | 10 +++++++ examples/sudoku_zkp/src/main.rs | 5 ++++ examples/whitelist_zkp/verifier/src/main.rs | 30 +++++++++++++++++++-- 12 files changed, 116 insertions(+), 26 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4a386cbf5..343eede9c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,30 +42,9 @@ jobs: run: cargo fmt --check # Build and run the tests - name: Build and run tests - run: cargo test --verbose --release - # Run our non-interactive examples and assert the complete without error - - name: Verify examples (amm) - run: cargo run --release --bin amm - - name: Verify examples (bigint) - run: cargo run --release --bin bigint - - name: Verify examples (chi_sq) - run: cargo run --release --bin chi_sq - - name: Verify examples (dot_prod) - run: cargo run --release --bin dot_prod - - name: Verify examples (mean_variance) - run: cargo run --release --bin mean_variance - - name: Verify examples (ordering_zkp) - run: cargo run --release --bin ordering_zkp - - name: Verify examples (pir) - run: cargo run --release --bin pir - - name: Verify examples (simple_multiply) - run: cargo run --release --bin simple_multiply - - name: Verify examples (sudoku_zkp) - run: cargo run --release --bin sudoku_zkp - - name: Verify examples (polynomial_zkp) - run: cargo run --release --bin polynomial_zkp - - name: Verify examples (whitelist_zkp) - run: cargo test --all + run: cargo test --workspace --verbose --release + - name: Verify examples outside of workspace (whitelist_zkp) + run: cargo test --workspace --verbose working-directory: ./examples/whitelist_zkp - name: Build sunscreen and bincode run: cargo build --release --package sunscreen --package bincode diff --git a/examples/amm/src/main.rs b/examples/amm/src/main.rs index 4c3afdc0c..a734802dc 100644 --- a/examples/amm/src/main.rs +++ b/examples/amm/src/main.rs @@ -106,3 +106,13 @@ fn main() -> Result<(), Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<(), Error> { + main() + } +} diff --git a/examples/bigint/src/main.rs b/examples/bigint/src/main.rs index 81657391d..596b2474c 100644 --- a/examples/bigint/src/main.rs +++ b/examples/bigint/src/main.rs @@ -89,3 +89,13 @@ fn main() -> Result<(), Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<(), Error> { + main() + } +} diff --git a/examples/chi_sq/src/main.rs b/examples/chi_sq/src/main.rs index 9f5bc2c44..642858e46 100644 --- a/examples/chi_sq/src/main.rs +++ b/examples/chi_sq/src/main.rs @@ -289,3 +289,13 @@ fn main() -> Result<(), Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<(), Error> { + main() + } +} diff --git a/examples/dot_prod/src/main.rs b/examples/dot_prod/src/main.rs index cf48f3ba3..42f7d206d 100644 --- a/examples/dot_prod/src/main.rs +++ b/examples/dot_prod/src/main.rs @@ -186,3 +186,13 @@ fn main() -> Result<(), sunscreen::Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<(), Error> { + main() + } +} diff --git a/examples/mean_variance/src/main.rs b/examples/mean_variance/src/main.rs index b88ee36a5..33e451a6b 100644 --- a/examples/mean_variance/src/main.rs +++ b/examples/mean_variance/src/main.rs @@ -201,3 +201,13 @@ fn main() -> Result<(), Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<(), Error> { + main() + } +} diff --git a/examples/ordering_zkp/src/main.rs b/examples/ordering_zkp/src/main.rs index 501168d01..119f1cbb3 100644 --- a/examples/ordering_zkp/src/main.rs +++ b/examples/ordering_zkp/src/main.rs @@ -35,6 +35,11 @@ fn main() -> Result<(), Error> { mod tests { use super::*; + #[test] + fn main_works() -> Result<(), Error> { + main() + } + fn run_test(amount: BulletproofsField, threshold: BulletproofsField, should_succeed: bool) { let app = Compiler::new() .zkp_backend::() diff --git a/examples/pir/src/main.rs b/examples/pir/src/main.rs index 626fd0222..53800b0af 100644 --- a/examples/pir/src/main.rs +++ b/examples/pir/src/main.rs @@ -159,3 +159,13 @@ fn main() -> Result<(), Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<(), Error> { + main() + } +} diff --git a/examples/polynomial_zkp/src/main.rs b/examples/polynomial_zkp/src/main.rs index 24e500485..db7f882be 100644 --- a/examples/polynomial_zkp/src/main.rs +++ b/examples/polynomial_zkp/src/main.rs @@ -308,6 +308,11 @@ mod tests { use super::*; + #[test] + fn main_works() -> Result<(), Error> { + main() + } + #[test] fn one_of_failure() -> Result<(), Error> { let one_of_zkp = one_of.compile::()?; diff --git a/examples/simple_multiply/src/main.rs b/examples/simple_multiply/src/main.rs index 1a4d95060..73bf2f130 100644 --- a/examples/simple_multiply/src/main.rs +++ b/examples/simple_multiply/src/main.rs @@ -81,3 +81,13 @@ fn main() -> Result<(), Error> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<(), Error> { + main() + } +} diff --git a/examples/sudoku_zkp/src/main.rs b/examples/sudoku_zkp/src/main.rs index 1f457ecdd..ad2dfd328 100644 --- a/examples/sudoku_zkp/src/main.rs +++ b/examples/sudoku_zkp/src/main.rs @@ -100,6 +100,11 @@ fn main() -> Result<(), Error> { mod tests { use super::*; + #[test] + fn main_works() -> Result<(), Error> { + main() + } + #[test] fn valid_example() { let prog = sudoku_proof.compile::().unwrap(); diff --git a/examples/whitelist_zkp/verifier/src/main.rs b/examples/whitelist_zkp/verifier/src/main.rs index 42051659a..88b8202f0 100644 --- a/examples/whitelist_zkp/verifier/src/main.rs +++ b/examples/whitelist_zkp/verifier/src/main.rs @@ -21,8 +21,34 @@ fn main() -> Result<()> { .public_input(list) .verify()?; - runtime.verify(&prog, &proof, vec![list], vec![])?; - println!("Verified proof successfully!"); Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn main_works() -> Result<()> { + let prog = whitelist.compile::()?; + let runtime = whitelist.runtime::()?; + + let entry: BulletproofsField = 101.into(); + let list: [BulletproofsField; 100] = default_list(); + + let proof = runtime + .proof_builder(&prog) + .private_input(entry) + .public_input(list) + .prove()?; + + runtime + .verification_builder(&prog) + .proof(&proof) + .public_input(list) + .verify()?; + + Ok(()) + } +}