a7d059151e Assert error type (yancy)
2f7e74da45 Add MathOp helper methods (yancy)

Pull request description:

  Follow up from https://github.com/rust-bitcoin/rust-bitcoin/pull/4428 to assert the error type which I agree improves the test.

  Added some helper functions since it can be nice to see what type of overflow happened.

ACKs for top commit:
  tcharding:
    ACK a7d059151e
  apoelstra:
    ACK a7d059151eb47bf4202302604309c95c0d66371d; successfully ran local tests

Tree-SHA512: e1b3eba640de2e4f98e075270fd797582601c541e1eebef2959a4e609bf51129e8ad38baab1253b40474c39f82ee4802658ec545cc5c3590637f2ddb13f873f7
This commit is contained in:
merge-script 2025-05-09 15:47:38 +00:00
commit e43c574146
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 17 additions and 2 deletions

View File

@ -345,8 +345,11 @@ mod tests {
#[test]
fn fee_wu() {
let fee_overflow = FeeRate::from_sat_per_kwu(10).to_fee(Weight::MAX);
assert!(fee_overflow.is_error());
let operation = FeeRate::from_sat_per_kwu(10)
.to_fee(Weight::MAX)
.unwrap_err()
.operation();
assert!(operation.is_multiplication());
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
let weight = Weight::from_vb(3).unwrap();

View File

@ -254,6 +254,18 @@ impl MathOp {
/// Returns `true` if this operation error'ed due to division by zero.
pub fn is_div_by_zero(self) -> bool { !self.is_overflow() }
/// Returns `true` if this operation error'ed due to addition.
pub fn is_addition(self) -> bool { self == MathOp::Add }
/// Returns `true` if this operation error'ed due to subtraction.
pub fn is_subtraction(self) -> bool { self == MathOp::Sub }
/// Returns `true` if this operation error'ed due to multiplication.
pub fn is_multiplication(self) -> bool { self == MathOp::Mul }
/// Returns `true` if this operation error'ed due to negation.
pub fn is_negation(self) -> bool { self == MathOp::Neg }
}
impl fmt::Display for MathOp {