From 796af5065deb7e630a8666cdc6e1fee9986ec4fd Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Thu, 19 Dec 2024 16:03:52 +0000 Subject: [PATCH] Add ForeignCallError::Disabled and an integration test --- compiler/noirc_printable_type/src/lib.rs | 3 +++ .../execution_failure/mocks_in_execution/Nargo.toml | 7 +++++++ .../execution_failure/mocks_in_execution/Prover.toml | 0 .../execution_failure/mocks_in_execution/src/main.nr | 5 +++++ tooling/nargo/src/foreign_calls/mocker.rs | 3 ++- 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test_programs/execution_failure/mocks_in_execution/Nargo.toml create mode 100644 test_programs/execution_failure/mocks_in_execution/Prover.toml create mode 100644 test_programs/execution_failure/mocks_in_execution/src/main.nr diff --git a/compiler/noirc_printable_type/src/lib.rs b/compiler/noirc_printable_type/src/lib.rs index f85dfcc8e1e..d592b84fa0a 100644 --- a/compiler/noirc_printable_type/src/lib.rs +++ b/compiler/noirc_printable_type/src/lib.rs @@ -69,6 +69,9 @@ pub enum PrintableValueDisplay { #[derive(Debug, Error)] pub enum ForeignCallError { + #[error("Attempted to call disabled foreign call `{0}`")] + Disabled(String), + #[error("No handler could be found for foreign call `{0}`")] NoHandler(String), diff --git a/test_programs/execution_failure/mocks_in_execution/Nargo.toml b/test_programs/execution_failure/mocks_in_execution/Nargo.toml new file mode 100644 index 00000000000..c83da9a3d0c --- /dev/null +++ b/test_programs/execution_failure/mocks_in_execution/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "mocks_in_execution" +type = "bin" +authors = [""] +compiler_version = ">=0.23.0" + +[dependencies] diff --git a/test_programs/execution_failure/mocks_in_execution/Prover.toml b/test_programs/execution_failure/mocks_in_execution/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_programs/execution_failure/mocks_in_execution/src/main.nr b/test_programs/execution_failure/mocks_in_execution/src/main.nr new file mode 100644 index 00000000000..b43068ab251 --- /dev/null +++ b/test_programs/execution_failure/mocks_in_execution/src/main.nr @@ -0,0 +1,5 @@ +fn main() { + // Trying to use a mock in `nargo execute` should fail. + let mock = unsafe { std::test::OracleMock::mock("foo") }; + assert_eq(mock.id, 0); +} diff --git a/tooling/nargo/src/foreign_calls/mocker.rs b/tooling/nargo/src/foreign_calls/mocker.rs index ac821155eef..c8a3425ee45 100644 --- a/tooling/nargo/src/foreign_calls/mocker.rs +++ b/tooling/nargo/src/foreign_calls/mocker.rs @@ -192,7 +192,8 @@ impl ForeignCallExecutor for DisabledMockForeignCallExecutor { | ForeignCall::SetMockReturns | ForeignCall::SetMockTimes | ForeignCall::ClearMock => { - panic!("unexpected mock call: {}", foreign_call.function) + // Returning an error instead of panicking so this can be tested. + return Err(ForeignCallError::Disabled(foreign_call.function.to_string())); } _ => {} }