Skip to content
Snippets Groups Projects
Commit 648194e4 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

[ref] blockchain: remove expects

parent 56ad07ae
Branches
Tags
1 merge request!117WIP: Resolve "Add block checking (checking all rules of the unit protocol)"
...@@ -92,7 +92,7 @@ pub fn verify_block_validity<W: WebOfTrust>( ...@@ -92,7 +92,7 @@ pub fn verify_block_validity<W: WebOfTrust>(
if previous_block_opt.is_none() { if previous_block_opt.is_none() {
return Err(BlockError::InvalidBlock(InvalidBlockError::NoPreviousBlock)); return Err(BlockError::InvalidBlock(InvalidBlockError::NoPreviousBlock));
} }
let previous_block = previous_block_opt.expect("safe unwrap"); let previous_block = previous_block_opt.unwrap_or_else(|| panic!(dbg!("dev error")));
// Block version must not decrease // Block version must not decrease
if previous_block.version > block.version { if previous_block.version > block.version {
...@@ -110,12 +110,13 @@ pub fn verify_block_validity<W: WebOfTrust>( ...@@ -110,12 +110,13 @@ pub fn verify_block_validity<W: WebOfTrust>(
} }
// BR_G100 - issuer is member // BR_G100 - issuer is member
match readers::identity::get_identity(identities_db, &block.issuers[0])? if let entities::identity::DALIdentityState::Member(_) =
.expect("safe unwrap") readers::identity::get_identity(identities_db, &block.issuers[0])?
.unwrap_or_else(|| panic!(dbg!("dev error")))
.state .state
{ {
entities::identity::DALIdentityState::Member(_) => {} } else {
_ => return Err(invalid_rule_error(InvalidRuleError::NotMemberIssuer)), return Err(invalid_rule_error(InvalidRuleError::NotMemberIssuer));
} }
// BR_G04 - issuers count // BR_G04 - issuers count
...@@ -154,15 +155,15 @@ mod tests { ...@@ -154,15 +155,15 @@ mod tests {
use durs_blockchain_dal::entities::identity::*; use durs_blockchain_dal::entities::identity::*;
#[test] #[test]
fn test_verify_blocks() { fn test_verify_blocks() -> Result<(), BlockError> {
let blocks_dbs = BlocksV10DBs::open(None); let blocks_dbs = BlocksV10DBs::open(None);
let wot_dbs = WotsV10DBs::open(None); let wot_dbs = WotsV10DBs::open(None);
let wot_index: HashMap<PubKey, NodeId> = HashMap::new(); let wot_index: HashMap<PubKey, NodeId> = HashMap::new();
let idty_a = identity::gen_mock_idty(pubkey('A'), BlockId(0)); let idty_a = identity::gen_mock_idty(pubkey('A'), BlockNumber(0));
let pubkey_a = idty_a.issuers()[0]; let pubkey_a = idty_a.issuers()[0];
let idty_b = identity::gen_mock_idty(pubkey('B'), BlockId(0)); let idty_b = identity::gen_mock_idty(pubkey('B'), BlockNumber(0));
let pubkey_b = idty_b.issuers()[0]; let pubkey_b = idty_b.issuers()[0];
let mut blocks = gen_empty_timed_blocks(2, 300); let mut blocks = gen_empty_timed_blocks(2, 300);
...@@ -173,7 +174,7 @@ mod tests { ...@@ -173,7 +174,7 @@ mod tests {
blocks[0].identities.push(idty_a.clone()); blocks[0].identities.push(idty_a.clone());
blocks[0].identities.push(idty_b.clone()); blocks[0].identities.push(idty_b.clone());
verify_genesis_block_validity(&blocks[0]).expect("Fail to valid genesis block"); verify_genesis_block_validity(&blocks[0])?;
blocks_dbs blocks_dbs
.blockchain_db .blockchain_db
...@@ -238,7 +239,8 @@ mod tests { ...@@ -238,7 +239,8 @@ mod tests {
&wot_dbs.certs_db, &wot_dbs.certs_db,
&wot_index, &wot_index,
&wot_dbs.wot_db, &wot_dbs.wot_db,
) )?;
.expect("Fail to valid block");
Ok(())
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment