From d98db3aa7cbfdaf5f698d4f4f0eaf4a788a02199 Mon Sep 17 00:00:00 2001 From: Maddiaa <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:32:30 +0000 Subject: [PATCH] fix: noir test incorrect reporting (#4925) fixes: https://github.com/AztecProtocol/aztec-packages/issues/4912 --- .../noir-protocol-circuits/crates/types/src/hash.nr | 8 ++++---- .../crates/types/src/tests/kernel_data_builder.nr | 9 +++++++-- .../should_fail_suite_with_one_failure/Prover.toml | 0 .../should_fail_suite_with_one_failure/src/main.nr | 11 +++++++++++ noir/noir-repo/tooling/nargo_cli/src/cli/test_cmd.rs | 6 +++--- 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 noir/noir-repo/test_programs/noir_test_failure/should_fail_suite_with_one_failure/Prover.toml create mode 100644 noir/noir-repo/test_programs/noir_test_failure/should_fail_suite_with_one_failure/src/main.nr diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index a374a21b416..14c5deba67d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -10,10 +10,10 @@ use crate::abis::side_effect::{SideEffect}; use crate::utils::uint256::U256; use crate::constants::{ ARGS_HASH_CHUNK_COUNT, ARGS_HASH_CHUNK_LENGTH, CONTRACT_TREE_HEIGHT, FUNCTION_TREE_HEIGHT, - NUM_FIELDS_PER_SHA256, GENERATOR_INDEX__SILOED_NOTE_HASH, - GENERATOR_INDEX__OUTER_NULLIFIER, GENERATOR_INDEX__VK, GENERATOR_INDEX__CONSTRUCTOR, - GENERATOR_INDEX__PARTIAL_ADDRESS, GENERATOR_INDEX__CONTRACT_ADDRESS, - GENERATOR_INDEX__NOTE_HASH_NONCE, GENERATOR_INDEX__UNIQUE_NOTE_HASH, GENERATOR_INDEX__FUNCTION_ARGS + NUM_FIELDS_PER_SHA256, GENERATOR_INDEX__SILOED_NOTE_HASH, GENERATOR_INDEX__OUTER_NULLIFIER, + GENERATOR_INDEX__VK, GENERATOR_INDEX__CONSTRUCTOR, GENERATOR_INDEX__PARTIAL_ADDRESS, + GENERATOR_INDEX__CONTRACT_ADDRESS, GENERATOR_INDEX__NOTE_HASH_NONCE, + GENERATOR_INDEX__UNIQUE_NOTE_HASH, GENERATOR_INDEX__FUNCTION_ARGS }; use crate::messaging::l2_to_l1_message::L2ToL1Message; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr index 357248be829..31704bb1b6e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr @@ -135,8 +135,13 @@ impl PreviousKernelDataBuilder { } fn get_mock_nullifier_value(self, nullifier_index: u64) -> Field { - let first_nullifier = self.end.new_nullifiers.get(0); - first_nullifier.value + nullifier_index as Field + let first_nullifier = if (self.end.new_nullifiers.len() > 0) { + self.end.new_nullifiers.get(0).value + } else { + 0 as Field + }; + + first_nullifier + nullifier_index as Field } pub fn append_new_nullifiers_from_private(&mut self, num_extra_nullifier: u64) { diff --git a/noir/noir-repo/test_programs/noir_test_failure/should_fail_suite_with_one_failure/Prover.toml b/noir/noir-repo/test_programs/noir_test_failure/should_fail_suite_with_one_failure/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/noir/noir-repo/test_programs/noir_test_failure/should_fail_suite_with_one_failure/src/main.nr b/noir/noir-repo/test_programs/noir_test_failure/should_fail_suite_with_one_failure/src/main.nr new file mode 100644 index 00000000000..8ed9003164a --- /dev/null +++ b/noir/noir-repo/test_programs/noir_test_failure/should_fail_suite_with_one_failure/src/main.nr @@ -0,0 +1,11 @@ +/// Test to make sure the entire test suite fails, even if some of the tests pass! + +#[test] +fn this_will_pass() { + assert(true); +} + +#[test] +fn this_will_fail() { + assert(false); +} diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/test_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/test_cmd.rs index 503fd5afdd4..68660d62d23 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/test_cmd.rs @@ -116,10 +116,10 @@ pub(crate) fn run( }; } - if test_report.iter().any(|(_, status)| !matches!(status, TestStatus::Fail { .. })) { - Ok(()) - } else { + if test_report.iter().any(|(_, status)| matches!(status, TestStatus::Fail { .. })) { Err(CliError::Generic(String::new())) + } else { + Ok(()) } }