Skip to content

Commit e43c574

Browse files
committed
Merge rust-bitcoin#4473: Assert num op error
a7d0591 Assert error type (yancy) 2f7e74d Add MathOp helper methods (yancy) Pull request description: Follow up from rust-bitcoin#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 a7d0591 apoelstra: ACK a7d0591; successfully ran local tests Tree-SHA512: e1b3eba640de2e4f98e075270fd797582601c541e1eebef2959a4e609bf51129e8ad38baab1253b40474c39f82ee4802658ec545cc5c3590637f2ddb13f873f7
2 parents 79a6840 + a7d0591 commit e43c574

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

units/src/fee.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,11 @@ mod tests {
345345

346346
#[test]
347347
fn fee_wu() {
348-
let fee_overflow = FeeRate::from_sat_per_kwu(10).to_fee(Weight::MAX);
349-
assert!(fee_overflow.is_error());
348+
let operation = FeeRate::from_sat_per_kwu(10)
349+
.to_fee(Weight::MAX)
350+
.unwrap_err()
351+
.operation();
352+
assert!(operation.is_multiplication());
350353

351354
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
352355
let weight = Weight::from_vb(3).unwrap();

units/src/result.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ impl MathOp {
254254

255255
/// Returns `true` if this operation error'ed due to division by zero.
256256
pub fn is_div_by_zero(self) -> bool { !self.is_overflow() }
257+
258+
/// Returns `true` if this operation error'ed due to addition.
259+
pub fn is_addition(self) -> bool { self == MathOp::Add }
260+
261+
/// Returns `true` if this operation error'ed due to subtraction.
262+
pub fn is_subtraction(self) -> bool { self == MathOp::Sub }
263+
264+
/// Returns `true` if this operation error'ed due to multiplication.
265+
pub fn is_multiplication(self) -> bool { self == MathOp::Mul }
266+
267+
/// Returns `true` if this operation error'ed due to negation.
268+
pub fn is_negation(self) -> bool { self == MathOp::Neg }
257269
}
258270

259271
impl fmt::Display for MathOp {

0 commit comments

Comments
 (0)