Skip to content

Commit

Permalink
add test for simple proof
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Mar 29, 2024
1 parent 9128f39 commit ff1d5bd
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions ssz-rs/src/merkleization/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ pub fn is_valid_merkle_branch_for_generalized_index<T: AsRef<[u8]>>(
generalized_index: GeneralizedIndex,
root: Node,
) -> Result<(), Error> {
let index = log_2(generalized_index).ok_or(Error::InvalidGeneralizedIndex)? as usize;
let depth = get_subtree_index(generalized_index)?;
let depth = log_2(generalized_index).ok_or(Error::InvalidGeneralizedIndex)? as usize;
let index = get_subtree_index(generalized_index)?;
is_valid_merkle_branch(leaf, branch, depth, index, root)
}

Expand Down Expand Up @@ -121,7 +121,7 @@ mod tests {
}

#[test]
fn test_basic_proof() {
fn test_is_valid_merkle_branch() {
let leaf = decode_node_from_hex(
"94159da973dfa9e40ed02535ee57023ba2d06bad1017e451055470967eb71cd5",
);
Expand All @@ -142,6 +142,29 @@ mod tests {
assert!(is_valid_merkle_branch(leaf, &branch, depth, index, root).is_ok());
}

#[test]
fn test_simple_proof() {
let leaf = decode_node_from_hex(
"94159da973dfa9e40ed02535ee57023ba2d06bad1017e451055470967eb71cd5",
);
let branch = [
"8f594dbb4f4219ad4967f86b9cccdb26e37e44995a291582a431eef36ecba45c",
"f8c2ed25e9c31399d4149dcaa48c51f394043a6a1297e65780a5979e3d7bb77c",
"382ba9638ce263e802593b387538faefbaed106e9f51ce793d405f161b105ee6",
]
.into_iter()
.map(decode_node_from_hex)
.collect::<Vec<_>>();
let depth = 3;
let index = 2;
let proof = Proof { leaf, branch, index: 2usize.pow(depth) + index };
let root = decode_node_from_hex(
"27097c728aade54ff1376d5954681f6d45c282a81596ef19183148441b754abb",
);
let result = proof.verify(root);
assert!(result.is_ok());
}

#[test]
fn test_proving_primitives() {
let mut data = 8u8;
Expand Down

0 comments on commit ff1d5bd

Please sign in to comment.