Skip to content

Commit cc49a05

Browse files
committed
test: add noir tests for get_note_hash_membership_witness
Cover both the happy path (valid witness against the note-hash-tree root) and the missing-hash error path, matching the existing block-hash tests in the same file. Resolves F-652.
1 parent a95b715 commit cc49a05

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

noir-projects/aztec-nr/aztec/src/history/mod.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ pub mod deployment;
1414
pub mod note;
1515
pub mod nullifier;
1616
pub mod storage;
17-
mod test;
17+
pub(crate) mod test;

noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ unconstrained fn get_block_hash_membership_witness_oracle(
2121

2222
/// Returns a membership witness for a `note_hash` in the note hash tree whose root is defined in
2323
// `anchor_block_header`.
24-
// TODO(https://linear.app/aztec-labs/issue/F-652): add Noir tests for this oracle
2524
pub unconstrained fn get_note_hash_membership_witness(
2625
anchor_block_header: BlockHeader,
2726
note_hash: Field,
@@ -55,10 +54,52 @@ pub unconstrained fn get_maybe_block_hash_membership_witness(
5554
}
5655

5756
mod test {
57+
use crate::history::test::{create_note, NOTE_CREATED_AT};
58+
use crate::note::note_interface::NoteHash;
5859
use crate::oracle::block_header::get_block_header_at;
59-
use crate::protocol::{merkle_tree::root::root_from_sibling_path, traits::Hash};
60-
use crate::test::helpers::test_environment::TestEnvironment;
61-
use super::{get_block_hash_membership_witness, get_maybe_block_hash_membership_witness};
60+
use crate::protocol::{
61+
hash::{compute_siloed_note_hash, compute_unique_note_hash},
62+
merkle_tree::root::root_from_sibling_path,
63+
traits::Hash,
64+
};
65+
use crate::test::helpers::test_environment::{PrivateContextOptions, TestEnvironment};
66+
use super::{
67+
get_block_hash_membership_witness, get_maybe_block_hash_membership_witness, get_note_hash_membership_witness,
68+
};
69+
70+
#[test]
71+
unconstrained fn get_note_hash_membership_witness_returns_valid_witness_for_known_note() {
72+
let (env, hinted_note) = create_note();
73+
74+
env.private_context_opts(PrivateContextOptions::new().at_anchor_block_number(NOTE_CREATED_AT), |context| {
75+
let anchor = context.anchor_block_header;
76+
77+
let note_hash =
78+
hinted_note.note.compute_note_hash(hinted_note.owner, hinted_note.storage_slot, hinted_note.randomness);
79+
let siloed = compute_siloed_note_hash(hinted_note.contract_address, note_hash);
80+
let unique = compute_unique_note_hash(hinted_note.metadata.to_settled().note_nonce(), siloed);
81+
82+
let witness = get_note_hash_membership_witness(anchor, unique);
83+
84+
assert_eq(
85+
root_from_sibling_path(unique, witness.leaf_index, witness.sibling_path),
86+
anchor.state.partial.note_hash_tree.root,
87+
);
88+
});
89+
}
90+
91+
#[test(should_fail_with = "not found in the note hash tree at block")]
92+
unconstrained fn get_note_hash_membership_witness_panics_for_unknown_note() {
93+
let env = TestEnvironment::new();
94+
95+
env.mine_block();
96+
env.mine_block();
97+
98+
env.private_context(|context| {
99+
let anchor = context.anchor_block_header;
100+
let _witness = get_note_hash_membership_witness(anchor, 0xdeadbeef);
101+
});
102+
}
62103

63104
#[test]
64105
unconstrained fn get_block_hash_membership_witness_returns_valid_witness_for_known_block() {

0 commit comments

Comments
 (0)