Skip to content

Commit

Permalink
Add Amount::is_zero fn
Browse files Browse the repository at this point in the history
  • Loading branch information
james-chf committed Dec 1, 2022
1 parent 6af5ff6 commit cf49c17
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cf49c17

Please sign in to comment.