Skip to content

Commit

Permalink
add nonmembership proofs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Feb 20, 2024
1 parent a4650ae commit f270ae4
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions crates/store/src/avl/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! # Test suite of tendermock AVL Tree.
use ics23::{commitment_proof::Proof, verify_membership, HostFunctionsManager};
use ics23::{
commitment_proof::Proof, verify_membership, verify_non_membership, HostFunctionsManager,
NonExistenceProof,
};
use sha2::{Digest, Sha256};

use crate::avl::{
Expand Down Expand Up @@ -134,35 +137,42 @@ fn proof() {

#[test]
fn integration() {
let existing_keys = ["C", "E", "G", "I", "K", "M", "O", "Q", "S", "U"];
// less than all, in the middle, greater than all
let non_existing_keys = ["A", "B", "D", "F", "H", "J", "L", "N", "P", "R", "T", "V"];

let mut tree = AvlTree::new();
tree.insert("M", [0]);
tree.insert("N", [0]);
tree.insert("O", [0]);
tree.insert("L", [0]);
tree.insert("K", [0]);
tree.insert("Q", [0]);
tree.insert("P", [0]);
tree.insert("H", [0]);
tree.insert("I", [0]);
tree.insert("A", [0]);

for &key in existing_keys.iter() {
tree.insert(key, [0]);
}

assert!(check_integrity(&tree.root));

let root = tree
.root_hash()
.expect("Unable to retrieve root hash")
.as_bytes()
.to_vec();
let proof = tree
.get_proof("K")
.expect("Unable to retrieve a proof for 'K'");
let spec = get_proof_spec();
assert!(verify_membership::<HostFunctionsManager>(
&proof,
&spec,
&root,
"K".as_bytes(),
&[0]
));

for &key in existing_keys.iter() {
let proof = tree.get_proof(key);
assert!(
verify_membership::<HostFunctionsManager>(&proof, &spec, &root, key.as_bytes(), &[0]),
"Failed to verify membership for key {}",
key
);
}

for &key in non_existing_keys.iter() {
let proof = tree.get_proof(key);
assert!(
verify_non_membership::<HostFunctionsManager>(&proof, &spec, &root, key.as_bytes()),
"Failed to verify non-membership for key {}",
key
);
}
}

/// Check that nodes are ordered, heights are correct and that balance factors are in {-1, 0, 1}.
Expand Down

0 comments on commit f270ae4

Please sign in to comment.