From 019091f1b8a513fdeb0a0492e3affac18fac6a06 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 1 Oct 2022 20:50:45 +0200 Subject: [PATCH 1/2] Fix Weight::is_zero Signed-off-by: Oliver Tale-Yazdi --- primitives/weights/src/weight_v2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/weights/src/weight_v2.rs b/primitives/weights/src/weight_v2.rs index a8eaf79a28711..1eccd8a19f81c 100644 --- a/primitives/weights/src/weight_v2.rs +++ b/primitives/weights/src/weight_v2.rs @@ -318,7 +318,7 @@ impl Zero for Weight { } fn is_zero(&self) -> bool { - self.ref_time == 0 + self == &Self::zero() } } From 11d230c1a3843eb384e083fb3aa15aa6a082c796 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Sat, 1 Oct 2022 21:04:39 +0200 Subject: [PATCH 2/2] Add test Signed-off-by: Oliver Tale-Yazdi --- primitives/weights/src/weight_v2.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/primitives/weights/src/weight_v2.rs b/primitives/weights/src/weight_v2.rs index 1eccd8a19f81c..8596a782c1fa7 100644 --- a/primitives/weights/src/weight_v2.rs +++ b/primitives/weights/src/weight_v2.rs @@ -447,3 +447,16 @@ impl SubAssign for Weight { }; } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn is_zero_works() { + assert!(Weight::zero().is_zero()); + assert!(!Weight::from_components(1, 0).is_zero()); + assert!(!Weight::from_components(0, 1).is_zero()); + assert!(!Weight::MAX.is_zero()); + } +}