From cf49c176001474327efc47a4bd8b67f966c882ed Mon Sep 17 00:00:00 2001 From: James Hiew Date: Thu, 1 Dec 2022 14:21:01 +0000 Subject: [PATCH] Add Amount::is_zero fn --- core/src/types/token.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/types/token.rs b/core/src/types/token.rs index 10c690bb065..add87b91af2 100644 --- a/core/src/types/token.rs +++ b/core/src/types/token.rs @@ -42,6 +42,11 @@ pub const SCALE: u64 = 1_000_000; pub type Change = i128; impl Amount { + /// Returns whether an amount is zero. + pub fn is_zero(&self) -> bool { + self.micro == 0 + } + /// Get the amount as a [`Change`] pub fn change(&self) -> Change { self.micro as Change @@ -484,6 +489,15 @@ mod tests { let zero = Amount::from(0); assert_eq!("0", zero.to_string()); } + + #[test] + fn test_amount_is_zero() { + let zero = Amount::from(0); + assert!(zero.is_zero()); + + let non_zero = Amount::from(1); + assert!(!non_zero.is_zero()); + } } /// Helpers for testing with addresses.