diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 2bb92925e59..f6291fc75ca 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -1,8 +1,7 @@ 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; @@ -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 { diff --git a/crates/nargo_cli/tests/prove_and_verify.rs b/crates/nargo_cli/tests/prove_and_verify.rs index 15e860bf059..951e288d7ed 100644 --- a/crates/nargo_cli/tests/prove_and_verify.rs +++ b/crates/nargo_cli/tests/prove_and_verify.rs @@ -1,3 +1,5 @@ +use assert_cmd::prelude::*; +use std::process::Command; use tempdir::TempDir; use std::collections::BTreeMap; @@ -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.