clearer assertions in sparse_path tests
This commit is contained in:
parent
ff75b046a6
commit
b28a31f495
2 changed files with 13 additions and 7 deletions
|
@ -1,12 +1,11 @@
|
||||||
use alloc::collections::BTreeSet;
|
use alloc::collections::BTreeSet;
|
||||||
|
|
||||||
use crate::merkle::{SparseMerklePath, SparseValuePath};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
super::ValuePath, EMPTY_WORD, EmptySubtreeRoots, InnerNode, InnerNodeInfo, InnerNodes,
|
super::ValuePath, EMPTY_WORD, EmptySubtreeRoots, InnerNode, InnerNodeInfo, InnerNodes,
|
||||||
LeafIndex, MerkleError, MerklePath, MutationSet, NodeIndex, RpoDigest, SMT_MAX_DEPTH,
|
LeafIndex, MerkleError, MerklePath, MutationSet, NodeIndex, RpoDigest, SMT_MAX_DEPTH,
|
||||||
SMT_MIN_DEPTH, SparseMerkleTree, Word,
|
SMT_MIN_DEPTH, SparseMerkleTree, Word,
|
||||||
};
|
};
|
||||||
|
use crate::merkle::{SparseMerklePath, SparseValuePath};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
|
@ -283,7 +283,10 @@ impl Iterator for SparseMerklePathIter<'_> {
|
||||||
self.next_depth = this_depth.get() - 1;
|
self.next_depth = this_depth.get() - 1;
|
||||||
|
|
||||||
// `this_depth` is only ever decreasing, so it can't ever exceed `self.path.depth()`.
|
// `this_depth` is only ever decreasing, so it can't ever exceed `self.path.depth()`.
|
||||||
let node = self.path.at_depth(this_depth).expect("current depth should never exceed the path depth");
|
let node = self
|
||||||
|
.path
|
||||||
|
.at_depth(this_depth)
|
||||||
|
.expect("current depth should never exceed the path depth");
|
||||||
Some(node)
|
Some(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,16 +712,20 @@ mod tests {
|
||||||
let index = NodeIndex::from(Smt::key_to_leaf_index(key));
|
let index = NodeIndex::from(Smt::key_to_leaf_index(key));
|
||||||
|
|
||||||
let control_path = tree.get_path(key);
|
let control_path = tree.get_path(key);
|
||||||
for (&control_node, proof_index) in iter::zip(&*control_path, index.proof_indices()) {
|
for (i, (&control_node, proof_index)) in
|
||||||
|
iter::zip(&*control_path, index.proof_indices()).enumerate()
|
||||||
|
{
|
||||||
let proof_node = tree.get_hash(proof_index);
|
let proof_node = tree.get_hash(proof_index);
|
||||||
assert_eq!(control_node, proof_node, "WHat");
|
assert_eq!(control_node, proof_node, "on iteration {i}");
|
||||||
}
|
}
|
||||||
|
|
||||||
let sparse_path =
|
let sparse_path =
|
||||||
SparseMerklePath::from_sized_iter(control_path.clone().into_iter()).unwrap();
|
SparseMerklePath::from_sized_iter(control_path.clone().into_iter()).unwrap();
|
||||||
for (sparse_node, proof_idx) in iter::zip(sparse_path.clone(), index.proof_indices()) {
|
for (i, (sparse_node, proof_idx)) in
|
||||||
|
iter::zip(sparse_path.clone(), index.proof_indices()).enumerate()
|
||||||
|
{
|
||||||
let proof_node = tree.get_hash(proof_idx);
|
let proof_node = tree.get_hash(proof_idx);
|
||||||
assert_eq!(sparse_node, proof_node, "WHat");
|
assert_eq!(sparse_node, proof_node, "on iteration {i}");
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(control_path.depth(), sparse_path.depth());
|
assert_eq!(control_path.depth(), sparse_path.depth());
|
||||||
|
|
Loading…
Add table
Reference in a new issue