Improve some test errors (#2643)

* Improve error logging in rejection_restores_internal_state

* Summarise history tree peaks in debug output

Co-authored-by: Conrado Gouvea <conrado@zfnd.org>
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
This commit is contained in:
teor 2021-08-20 05:44:02 +10:00 committed by GitHub
parent f6416ff8ee
commit 2ec6ae364f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -14,6 +14,7 @@ use thiserror::Error;
use crate::{
block::{Block, ChainHistoryMmrRootHash, Height},
fmt::SummaryDebug,
orchard,
parameters::{Network, NetworkUpgrade},
primitives::zcash_history::{Entry, Tree, V1 as PreOrchard, V2 as OrchardOnward},
@ -66,7 +67,7 @@ pub struct NonEmptyHistoryTree {
size: u32,
/// The peaks of the tree, indexed by their position in the array representation
/// of the tree. This can be persisted to save the tree.
peaks: BTreeMap<u32, Entry>,
peaks: SummaryDebug<BTreeMap<u32, Entry>>,
/// The height of the most recent block added to the tree.
current_height: Height,
}
@ -117,7 +118,7 @@ impl NonEmptyHistoryTree {
network_upgrade,
inner,
size,
peaks,
peaks: peaks.into(),
current_height,
})
}
@ -171,7 +172,7 @@ impl NonEmptyHistoryTree {
network_upgrade,
inner: tree,
size: 1,
peaks,
peaks: peaks.into(),
current_height: height,
})
}

View File

@ -182,12 +182,23 @@ fn rejection_restores_internal_state() -> Result<()> {
prop_assert!(state.eq_internal_state(&state));
if let Some(first_block) = chain.next() {
state.commit_new_chain(first_block, &finalized_state)?;
let result = state.commit_new_chain(first_block, &finalized_state);
prop_assert_eq!(
result,
Ok(()),
"PreparedChain should generate a valid first block"
);
prop_assert!(state.eq_internal_state(&state));
}
for block in chain {
state.commit_block(block, &finalized_state)?;
let result = state.commit_block(block.clone(), &finalized_state);
prop_assert_eq!(
result,
Ok(()),
"PreparedChain should generate a valid block at {:?}",
block.height,
);
prop_assert!(state.eq_internal_state(&state));
}