瀏覽代碼

chore: kill mutants amount (#1536)

tsk 1 周之前
父節點
當前提交
99e89d5759
共有 3 個文件被更改,包括 44 次插入1 次删除
  1. 1 0
      .cargo/mutants.toml
  2. 1 1
      Cargo.lock
  3. 42 0
      crates/cashu/src/amount.rs

+ 1 - 0
.cargo/mutants.toml

@@ -41,6 +41,7 @@ exclude_re = [
     "FeeAndAmounts::fee",
     "FeeAndAmounts::amounts",
     "BlindedMessage::witness",
+    "crates/cashu/src/amount.rs:.*to_u64",
 
     # Trivial trait implementations - unrealistic mutations
     "crates/cashu/src/amount.rs.*impl From<&u64> for Amount.*from",

+ 1 - 1
Cargo.lock

@@ -1554,7 +1554,7 @@ dependencies = [
  "chrono",
  "nostr-sdk",
  "reqwest",
- "rustls 0.23.35",
+ "rustls 0.23.36",
  "serde",
  "serde_json",
  "thiserror 2.0.17",

+ 42 - 0
crates/cashu/src/amount.rs

@@ -1916,4 +1916,46 @@ mod tests {
             ]
         );
     }
+
+    #[test]
+    fn test_amount_currency_unit_to_i64() {
+        let amount = Amount::new(100, CurrencyUnit::Sat);
+        assert_eq!(amount.to_i64(), Some(100));
+
+        let amount = Amount::new(i64::MAX as u64, CurrencyUnit::Sat);
+        assert_eq!(amount.to_i64(), Some(i64::MAX));
+
+        let amount = Amount::new(i64::MAX as u64 + 1, CurrencyUnit::Sat);
+        assert_eq!(amount.to_i64(), None);
+
+        let amount = Amount::new(0, CurrencyUnit::Sat);
+        assert_eq!(amount.to_i64(), Some(0));
+
+        let amount = Amount::new(1, CurrencyUnit::Sat);
+        assert_eq!(amount.to_i64(), Some(1));
+    }
+
+    #[test]
+    fn test_display_with_unit() {
+        let amount = Amount::new(100, CurrencyUnit::Sat);
+        assert_eq!(amount.display_with_unit(), "100 sat");
+
+        let amount = Amount::new(50, CurrencyUnit::Msat);
+        assert_eq!(amount.display_with_unit(), "50 msat");
+
+        let amount = Amount::new(100, CurrencyUnit::Usd);
+        assert_eq!(amount.display_with_unit(), "100 usd");
+
+        let amount = Amount::new(123, CurrencyUnit::Custom("BTC".to_string()));
+        assert_eq!(amount.display_with_unit(), "123 btc");
+    }
+
+    #[test]
+    fn test_amount_add_operator() {
+        let a = Amount::from(100);
+        let b = Amount::from(50);
+        let sum = a + b;
+        assert_eq!(sum, Amount::from(150));
+        assert_ne!(sum, Amount::ZERO);
+    }
 }