Skip to content

Commit

Permalink
Move example run checks into example tests
Browse files Browse the repository at this point in the history
Should speed up CI a bit
  • Loading branch information
samtay committed Jul 18, 2023
1 parent 0871969 commit f786666
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 26 deletions.
27 changes: 3 additions & 24 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions examples/amm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ fn main() -> Result<(), Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn main_works() -> Result<(), Error> {
main()
}
}
10 changes: 10 additions & 0 deletions examples/bigint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,13 @@ fn main() -> Result<(), Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn main_works() -> Result<(), Error> {
main()
}
}
10 changes: 10 additions & 0 deletions examples/chi_sq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,13 @@ fn main() -> Result<(), Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn main_works() -> Result<(), Error> {
main()
}
}
10 changes: 10 additions & 0 deletions examples/dot_prod/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,13 @@ fn main() -> Result<(), sunscreen::Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn main_works() -> Result<(), Error> {
main()
}
}
10 changes: 10 additions & 0 deletions examples/mean_variance/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,13 @@ fn main() -> Result<(), Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn main_works() -> Result<(), Error> {
main()
}
}
5 changes: 5 additions & 0 deletions examples/ordering_zkp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BulletproofsBackend>()
Expand Down
10 changes: 10 additions & 0 deletions examples/pir/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,13 @@ fn main() -> Result<(), Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn main_works() -> Result<(), Error> {
main()
}
}
5 changes: 5 additions & 0 deletions examples/polynomial_zkp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BulletproofsBackend>()?;
Expand Down
10 changes: 10 additions & 0 deletions examples/simple_multiply/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ fn main() -> Result<(), Error> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn main_works() -> Result<(), Error> {
main()
}
}
5 changes: 5 additions & 0 deletions examples/sudoku_zkp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BulletproofsBackend>().unwrap();
Expand Down
30 changes: 28 additions & 2 deletions examples/whitelist_zkp/verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BulletproofsBackend>()?;
let runtime = whitelist.runtime::<BulletproofsBackend>()?;

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(())
}
}

0 comments on commit f786666

Please sign in to comment.