cleanup path fn and add test coverage (#1201)
This commit is contained in:
@@ -712,14 +712,11 @@ pub fn is_left_sibling(pos: u64) -> bool {
|
||||
/// The size (and therefore the set of peaks) of the MMR
|
||||
/// is defined by last_pos.
|
||||
pub fn path(pos: u64, last_pos: u64) -> Vec<u64> {
|
||||
let mut path = vec![pos];
|
||||
let mut path = vec![];
|
||||
let mut current = pos;
|
||||
while current + 1 <= last_pos {
|
||||
while current <= last_pos {
|
||||
path.push(current);
|
||||
let (parent, _) = family(current);
|
||||
if parent > last_pos {
|
||||
break;
|
||||
}
|
||||
path.push(parent);
|
||||
current = parent;
|
||||
}
|
||||
path
|
||||
|
||||
@@ -97,6 +97,14 @@ fn various_families() {
|
||||
assert_eq!(pmmr::family(1_000), (1_001, 997));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_paths() {
|
||||
assert_eq!(pmmr::path(1, 1), [1]);
|
||||
assert_eq!(pmmr::path(1, 3), [1, 3]);
|
||||
assert_eq!(pmmr::path(2, 3), [2, 3]);
|
||||
assert_eq!(pmmr::path(4, 16), [4, 6, 7, 15]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_left_sibling() {
|
||||
assert_eq!(pmmr::is_left_sibling(1), true);
|
||||
|
||||
Reference in New Issue
Block a user