Fix weight subtract bug
This commit is contained in:
parent
9ffbbb8efb
commit
b311e96603
|
@ -86,7 +86,7 @@ impl Weight {
|
||||||
///
|
///
|
||||||
/// Computes `self - rhs` returning `None` if overflow occurred.
|
/// Computes `self - rhs` returning `None` if overflow occurred.
|
||||||
pub fn checked_sub(self, rhs: Self) -> Option<Self> {
|
pub fn checked_sub(self, rhs: Self) -> Option<Self> {
|
||||||
self.0.checked_add(rhs.0).map(Self)
|
self.0.checked_sub(rhs.0).map(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checked multiplication.
|
/// Checked multiplication.
|
||||||
|
@ -115,6 +115,20 @@ impl fmt::Display for Weight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checked_sub_test(){
|
||||||
|
let result = Weight(1).checked_sub(Weight(1)).expect("expected weight unit");
|
||||||
|
assert_eq!(Weight::ZERO, result);
|
||||||
|
|
||||||
|
let result = Weight::MIN.checked_sub(Weight(1));
|
||||||
|
assert_eq!(None, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Weight> for u64 {
|
impl From<Weight> for u64 {
|
||||||
fn from(value: Weight) -> Self {
|
fn from(value: Weight) -> Self {
|
||||||
value.to_wu()
|
value.to_wu()
|
||||||
|
|
Loading…
Reference in New Issue