Update TestRandom
to vary list length
This commit is contained in:
parent
a425beb42a
commit
0f3b74b20e
@ -47,12 +47,25 @@ macro_rules! cached_tree_hash_tests {
|
||||
// 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());
|
||||
assert_eq!(
|
||||
hasher.tree_hash_root().unwrap(),
|
||||
original.tree_hash_root(),
|
||||
"Original hash failed."
|
||||
);
|
||||
|
||||
// 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());
|
||||
dbg!(&hasher.cache.chunk_modified);
|
||||
dbg!(hasher.cache.chunk_modified.len());
|
||||
dbg!(hasher.cache.chunk_index);
|
||||
dbg!(hasher.cache.schemas.len());
|
||||
dbg!(hasher.cache.schema_index);
|
||||
assert_eq!(
|
||||
hasher.tree_hash_root().unwrap(),
|
||||
modified.tree_hash_root(),
|
||||
"Modification hash failed"
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -44,11 +44,13 @@ where
|
||||
U: TestRandom<T>,
|
||||
{
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
vec![
|
||||
<U>::random_for_test(rng),
|
||||
<U>::random_for_test(rng),
|
||||
<U>::random_for_test(rng),
|
||||
]
|
||||
let mut output = vec![];
|
||||
|
||||
for _ in 0..(usize::random_for_test(rng) % 4) {
|
||||
output.push(<U>::random_for_test(rng));
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,11 @@ where
|
||||
U: TestRandom<T>,
|
||||
{
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
Vec::random_for_test(rng).into()
|
||||
TreeHashVector::from(vec![
|
||||
U::random_for_test(rng),
|
||||
U::random_for_test(rng),
|
||||
U::random_for_test(rng),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user