Skip to content

Commit

Permalink
Add test for attaching to hash nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum committed Oct 18, 2024
1 parent 6515228 commit 770782d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/proofs/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ mod test {
use super::*;
use crate::test_utils::make_tree_seq;
use crate::tree::{NoopCommit, PanicSource, RefWalker, Tree};
use ed::Encode;

fn make_3_node_tree() -> Result<Tree> {
let mut tree = Tree::new(vec![5], vec![5])?
Expand Down Expand Up @@ -1477,4 +1478,18 @@ mod test {

let _result = verify_query(bytes.as_slice(), &query, [42; 32]).expect("verify failed");
}

#[test]
#[should_panic(expected = "Tried to attach to Hash node")]
fn hash_attach() {
let mut target = make_3_node_tree().expect("tree construction failed");

let mut proof = Vec::new();
proof.push(Op::Push(Node::KV(vec![42], vec![42])));
proof.push(Op::Push(Node::Hash(target.hash())));
proof.push(Op::Parent);

let map = verify(&proof.encode().unwrap(), target.hash()).unwrap();
assert_eq!(map.get(&[42]).unwrap().unwrap(), &[42])
}
}

0 comments on commit 770782d

Please sign in to comment.