Introduce failing test
This commit is contained in:
parent
2f69185ccb
commit
ec43a4085c
@ -19,9 +19,13 @@ impl CachedTreeHashSubTree<u64> for u64 {
|
|||||||
let leaf = merkleize(self.to_le_bytes().to_vec());
|
let leaf = merkleize(self.to_le_bytes().to_vec());
|
||||||
cache.maybe_update_chunk(cache.chunk_index, &leaf)?;
|
cache.maybe_update_chunk(cache.chunk_index, &leaf)?;
|
||||||
|
|
||||||
|
dbg!(cache.overlay_index);
|
||||||
|
|
||||||
cache.chunk_index += 1;
|
cache.chunk_index += 1;
|
||||||
cache.overlay_index += 1;
|
cache.overlay_index += 1;
|
||||||
|
|
||||||
|
dbg!(cache.overlay_index);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,11 @@ where
|
|||||||
let new_overlay = BTreeOverlay::new(self, cache.chunk_index)?;
|
let new_overlay = BTreeOverlay::new(self, cache.chunk_index)?;
|
||||||
let old_overlay = cache.get_overlay(cache.overlay_index, cache.chunk_index)?;
|
let old_overlay = cache.get_overlay(cache.overlay_index, cache.chunk_index)?;
|
||||||
|
|
||||||
|
dbg!(cache.overlay_index);
|
||||||
|
|
||||||
|
// dbg!(&new_overlay);
|
||||||
|
// dbg!(&old_overlay);
|
||||||
|
|
||||||
// If the merkle tree required to represent the new list is of a different size to the one
|
// If the merkle tree required to represent the new list is of a different size to the one
|
||||||
// required for the previous list, then update our cache.
|
// required for the previous list, then update our cache.
|
||||||
//
|
//
|
||||||
@ -106,7 +111,6 @@ where
|
|||||||
TreeHashType::Container | TreeHashType::List | TreeHashType::Vector => {
|
TreeHashType::Container | TreeHashType::List | TreeHashType::Vector => {
|
||||||
let mut local_overlay_index = cache.overlay_index;
|
let mut local_overlay_index = cache.overlay_index;
|
||||||
|
|
||||||
|
|
||||||
for i in 0..new_overlay.num_leaf_nodes() {
|
for i in 0..new_overlay.num_leaf_nodes() {
|
||||||
cache.overlay_index = local_overlay_index;
|
cache.overlay_index = local_overlay_index;
|
||||||
|
|
||||||
@ -122,7 +126,6 @@ where
|
|||||||
(Some(_old), Some(new)) => {
|
(Some(_old), Some(new)) => {
|
||||||
cache.chunk_index = new.start;
|
cache.chunk_index = new.start;
|
||||||
|
|
||||||
|
|
||||||
self[i].update_tree_hash_cache(cache)?;
|
self[i].update_tree_hash_cache(cache)?;
|
||||||
|
|
||||||
local_overlay_index += 1;
|
local_overlay_index += 1;
|
||||||
@ -188,6 +191,8 @@ where
|
|||||||
|
|
||||||
cache.chunk_index = new_overlay.next_node();
|
cache.chunk_index = new_overlay.next_node();
|
||||||
|
|
||||||
|
dbg!(&cache.overlay_index);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,47 @@ fn test_nested_list_of_u64() {
|
|||||||
vec![],
|
vec![],
|
||||||
vec![vec![1], vec![2], vec![3]],
|
vec![vec![1], vec![2], vec![3]],
|
||||||
vec![vec![1, 2, 3, 4, 5, 6], vec![1, 2, 3, 4, 5, 6, 7]],
|
vec![vec![1, 2, 3, 4, 5, 6], vec![1, 2, 3, 4, 5, 6, 7]],
|
||||||
|
vec![vec![], vec![], vec![]],
|
||||||
|
vec![vec![0, 0, 0], vec![0], vec![0]],
|
||||||
|
];
|
||||||
|
|
||||||
|
test_routine(original, modified);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_list_of_struct_with_vec() {
|
||||||
|
let a = StructWithVec {
|
||||||
|
a: 42,
|
||||||
|
b: Inner {
|
||||||
|
a: 12,
|
||||||
|
b: 13,
|
||||||
|
c: 14,
|
||||||
|
d: 15,
|
||||||
|
},
|
||||||
|
c: vec![1, 2, 3, 4, 5],
|
||||||
|
};
|
||||||
|
let b = StructWithVec {
|
||||||
|
c: vec![],
|
||||||
|
..a.clone()
|
||||||
|
};
|
||||||
|
let c = StructWithVec {
|
||||||
|
b: Inner {
|
||||||
|
a: 99,
|
||||||
|
b: 100,
|
||||||
|
c: 101,
|
||||||
|
d: 102,
|
||||||
|
},
|
||||||
|
..a.clone()
|
||||||
|
};
|
||||||
|
let d = StructWithVec { a: 0, ..a.clone() };
|
||||||
|
|
||||||
|
let original: Vec<StructWithVec> = vec![a.clone(), c.clone()];
|
||||||
|
|
||||||
|
let modified = vec![
|
||||||
|
vec![a.clone(), c.clone()],
|
||||||
|
// vec![a.clone(), b.clone(), c.clone(), d.clone()],
|
||||||
|
// vec![b.clone(), a.clone(), c.clone(), d.clone()],
|
||||||
|
vec![],
|
||||||
];
|
];
|
||||||
|
|
||||||
test_routine(original, modified);
|
test_routine(original, modified);
|
||||||
@ -255,6 +296,8 @@ impl CachedTreeHashSubTree<Inner> for Inner {
|
|||||||
self.c.update_tree_hash_cache(cache)?;
|
self.c.update_tree_hash_cache(cache)?;
|
||||||
self.d.update_tree_hash_cache(cache)?;
|
self.d.update_tree_hash_cache(cache)?;
|
||||||
|
|
||||||
|
dbg!(cache.overlay_index);
|
||||||
|
|
||||||
// Iterate through the internal nodes, updating them if their children have changed.
|
// Iterate through the internal nodes, updating them if their children have changed.
|
||||||
cache.update_internal_nodes(&overlay)?;
|
cache.update_internal_nodes(&overlay)?;
|
||||||
|
|
||||||
|
@ -85,6 +85,8 @@ pub fn subtree_derive(input: TokenStream) -> TokenStream {
|
|||||||
fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> {
|
fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> {
|
||||||
let overlay = BTreeOverlay::new(self, cache.chunk_index)?;
|
let overlay = BTreeOverlay::new(self, cache.chunk_index)?;
|
||||||
|
|
||||||
|
println!("start derive - cache.overlay_index: {}", cache.overlay_index);
|
||||||
|
|
||||||
// Skip the chunk index to the first leaf node of this struct.
|
// Skip the chunk index to the first leaf node of this struct.
|
||||||
cache.chunk_index = overlay.first_leaf_node();
|
cache.chunk_index = overlay.first_leaf_node();
|
||||||
// Skip the overlay index to the first leaf node of this struct.
|
// Skip the overlay index to the first leaf node of this struct.
|
||||||
@ -95,6 +97,8 @@ pub fn subtree_derive(input: TokenStream) -> TokenStream {
|
|||||||
self.#idents_c.update_tree_hash_cache(cache)?;
|
self.#idents_c.update_tree_hash_cache(cache)?;
|
||||||
)*
|
)*
|
||||||
|
|
||||||
|
println!("end derive - cache.overlay_index: {}", cache.overlay_index);
|
||||||
|
|
||||||
// Iterate through the internal nodes, updating them if their children have changed.
|
// Iterate through the internal nodes, updating them if their children have changed.
|
||||||
cache.update_internal_nodes(&overlay)?;
|
cache.update_internal_nodes(&overlay)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user