Fix tree hash bug
This commit is contained in:
parent
7c64a5a21b
commit
2f69185ccb
@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use std::cmp::min;
|
||||
|
||||
/// New vec is bigger than old vec.
|
||||
pub fn grow_merkle_cache(
|
||||
@ -100,8 +101,15 @@ pub fn shrink_merkle_cache(
|
||||
)
|
||||
};
|
||||
|
||||
to_byte_slice.copy_from_slice(from_byte_slice.get(0..to_byte_slice.len())?);
|
||||
to_flag_slice.copy_from_slice(from_flag_slice.get(0..to_flag_slice.len())?);
|
||||
let num_bytes = min(from_byte_slice.len(), to_byte_slice.len());
|
||||
let num_flags = min(from_flag_slice.len(), to_flag_slice.len());
|
||||
|
||||
to_byte_slice
|
||||
.get_mut(0..num_bytes)?
|
||||
.copy_from_slice(from_byte_slice.get(0..num_bytes)?);
|
||||
to_flag_slice
|
||||
.get_mut(0..num_flags)?
|
||||
.copy_from_slice(from_flag_slice.get(0..num_flags)?);
|
||||
}
|
||||
|
||||
Some((bytes, flags))
|
||||
|
@ -163,7 +163,7 @@ fn test_vec() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nested_list() {
|
||||
fn test_nested_list_of_u64() {
|
||||
let original: Vec<Vec<u64>> = vec![vec![1]];
|
||||
|
||||
let modified = vec![
|
||||
@ -175,6 +175,8 @@ fn test_nested_list() {
|
||||
vec![],
|
||||
vec![vec![1, 2], vec![3], vec![4, 5, 6, 7, 8]],
|
||||
vec![],
|
||||
vec![vec![1], vec![2], vec![3]],
|
||||
vec![vec![1, 2, 3, 4, 5, 6], vec![1, 2, 3, 4, 5, 6, 7]],
|
||||
];
|
||||
|
||||
test_routine(original, modified);
|
||||
|
Loading…
Reference in New Issue
Block a user