Skip to content

Commit

Permalink
Add ForeignCallError::Disabled and an integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Dec 19, 2024
1 parent 0f2ddca commit 796af50
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/noirc_printable_type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ pub enum PrintableValueDisplay<F> {

#[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),

Expand Down
7 changes: 7 additions & 0 deletions test_programs/execution_failure/mocks_in_execution/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "mocks_in_execution"
type = "bin"
authors = [""]
compiler_version = ">=0.23.0"

[dependencies]
Empty file.
Original file line number Diff line number Diff line change
@@ -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);
}
3 changes: 2 additions & 1 deletion tooling/nargo/src/foreign_calls/mocker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ impl<F> ForeignCallExecutor<F> 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()));
}
_ => {}
}
Expand Down

0 comments on commit 796af50

Please sign in to comment.