Skip to content

Commit

Permalink
feat(errors)!: additional context information to Error::SpentProofInp…
Browse files Browse the repository at this point in the history
…utLenMismatch
  • Loading branch information
bochaco committed Jun 16, 2022
1 parent c185297 commit 3e291d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/dbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,10 @@ pub(crate) mod tests {
assert_eq!(dbc_amount, amount);
assert_eq!(extra_output_amount.coerce::<u8>(), 0);
}
Err(Error::SpentProofInputLenMismatch) => {
Err(Error::SpentProofInputLenMismatch { current, expected }) => {
assert_ne!(dbc.spent_proofs.len(), dbc.transaction.mlsags.len());
assert_eq!(dbc.spent_proofs.len(), current);
assert_eq!(dbc.transaction.mlsags.len(), expected);
}
Err(Error::SpentProofInputKeyImageMismatch) => {
assert!(n_extra_input_sigs.coerce::<u8>() > 0);
Expand Down
6 changes: 4 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ pub enum Error {
#[error("public key is not unique across all transaction outputs")]
PublicKeyNotUniqueAcrossOutputs,

#[error("The number of SpentProof does not match the number of input MlsagSignature")]
SpentProofInputLenMismatch,
#[error(
"The number of SpentProof ({current}) does not match the number of input MlsagSignature ({expected})"
)]
SpentProofInputLenMismatch { current: usize, expected: usize },

#[error("A SpentProof KeyImage does not match an MlsagSignature KeyImage")]
SpentProofInputKeyImageMismatch,
Expand Down
3 changes: 2 additions & 1 deletion src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ mod tests {
// a couple places.
let check_error = |error: Error| -> Result<()> {
match error {
Error::SpentProofInputLenMismatch => {
Error::SpentProofInputLenMismatch { expected, .. } => {
assert!(!invalid_spent_proofs.is_empty());
assert_eq!(inputs_dbcs.len(), expected);
}
Error::SpentProofInputKeyImageMismatch => {
assert!(!invalid_spent_proofs.is_empty());
Expand Down
5 changes: 4 additions & 1 deletion src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl TransactionVerifier {
spent_proofs: &BTreeSet<SpentProof>,
) -> Result<(), Error> {
if spent_proofs.len() != transaction.mlsags.len() {
return Err(Error::SpentProofInputLenMismatch);
return Err(Error::SpentProofInputLenMismatch {
current: spent_proofs.len(),
expected: transaction.mlsags.len(),
});
}

let transaction_hash = Hash::from(transaction.hash());
Expand Down

0 comments on commit 3e291d7

Please sign in to comment.