Skip to content

Commit

Permalink
feat: switch integration tests to mirror CLI usage
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Apr 19, 2023
1 parent a675e07 commit 86cfa3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
26 changes: 2 additions & 24 deletions crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use clap::{Args, Parser, Subcommand};
use const_format::formatcp;
use noirc_abi::InputMap;
use noirc_driver::CompileOptions;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use color_eyre::eyre;

use crate::{constants::PROOFS_DIR, find_package_root};
use crate::find_package_root;

mod fs;

Expand Down Expand Up @@ -84,27 +83,6 @@ pub fn start_cli() -> eyre::Result<()> {
Ok(())
}

// helper function which tests noir programs by trying to generate a proof and verify it
pub fn prove_and_verify(proof_name: &str, program_dir: &Path, show_ssa: bool) -> bool {
let compile_options = CompileOptions { show_ssa, allow_warnings: false, show_output: false };
let proof_dir = program_dir.join(PROOFS_DIR);

match prove_cmd::prove_with_path(
Some(proof_name.to_owned()),
program_dir,
&proof_dir,
None,
true,
&compile_options,
) {
Ok(_) => true,
Err(error) => {
println!("{error}");
false
}
}
}

// FIXME: I not sure that this is the right place for this tests.
#[cfg(test)]
mod tests {
Expand Down
32 changes: 18 additions & 14 deletions crates/nargo_cli/tests/prove_and_verify.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use assert_cmd::prelude::*;
use std::process::Command;
use tempdir::TempDir;

use std::collections::BTreeMap;
Expand Down Expand Up @@ -79,24 +81,26 @@ mod tests {

println!("Running test {test_name}");

let verified = std::panic::catch_unwind(|| {
nargo_cli::cli::prove_and_verify("pp", test_program_dir, false)
});

let r = match verified {
Ok(result) => result,
Err(_) => {
panic!(
"\n\n\nPanic occurred while running test {test_name} (ignore the following panic)"
);
}
};
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("prove").arg("pp");

if config_data["fail"].contains(&test_name) {
assert!(!r, "{:?} should not succeed", test_name);
// TODO: add an expected error for each "fail" testcase.
// Alternatively we can move these to a separate integration test which just attempts
// to execute the circuit to ensure we catch the failure there.
// (currently these could pass execution but fail in proving)
cmd.assert().failure();
continue;
} else {
assert!(r, "verification fail for {:?}", test_name);
cmd.assert().success();
}

// Any programs which can be proven *must* be verifiable.
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("verify").arg("pp");
cmd.assert().success();
}

// Ensure that temp dir remains alive until all tests have run.
Expand Down

0 comments on commit 86cfa3f

Please sign in to comment.