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 authored and tzemanovic committed Mar 30, 2023
1 parent c92ac83 commit c2d6105
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 @@ -45,6 +45,11 @@ pub const MAX_AMOUNT: Amount = Amount { micro: u64::MAX };
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 @@ -550,6 +555,15 @@ mod tests {
assert_eq!(max.checked_add(one), None);
assert_eq!(max.checked_add(max), None);
}

#[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 c2d6105

Please sign in to comment.