-
Notifications
You must be signed in to change notification settings - Fork 204
/
main.nr
42 lines (34 loc) · 1.43 KB
/
main.nr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use dep::std::slice;
use dep::std::test::OracleMock;
// Tests oracle usage in brillig/unconstrained functions
fn main(x: Field) {
let size = 20;
// TODO: Add a method along the lines of `(0..size).to_array()`.
let mut mock_oracle_response = [0; 20];
// TODO: Add an `array.reverse()` method.
let mut reversed_mock_oracle_response = [0; 20];
for i in 0..size {
mock_oracle_response[i] = i;
reversed_mock_oracle_response[19 - i] = i;
}
// TODO: this method of returning a slice feels hacky.
let _ = OracleMock::mock("get_number_sequence").with_params(size).returns((20, mock_oracle_response));
let _ = OracleMock::mock("get_reverse_number_sequence").with_params(size).returns((20, reversed_mock_oracle_response));
get_number_sequence_wrapper(size);
}
// Define oracle functions which we have mocked above
#[oracle(get_number_sequence)]
unconstrained fn get_number_sequence(_size: Field) -> [Field] {}
#[oracle(get_reverse_number_sequence)]
unconstrained fn get_reverse_number_sequence(_size: Field) -> [Field] {}
unconstrained fn get_number_sequence_wrapper(size: Field) {
let slice = get_number_sequence(size);
for i in 0..20 as u32 {
assert(slice[i] == i as Field);
}
let reversed_slice = get_reverse_number_sequence(size);
// Regression test that we have not overwritten memory
for i in 0..20 as u32 {
assert(slice[i] == reversed_slice[19 - i]);
}
}