Merge rust-bitcoin/rust-bitcoin#4473: Assert num op error
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: ACKa7d059151e
apoelstra: ACK a7d059151eb47bf4202302604309c95c0d66371d; successfully ran local tests Tree-SHA512: e1b3eba640de2e4f98e075270fd797582601c541e1eebef2959a4e609bf51129e8ad38baab1253b40474c39f82ee4802658ec545cc5c3590637f2ddb13f873f7
This commit is contained in:
commit
e43c574146
|
@ -345,8 +345,11 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fee_wu() {
|
fn fee_wu() {
|
||||||
let fee_overflow = FeeRate::from_sat_per_kwu(10).to_fee(Weight::MAX);
|
let operation = FeeRate::from_sat_per_kwu(10)
|
||||||
assert!(fee_overflow.is_error());
|
.to_fee(Weight::MAX)
|
||||||
|
.unwrap_err()
|
||||||
|
.operation();
|
||||||
|
assert!(operation.is_multiplication());
|
||||||
|
|
||||||
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
|
let fee_rate = FeeRate::from_sat_per_vb(2).unwrap();
|
||||||
let weight = Weight::from_vb(3).unwrap();
|
let weight = Weight::from_vb(3).unwrap();
|
||||||
|
|
|
@ -254,6 +254,18 @@ impl MathOp {
|
||||||
|
|
||||||
/// Returns `true` if this operation error'ed due to division by zero.
|
/// Returns `true` if this operation error'ed due to division by zero.
|
||||||
pub fn is_div_by_zero(self) -> bool { !self.is_overflow() }
|
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 {
|
impl fmt::Display for MathOp {
|
||||||
|
|
Loading…
Reference in New Issue