From 71f14d197659ba2e4b53da12d8066cab82e8e13d Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Thu, 11 Jul 2024 13:42:01 +0000 Subject: [PATCH 1/3] added regression test --- .../check_uncostrained_regression/Nargo.toml | 7 +++++ .../check_uncostrained_regression/src/main.nr | 27 +++++++++++++++++++ tooling/nargo_cli/build.rs | 6 ++--- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 test_programs/compile_success_empty/check_uncostrained_regression/Nargo.toml create mode 100644 test_programs/compile_success_empty/check_uncostrained_regression/src/main.nr diff --git a/test_programs/compile_success_empty/check_uncostrained_regression/Nargo.toml b/test_programs/compile_success_empty/check_uncostrained_regression/Nargo.toml new file mode 100644 index 00000000000..3c6b5d9688c --- /dev/null +++ b/test_programs/compile_success_empty/check_uncostrained_regression/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "check_unconstrained_regression" +type = "bin" +authors = [""] +compiler_version = ">=0.31.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_empty/check_uncostrained_regression/src/main.nr b/test_programs/compile_success_empty/check_uncostrained_regression/src/main.nr new file mode 100644 index 00000000000..e93e068f432 --- /dev/null +++ b/test_programs/compile_success_empty/check_uncostrained_regression/src/main.nr @@ -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() +} diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index 9dfa0dfe861..0a3cfe7ceff 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -34,7 +34,7 @@ fn main() { generate_noir_test_success_tests(&mut test_file, &test_dir); 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_bugs_contract_tests(&mut test_file, &test_dir); generate_compile_failure_tests(&mut test_file, &test_dir); } @@ -301,7 +301,7 @@ fn generate_compile_success_empty_tests(test_file: &mut File, test_data_dir: &Pa } } -fn generate_compile_success_contract_tests(test_file: &mut File, test_data_dir: &Path) { +fn generate_compile_success_no_bugs_contract_tests(test_file: &mut File, test_data_dir: &Path) { let test_type = "compile_success_contract"; let test_cases = read_test_cases(test_data_dir, test_type); for (test_name, test_dir) in test_cases { @@ -326,7 +326,7 @@ fn generate_compile_success_contract_tests(test_file: &mut File, test_data_dir: r#" nargo.arg("compile").arg("--force").arg("--use-legacy"); - nargo.assert().success();"#, + nargo.assert().success().stderr(predicate::str::contains("bug").not());"#, ); } } From 61ec38b91570431fdf14126d8a92a1b2b4292ea8 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Thu, 11 Jul 2024 16:18:59 +0000 Subject: [PATCH 2/3] return to previous --- .../check_uncostrained_regression/Nargo.toml | 0 .../check_uncostrained_regression/src/main.nr | 0 tooling/nargo_cli/build.rs | 3 +-- 3 files changed, 1 insertion(+), 2 deletions(-) rename test_programs/{compile_success_empty => compile_success_contract}/check_uncostrained_regression/Nargo.toml (100%) rename test_programs/{compile_success_empty => compile_success_contract}/check_uncostrained_regression/src/main.nr (100%) diff --git a/test_programs/compile_success_empty/check_uncostrained_regression/Nargo.toml b/test_programs/compile_success_contract/check_uncostrained_regression/Nargo.toml similarity index 100% rename from test_programs/compile_success_empty/check_uncostrained_regression/Nargo.toml rename to test_programs/compile_success_contract/check_uncostrained_regression/Nargo.toml diff --git a/test_programs/compile_success_empty/check_uncostrained_regression/src/main.nr b/test_programs/compile_success_contract/check_uncostrained_regression/src/main.nr similarity index 100% rename from test_programs/compile_success_empty/check_uncostrained_regression/src/main.nr rename to test_programs/compile_success_contract/check_uncostrained_regression/src/main.nr diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index 0a3cfe7ceff..24f7ac63641 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -314,7 +314,6 @@ fn generate_compile_success_no_bugs_contract_tests(test_file: &mut File, test_da &test_dir, r#" nargo.arg("compile").arg("--force"); - nargo.assert().success();"#, ); @@ -326,7 +325,7 @@ fn generate_compile_success_no_bugs_contract_tests(test_file: &mut File, test_da r#" nargo.arg("compile").arg("--force").arg("--use-legacy"); - nargo.assert().success().stderr(predicate::str::contains("bug").not());"#, + nargo.assert().success();"#, ); } } From ea6f5e5c8937796ac5d192d3182d96a9722910db Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Thu, 11 Jul 2024 17:15:37 +0000 Subject: [PATCH 3/3] separate type --- .../check_uncostrained_regression/Nargo.toml | 0 .../check_uncostrained_regression/src/main.nr | 0 tooling/nargo_cli/build.rs | 35 +++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) rename test_programs/{compile_success_contract => compile_success_no_bug}/check_uncostrained_regression/Nargo.toml (100%) rename test_programs/{compile_success_contract => compile_success_no_bug}/check_uncostrained_regression/src/main.nr (100%) diff --git a/test_programs/compile_success_contract/check_uncostrained_regression/Nargo.toml b/test_programs/compile_success_no_bug/check_uncostrained_regression/Nargo.toml similarity index 100% rename from test_programs/compile_success_contract/check_uncostrained_regression/Nargo.toml rename to test_programs/compile_success_no_bug/check_uncostrained_regression/Nargo.toml diff --git a/test_programs/compile_success_contract/check_uncostrained_regression/src/main.nr b/test_programs/compile_success_no_bug/check_uncostrained_regression/src/main.nr similarity index 100% rename from test_programs/compile_success_contract/check_uncostrained_regression/src/main.nr rename to test_programs/compile_success_no_bug/check_uncostrained_regression/src/main.nr diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index 24f7ac63641..37b02500023 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -34,7 +34,8 @@ fn main() { generate_noir_test_success_tests(&mut test_file, &test_dir); generate_noir_test_failure_tests(&mut test_file, &test_dir); generate_compile_success_empty_tests(&mut test_file, &test_dir); - generate_compile_success_no_bugs_contract_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); } @@ -301,7 +302,7 @@ fn generate_compile_success_empty_tests(test_file: &mut File, test_data_dir: &Pa } } -fn generate_compile_success_no_bugs_contract_tests(test_file: &mut File, test_data_dir: &Path) { +fn generate_compile_success_contract_tests(test_file: &mut File, test_data_dir: &Path) { let test_type = "compile_success_contract"; let test_cases = read_test_cases(test_data_dir, test_type); for (test_name, test_dir) in test_cases { @@ -330,6 +331,36 @@ fn generate_compile_success_no_bugs_contract_tests(test_file: &mut File, test_da } } +/// 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);