Skip to content
Snippets Groups Projects

[ref+tests] crypto: improve error handling & improve test coverage

Merged Éloïs requested to merge elois/crypto into dev
27 files
+ 1206
276
Compare changes
  • Side-by-side
  • Inline
Files
27
@@ -15,31 +15,25 @@
@@ -15,31 +15,25 @@
//! Verify block inner hash and block hash
//! Verify block inner hash and block hash
use crate::VerifyBlockHashsError;
use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait, VerifyBlockHashError};
use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait};
/// Verify block hashs
/// Verify block hashs
pub fn verify_block_hashs(block_doc: &BlockDocument) -> Result<(), VerifyBlockHashsError> {
pub fn verify_block_hashs(block_doc: &BlockDocument) -> Result<(), VerifyBlockHashError> {
trace!("complete_block #{}...", block_doc.number());
trace!("complete_block #{}...", block_doc.number());
if block_doc.verify_inner_hash() {
match block_doc.verify_inner_hash() {
if block_doc.verify_hash() {
Ok(()) => block_doc.verify_hash().map_err(|e| {
trace!("Succes to verify_block_hashs #{}", block_doc.number().0);
Ok(())
} else {
warn!("BlockchainModule : Refuse Bloc : invalid hash !");
warn!("BlockchainModule : Refuse Bloc : invalid hash !");
Err(VerifyBlockHashsError::InvalidHash(
e
block_doc.number(),
}),
block_doc.hash(),
Err(e) => {
))
warn!("BlockchainModule : Refuse Bloc : invalid inner hash !");
 
warn!("BlockDocument=\"{:?}\"", block_doc);
 
warn!(
 
"BlockInnerFormat=\"{}\"",
 
block_doc.generate_compact_inner_text()
 
);
 
Err(e)
}
}
} else {
warn!("BlockchainModule : Refuse Bloc : invalid inner hash !");
warn!("BlockDocument=\"{:?}\"", block_doc);
warn!(
"BlockInnerFormat=\"{}\"",
block_doc.generate_compact_inner_text()
);
Err(VerifyBlockHashsError::InvalidInnerHash())
}
}
}
}
Loading