-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sync from noir (AztecProtocol/aztec-packages#5725)
Automated pull of development from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE feat: get last mock oracles params (#4789) feat: split `backend_barretenburg` into prover and verifier classes (#4769) chore: testing that nargo fmt is idempotent (#4765) feat: Sync from aztec-packages (#4787) fix: ArrayGet and Set are not pure (#4783) END_COMMIT_OVERRIDE --------- Co-authored-by: Santiago Palladino <santiago@aztecprotocol.com>
- Loading branch information
Showing
15 changed files
with
472 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
145cbcda61fd73f4e135348b31c59c774cfae965 | ||
825c455a62faeae5d148ce4f914efacb8f4c50fd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
name = "mock_oracle" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.23.0" | ||
|
||
[dependencies] | ||
[dependencies] |
Empty file.
130 changes: 130 additions & 0 deletions
130
test_programs/noir_test_success/mock_oracle/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
use dep::std::test::OracleMock; | ||
|
||
struct Point { | ||
x: Field, | ||
y: Field, | ||
} | ||
|
||
impl Eq for Point { | ||
fn eq(self, other: Point) -> bool { | ||
(self.x == other.x) & (self.y == other.y) | ||
} | ||
} | ||
|
||
#[oracle(void_field)] | ||
unconstrained fn void_field_oracle() -> Field {} | ||
|
||
unconstrained fn void_field() -> Field { | ||
void_field_oracle() | ||
} | ||
|
||
#[oracle(field_field)] | ||
unconstrained fn field_field_oracle(_x: Field) -> Field {} | ||
|
||
unconstrained fn field_field(x: Field) -> Field { | ||
field_field_oracle(x) | ||
} | ||
|
||
#[oracle(struct_field)] | ||
unconstrained fn struct_field_oracle(_point: Point, _array: [Field; 4]) -> Field {} | ||
|
||
unconstrained fn struct_field(point: Point, array: [Field; 4]) -> Field { | ||
struct_field_oracle(point, array) | ||
} | ||
|
||
#[test(should_fail)] | ||
fn test_mock_no_returns() { | ||
OracleMock::mock("void_field"); | ||
void_field(); // Some return value must be set | ||
} | ||
|
||
#[test] | ||
fn test_mock() { | ||
OracleMock::mock("void_field").returns(10); | ||
assert_eq(void_field(), 10); | ||
} | ||
|
||
#[test] | ||
fn test_multiple_mock() { | ||
let first_mock = OracleMock::mock("void_field").returns(10); | ||
OracleMock::mock("void_field").returns(42); | ||
|
||
// The mocks are searched for in creation order, so the first one prevents the second from being called. | ||
assert_eq(void_field(), 10); | ||
|
||
first_mock.clear(); | ||
assert_eq(void_field(), 42); | ||
} | ||
|
||
#[test] | ||
fn test_multiple_mock_times() { | ||
OracleMock::mock("void_field").returns(10).times(2); | ||
OracleMock::mock("void_field").returns(42); | ||
|
||
assert_eq(void_field(), 10); | ||
assert_eq(void_field(), 10); | ||
assert_eq(void_field(), 42); | ||
} | ||
|
||
#[test] | ||
fn test_mock_with_params() { | ||
OracleMock::mock("field_field").with_params((5,)).returns(10); | ||
assert_eq(field_field(5), 10); | ||
} | ||
|
||
#[test] | ||
fn test_multiple_mock_with_params() { | ||
OracleMock::mock("field_field").with_params((5,)).returns(10); | ||
OracleMock::mock("field_field").with_params((7,)).returns(14); | ||
|
||
assert_eq(field_field(5), 10); | ||
assert_eq(field_field(7), 14); | ||
} | ||
|
||
#[test] | ||
fn test_mock_last_params() { | ||
let mock = OracleMock::mock("field_field").returns(10); | ||
assert_eq(field_field(5), 10); | ||
|
||
assert_eq(mock.get_last_params(), 5); | ||
} | ||
|
||
#[test] | ||
fn test_mock_last_params_many_calls() { | ||
let mock = OracleMock::mock("field_field").returns(10); | ||
assert_eq(field_field(5), 10); | ||
assert_eq(field_field(7), 10); | ||
|
||
assert_eq(mock.get_last_params(), 7); | ||
} | ||
|
||
#[test] | ||
fn test_mock_struct_field() { | ||
// Combination of simpler test cases | ||
|
||
let array = [1, 2, 3, 4]; | ||
let another_array = [4, 3, 2, 1]; | ||
let point = Point { x: 14, y: 27 }; | ||
|
||
OracleMock::mock("struct_field").returns(42).times(2); | ||
let timeless_mock = OracleMock::mock("struct_field").returns(0); | ||
|
||
assert_eq(42, struct_field(point, array)); | ||
assert_eq(42, struct_field(point, array)); | ||
// The times(2) mock is now cleared | ||
|
||
assert_eq(0, struct_field(point, array)); | ||
|
||
let last_params: (Point, [Field; 4]) = timeless_mock.get_last_params(); | ||
assert_eq(last_params.0, point); | ||
assert_eq(last_params.1, array); | ||
|
||
// We clear the mock with no times() to allow other mocks to be callable | ||
timeless_mock.clear(); | ||
|
||
OracleMock::mock("struct_field").with_params((point, array)).returns(10); | ||
OracleMock::mock("struct_field").with_params((point, another_array)).returns(20); | ||
assert_eq(10, struct_field(point, array)); | ||
assert_eq(20, struct_field(point, another_array)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.