Fix chunk index bug with structs
This commit is contained in:
parent
d3309b9f7e
commit
a425beb42a
@ -44,16 +44,14 @@ macro_rules! cached_tree_hash_tests {
|
||||
|
||||
let mut rng = XorShiftRng::from_seed([42; 16]);
|
||||
|
||||
// Test the original hash
|
||||
let original = $type::random_for_test(&mut rng);
|
||||
|
||||
let mut hasher = cached_tree_hash::CachedTreeHasher::new(&original).unwrap();
|
||||
|
||||
assert_eq!(hasher.tree_hash_root().unwrap(), original.tree_hash_root());
|
||||
|
||||
// Test the updated hash
|
||||
let modified = $type::random_for_test(&mut rng);
|
||||
|
||||
hasher.update(&modified).unwrap();
|
||||
|
||||
assert_eq!(hasher.tree_hash_root().unwrap(), modified.tree_hash_root());
|
||||
}
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ pub trait CachedTreeHash<Item>: TreeHash {
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct CachedTreeHasher {
|
||||
cache: TreeHashCache,
|
||||
pub cache: TreeHashCache,
|
||||
}
|
||||
|
||||
impl CachedTreeHasher {
|
||||
|
@ -423,6 +423,45 @@ fn test_struct_with_two_vecs() {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, TreeHash, CachedTreeHash)]
|
||||
pub struct U64AndTwoStructs {
|
||||
pub a: u64,
|
||||
pub b: Inner,
|
||||
pub c: Inner,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_u64_and_two_structs() {
|
||||
let inners = get_inners();
|
||||
|
||||
let variants = vec![
|
||||
U64AndTwoStructs {
|
||||
a: 99,
|
||||
b: inners[0].clone(),
|
||||
c: inners[1].clone(),
|
||||
},
|
||||
U64AndTwoStructs {
|
||||
a: 10,
|
||||
b: inners[2].clone(),
|
||||
c: inners[3].clone(),
|
||||
},
|
||||
U64AndTwoStructs {
|
||||
a: 0,
|
||||
b: inners[1].clone(),
|
||||
c: inners[1].clone(),
|
||||
},
|
||||
U64AndTwoStructs {
|
||||
a: 0,
|
||||
b: inners[1].clone(),
|
||||
c: inners[1].clone(),
|
||||
},
|
||||
];
|
||||
|
||||
for v in &variants {
|
||||
test_routine(v.clone(), variants.clone());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, TreeHash, CachedTreeHash)]
|
||||
pub struct Inner {
|
||||
pub a: u64,
|
||||
|
@ -102,6 +102,8 @@ pub fn subtree_derive(input: TokenStream) -> TokenStream {
|
||||
// Iterate through the internal nodes, updating them if their children have changed.
|
||||
cache.update_internal_nodes(&overlay)?;
|
||||
|
||||
cache.chunk_index = overlay.next_node();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user