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: added regression test for check_for_underconstrained_values resolve bug #5490

Merged
merged 4 commits into from
Jul 15, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "check_unconstrained_regression"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
struct Trigger{
x: u32,
y: Field,
z: [Field;3],
}
struct ResultType{
a: u32,
b: Field,
c: [Field;3],
}

unconstrained fn convert(trigger: Trigger) -> ResultType {
let result= ResultType { a: trigger.x + 1, b: trigger.y - 1 + trigger.z[2], c: [trigger.z[0], 0, trigger.z[1]] };
result
}
impl Trigger {
fn execute(self) -> ResultType {
let result = convert(self);
assert(result.a == self.x + 1);
assert(result.b == self.y - 1 + self.z[2]);
assert(result.c[1] == 0);
result
}
}
fn main(x: Trigger) -> pub ResultType {
x.execute()
}
32 changes: 31 additions & 1 deletion tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn main() {
generate_noir_test_failure_tests(&mut test_file, &test_dir);
generate_compile_success_empty_tests(&mut test_file, &test_dir);
generate_compile_success_contract_tests(&mut test_file, &test_dir);
generate_compile_success_no_bug_tests(&mut test_file, &test_dir);
generate_compile_failure_tests(&mut test_file, &test_dir);
}

Expand Down Expand Up @@ -315,7 +316,6 @@ fn generate_compile_success_contract_tests(test_file: &mut File, test_data_dir:
&test_dir,
r#"
nargo.arg("compile").arg("--force");

nargo.assert().success();"#,
);

Expand All @@ -332,6 +332,36 @@ fn generate_compile_success_contract_tests(test_file: &mut File, test_data_dir:
}
}

/// Generate tests for checking that the contract compiles and there are no "bugs" in stderr
fn generate_compile_success_no_bug_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "compile_success_no_bug";
let test_cases = read_test_cases(test_data_dir, test_type);
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();

generate_test_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"
nargo.arg("compile").arg("--force");
nargo.assert().success().stderr(predicate::str::contains("bug:").not());"#,
);

generate_test_case(
test_file,
test_type,
&format!("legacy_{test_name}"),
&test_dir,
r#"
nargo.arg("compile").arg("--force").arg("--use-legacy");

nargo.assert().success().stderr(predicate::str::contains("bug:").not());"#,
);
}
}

fn generate_compile_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "compile_failure";
let test_cases = read_test_cases(test_data_dir, test_type);
Expand Down
Loading