Skip to content

Commit

Permalink
fix(tests): also match on the mapped errors
Browse files Browse the repository at this point in the history
The tests are setup to verify that a specific error is returned for a
specific failure condition. With the associated type in the trait, we
do not know the Error implementation type, and therefore map it
into a catch-all "Signing" variant. To not break the tests, we extract
the expected errors out of the enum variant when matching.
  • Loading branch information
oetyng committed Jun 19, 2021
1 parent f4a6ec5 commit df5c98c
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/dbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ mod tests {
dbc.transaction.inputs
);
}
Err(Error::UnrecognisedAuthority) => {
assert!(n_wrong_signer_sigs.coerce::<u8>() > 0);
assert!(dbc
.transaction_sigs
.values()
.any(|(k, _)| verifier.verify_known_key(k).is_err()));
}
Err(Error::DbcContentParentsDifferentFromTransactionInputs) => {
assert!(
n_add_random_parents.coerce::<u8>() > 0 || n_drop_parents.coerce::<u8>() > 0
Expand All @@ -407,6 +400,23 @@ mod tests {
Err(Error::FailedSignature) => {
assert_ne!(n_wrong_msg_sigs.coerce::<u8>(), 0);
}
Err(Error::Signing(s)) if s == Error::FailedSignature.to_string() => {
assert_ne!(n_wrong_msg_sigs.coerce::<u8>(), 0);
}
Err(Error::UnrecognisedAuthority) => {
assert!(n_wrong_signer_sigs.coerce::<u8>() > 0);
assert!(dbc
.transaction_sigs
.values()
.any(|(k, _)| verifier.verify_known_key(k).is_err()));
}
Err(Error::Signing(s)) if s == Error::UnrecognisedAuthority.to_string() => {
assert!(n_wrong_signer_sigs.coerce::<u8>() > 0);
assert!(dbc
.transaction_sigs
.values()
.any(|(k, _)| verifier.verify_known_key(k).is_err()));
}
res => panic!("Unexpected verification result {:?}", res),
}
}
Expand Down

0 comments on commit df5c98c

Please sign in to comment.