Cesar Rodas преди 1 година
родител
ревизия
2d17778f9d
променени са 1 файла, в които са добавени 85 реда и са изтрити 0 реда
  1. 85 0
      utxo/src/storage.rs

+ 85 - 0
utxo/src/storage.rs

@@ -211,6 +211,10 @@ pub mod test {
             $crate::storage_unit_test!(does_not_update_spent_payments);
             $crate::storage_unit_test!(does_not_spend_unspendable_payments);
             $crate::storage_unit_test!(relate_account_to_transaction);
+            $crate::storage_unit_test!(pending_new_payments_are_not_spendable);
+            $crate::storage_unit_test!(processing_new_payments_are_not_spendable);
+            $crate::storage_unit_test!(cancelled_new_payments_are_not_spendable);
+            $crate::storage_unit_test!(failed_new_payments_are_not_spendable);
         };
     }
 
@@ -330,6 +334,46 @@ pub mod test {
         }
     }
 
+    pub async fn pending_new_payments_are_not_spendable<'a, T, B>(
+        storage: &'a T,
+        assets: AssetManager,
+    ) where
+        T: Storage<'a, B>,
+        B: Batch<'a>,
+    {
+        not_spendable_new_payments_not_spendable(storage, assets, Status::Pending).await
+    }
+
+    pub async fn processing_new_payments_are_not_spendable<'a, T, B>(
+        storage: &'a T,
+        assets: AssetManager,
+    ) where
+        T: Storage<'a, B>,
+        B: Batch<'a>,
+    {
+        not_spendable_new_payments_not_spendable(storage, assets, Status::Processing).await
+    }
+
+    pub async fn cancelled_new_payments_are_not_spendable<'a, T, B>(
+        storage: &'a T,
+        assets: AssetManager,
+    ) where
+        T: Storage<'a, B>,
+        B: Batch<'a>,
+    {
+        not_spendable_new_payments_not_spendable(storage, assets, Status::Cancelled).await
+    }
+
+    pub async fn failed_new_payments_are_not_spendable<'a, T, B>(
+        storage: &'a T,
+        assets: AssetManager,
+    ) where
+        T: Storage<'a, B>,
+        B: Batch<'a>,
+    {
+        not_spendable_new_payments_not_spendable(storage, assets, Status::Failed).await
+    }
+
     pub async fn does_not_spend_unspendable_payments<'a, T, B>(storage: &'a T, assets: AssetManager)
     where
         T: Storage<'a, B>,
@@ -508,4 +552,45 @@ pub mod test {
             );
         }
     }
+
+    async fn not_spendable_new_payments_not_spendable<'a, T, B>(
+        storage: &'a T,
+        assets: AssetManager,
+        status: Status,
+    ) where
+        T: Storage<'a, B>,
+        B: Batch<'a>,
+    {
+        let mut writer = storage.begin().await.expect("writer");
+        let mut rng = rand::thread_rng();
+        let account = "account0".parse::<AccountId>().expect("account");
+        let amount = assets
+            .human_amount_by_name("USD", &format!("{}", rng.gen_range(10.0..10000.0)))
+            .expect("valid amount");
+
+        let payment_id = PaymentId {
+            transaction: vec![0u8; 32].try_into().expect("valid tx id"),
+            position: 0,
+        };
+
+        writer
+            .store_new_payment(&Payment {
+                id: payment_id.clone(),
+                to: account.clone(),
+                amount,
+                status,
+                changelog: vec![],
+                spent: None,
+            })
+            .await
+            .expect("valid payment");
+
+        writer.commit().await.is_ok();
+
+        assert!(storage
+            .get_balance(&account)
+            .await
+            .expect("valid balance")
+            .is_empty());
+    }
 }