Skip to content

Commit

Permalink
chore: added regression test for check_for_underconstrained_values re…
Browse files Browse the repository at this point in the history
…solve bug (#5490)

# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

There was a bug in the check_for_underconstrained_values pass that got
fixed. This PR adds a regression test for that issue

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
Rumata888 authored Jul 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 6bcdac4 commit d4baf61
Showing 3 changed files with 65 additions and 1 deletion.
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
@@ -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);
}

@@ -318,7 +319,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();"#,
);

@@ -335,6 +335,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);

0 comments on commit d4baf61

Please sign in to comment.