Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch integration tests to mirror CLI usage #1179

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions crates/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,18 @@ fn generate_tests(test_file: &mut File, experimental_ssa: bool) {
fn prove_and_verify_{test_sub_dir}_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");

let verified = std::panic::catch_unwind(|| {{
nargo_cli::cli::prove_and_verify(&test_program_dir, {experimental_ssa})
}});

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("execute");
if {experimental_ssa} {{
cmd.arg("--experimental-ssa");
}};


if {should_fail} {{
assert!(!r, "{test_name} should not succeed");
cmd.assert().failure();
}} else {{
assert!(r, "verification fail for {test_name}");
cmd.assert().success();
}}
}}
"#,
Expand Down
32 changes: 1 addition & 31 deletions crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clap::{Args, Parser, Subcommand};
use const_format::formatcp;
use noirc_driver::CompileOptions;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use color_eyre::eyre;

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

// helper function which tests noir programs by trying to generate a proof and verify it without reading/writing to the filesystem
pub fn prove_and_verify(program_dir: &Path, experimental_ssa: bool) -> bool {
use compile_cmd::compile_circuit;

let backend = crate::backends::ConcreteBackend::default();

let compile_options = CompileOptions {
show_ssa: false,
print_acir: false,
deny_warnings: false,
show_output: false,
experimental_ssa,
};

let program =
compile_circuit(&backend, program_dir, &compile_options).expect("Compile should succeed");

// Parse the initial witness values from Prover.toml
let (inputs_map, _) = fs::inputs::read_inputs_from_file(
program_dir,
crate::constants::PROVER_INPUT_FILE,
noirc_abi::input_parser::Format::Toml,
&program.abi,
)
.expect("Should read inputs");

execute_cmd::execute_program(&backend, program.circuit, &program.abi, &inputs_map).is_ok()
}

// FIXME: I not sure that this is the right place for this tests.
#[cfg(test)]
mod tests {
Expand Down
6 changes: 5 additions & 1 deletion crates/nargo_cli/tests/prove_and_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#[cfg(test)]
mod tests {
// Some of these imports are consumed by the injected tests
use assert_cmd::prelude::*;
use tempdir::TempDir;

use std::collections::BTreeMap;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;

use super::*;

Expand Down