Merge bitcoindevkit/bdk#821: [#344] Add assert_matches

14bc9c0e35 [#344] Add assert_matches Replace assert!(matches! with assert_matches! everywhere Convert assert! to assert_eq! in 2 places (Jeremy Mawson)

Pull request description:

  [#344] Add assert_matches

ACKs for top commit:
  notmandatory:
    ACK 14bc9c0e35
  danielabrozzoni:
    utACK 14bc9c0e35

Tree-SHA512: 730fed9c8c22b0725b1337140636def1a059ac78e4ae16f1abd4c7f379628d9329ccd3ed28e4cbab58e9ace5f349333cb5fa83ec43d507d7a7609601efebc9e1
This commit is contained in:
Steve Myers
2022-12-26 13:38:11 -08:00
13 changed files with 152 additions and 228 deletions

View File

@@ -1851,6 +1851,7 @@ pub fn get_funded_wallet(
#[cfg(test)]
pub(crate) mod test {
use assert_matches::assert_matches;
use bitcoin::{util::psbt, Network, PackedLockTime, Sequence};
use crate::database::Database;
@@ -4425,11 +4426,9 @@ pub(crate) mod test {
result.is_err(),
"Signing should have failed because the TX uses non-standard sighashes"
);
assert!(
matches!(
result.unwrap_err(),
Error::Signer(SignerError::NonStandardSighash)
),
assert_matches!(
result,
Err(Error::Signer(SignerError::NonStandardSighash)),
"Signing failed with the wrong error type"
);
@@ -4912,16 +4911,10 @@ pub(crate) mod test {
..Default::default()
},
);
assert!(
result.is_err(),
"Signing should have failed because the witness_utxo is missing"
);
assert!(
matches!(
result.unwrap_err(),
Error::Signer(SignerError::MissingWitnessUtxo)
),
"Signing failed with the wrong error type"
assert_matches!(
result,
Err(Error::Signer(SignerError::MissingWitnessUtxo)),
"Signing should have failed with the correct error because the witness_utxo is missing"
);
// restore the witness_utxo
@@ -4935,9 +4928,9 @@ pub(crate) mod test {
},
);
assert!(result.is_ok(), "Signing should have worked");
assert!(
result.unwrap(),
assert_matches!(
result,
Ok(true),
"Should finalize the input since we can produce signatures"
);
}
@@ -5262,11 +5255,9 @@ pub(crate) mod test {
result.is_err(),
"Signing should have failed because the TX uses non-standard sighashes"
);
assert!(
matches!(
result.unwrap_err(),
Error::Signer(SignerError::NonStandardSighash)
),
assert_matches!(
result,
Err(Error::Signer(SignerError::NonStandardSighash)),
"Signing failed with the wrong error type"
);
@@ -5282,11 +5273,9 @@ pub(crate) mod test {
result.is_err(),
"Signing should have failed because the witness_utxo is missing"
);
assert!(
matches!(
result.unwrap_err(),
Error::Signer(SignerError::MissingWitnessUtxo)
),
assert_matches!(
result,
Err(Error::Signer(SignerError::MissingWitnessUtxo)),
"Signing failed with the wrong error type"
);
@@ -5367,26 +5356,26 @@ pub(crate) mod test {
builder
.add_recipient(addr.script_pubkey(), balance.immature / 2)
.current_height(confirmation_time);
assert!(matches!(
builder.finish().unwrap_err(),
Error::InsufficientFunds {
assert_matches!(
builder.finish(),
Err(Error::InsufficientFunds {
needed: _,
available: 0
}
));
})
);
// Still unspendable...
let mut builder = wallet.build_tx();
builder
.add_recipient(addr.script_pubkey(), balance.immature / 2)
.current_height(not_yet_mature_time);
assert!(matches!(
builder.finish().unwrap_err(),
Error::InsufficientFunds {
assert_matches!(
builder.finish(),
Err(Error::InsufficientFunds {
needed: _,
available: 0
}
));
})
);
// ...Now the coinbase is mature :)
let sync_time = SyncTime {
@@ -5428,10 +5417,7 @@ pub(crate) mod test {
builder.add_recipient(addr.script_pubkey(), 0);
assert!(matches!(
builder.finish().unwrap_err(),
Error::OutputBelowDustLimit(0)
));
assert_matches!(builder.finish(), Err(Error::OutputBelowDustLimit(0)));
let mut builder = wallet.build_tx();