瀏覽代碼

Add more tests

Cesar Rodas 1 年之前
父節點
當前提交
33c35601c2
共有 3 個文件被更改,包括 18 次插入6 次删除
  1. 1 1
      utxo/src/payment.rs
  2. 1 1
      utxo/src/storage/sqlite/batch.rs
  3. 16 4
      utxo/src/tests/deposit.rs

+ 1 - 1
utxo/src/payment.rs

@@ -79,7 +79,7 @@ impl<'de> de::Visitor<'de> for PaymentIdVisitor {
     {
         value
             .parse()
-            .map_err(|e: Error| E::custom(format!("Invalid payment ID: {}", e.to_string())))
+            .map_err(|e: Error| E::custom(format!("Invalid payment ID: {}", e)))
     }
 }
 

+ 1 - 1
utxo/src/storage/sqlite/batch.rs

@@ -180,7 +180,7 @@ impl<'a> storage::Batch<'a> for Batch<'a> {
         "#,
         )
         .bind::<u32>(create_status.into())
-        .bind(format!("{}:%", transaction_id.to_string()))
+        .bind(format!("{}:%", transaction_id))
         .bind::<u32>(Status::Spendable.into())
         .bind::<u32>(Status::Locked.into())
         .execute(&mut *self.inner)

+ 16 - 4
utxo/src/tests/deposit.rs

@@ -43,13 +43,20 @@ async fn deposit_and_transfer() {
     let fee = "fee".parse::<AccountId>().expect("account");
     let ledger = get_asset_manager_and_ledger().await;
     let usd: Asset = "USD/2".parse().expect("asset");
+    let btc: Asset = "BTC/8".parse().expect("asset");
 
     deposit(&ledger, &source, usd.from_human("10").expect("amount")).await;
     deposit(&ledger, &source, usd.from_human("20").expect("amount")).await;
+    deposit(&ledger, &source, btc.from_human(".2").expect("amount")).await;
 
+    let mut balances = ledger.get_balance(&source).await.expect("balance");
+    balances.sort_by(|a, b| a.asset().name.cmp(&b.asset().name));
     assert_eq!(
-        vec![usd.from_human("30").expect("amount")],
-        ledger.get_balance(&source).await.expect("balance")
+        vec![
+            btc.from_human("0.2").expect("amount"),
+            usd.from_human("30").expect("amount")
+        ],
+        balances
     );
 
     ledger
@@ -65,9 +72,14 @@ async fn deposit_and_transfer() {
         .await
         .expect("valid tx");
 
+    let mut balances = ledger.get_balance(&source).await.expect("balance");
+    balances.sort_by(|a, b| a.asset().name.cmp(&b.asset().name));
     assert_eq!(
-        vec![usd.from_human("17").expect("amount"),],
-        ledger.get_balance(&source).await.expect("balance")
+        vec![
+            btc.from_human("0.2").expect("amount"),
+            usd.from_human("17").expect("amount")
+        ],
+        balances
     );
     assert_eq!(
         vec![usd.from_human("12.5").expect("amount"),],