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(nargo): add integration test for "hello world" flow #1038

Merged
merged 3 commits into from
Mar 27, 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
182 changes: 182 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ aztec_backend = { optional = true, package = "barretenberg_static_lib", git = "h
aztec_wasm_backend = { optional = true, package = "barretenberg_wasm", git = "https://github.com/noir-lang/aztec_backend", rev = "2cb523d2ab95249157b22e198d9dcd6841c3eed8" }
marlin_arkworks_backend = { optional = true, git = "https://github.com/noir-lang/marlin_arkworks_backend", rev = "144378edad821bfaa52bf2cacca8ecc87514a4fc" }

[dev-dependencies]
assert_cmd = "2.0.8"
assert_fs = "1.0.10"
predicates = "2.1.5"

[features]
default = ["plonk_bn254"]
# The plonk backend can only use bn254, so we do not specify the field
Expand Down
56 changes: 56 additions & 0 deletions crates/nargo/tests/hello_world.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! This integration test aims to mirror the steps taken by a new user using Nargo for the first time.
//! It then follows the steps published at https://noir-lang.org/getting_started/hello_world.html
//! Any modifications to the commands run here MUST be documented in the noir-lang book.

use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;

use assert_fs::prelude::{FileWriteStr, PathAssert, PathChild};

#[test]
fn hello_world_example() {
let test_dir = assert_fs::TempDir::new().unwrap();
std::env::set_current_dir(&test_dir).unwrap();

let project_name = "hello_world";
let project_dir = test_dir.child(project_name);

// `nargo new hello_world`
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("new").arg(project_name);
cmd.assert().success().stdout(predicate::str::contains("Project successfully created!"));

project_dir.child("src").assert(predicate::path::is_dir());
project_dir.child("Nargo.toml").assert(predicate::path::is_file());

std::env::set_current_dir(&project_dir).unwrap();

// `nargo check`
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("check");
cmd.assert()
.success()
.stdout(predicate::str::contains("Constraint system successfully built!"));

project_dir.child("Prover.toml").assert(predicate::path::is_file());
project_dir.child("Verifier.toml").assert(predicate::path::is_file());

// `nargo prove p`
let proof_name = "p";
project_dir.child("Prover.toml").write_str("x = 1\ny = 2").unwrap();

let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("prove").arg(proof_name);
cmd.assert().success();

project_dir
.child("proofs")
.child(format!("{proof_name}.proof"))
.assert(predicate::path::is_file());

// `nargo verify p`
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("verify").arg(proof_name);
cmd.assert().success();
}