|
@@ -229,6 +229,7 @@ pub trait Storage {
|
|
|
#[cfg(test)]
|
|
|
pub mod test {
|
|
|
use super::*;
|
|
|
+ use crate::{config::Config, status::StatusManager};
|
|
|
use rand::Rng;
|
|
|
|
|
|
#[macro_export]
|
|
@@ -237,7 +238,7 @@ pub mod test {
|
|
|
#[tokio::test]
|
|
|
async fn $name() {
|
|
|
let ledger = get_instance(stringify!($name)).await;
|
|
|
- $crate::storage::test::$name(&ledger).await;
|
|
|
+ $crate::storage::test::$name(ledger).await;
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -246,6 +247,7 @@ pub mod test {
|
|
|
macro_rules! storage_test_suite {
|
|
|
() => {
|
|
|
$crate::storage_unit_test!(transaction);
|
|
|
+ $crate::storage_unit_test!(transaction_does_not_update_stale_transactions);
|
|
|
$crate::storage_unit_test!(transaction_not_available_until_commit);
|
|
|
$crate::storage_unit_test!(sorted_unspent_payments);
|
|
|
$crate::storage_unit_test!(does_not_update_spent_payments);
|
|
@@ -256,7 +258,45 @@ pub mod test {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- pub async fn transaction<'a, T>(storage: &'a T)
|
|
|
+ pub async fn transaction_does_not_update_stale_transactions<T>(storage: T)
|
|
|
+ where
|
|
|
+ T: Storage + Send + Sync,
|
|
|
+ {
|
|
|
+ let config = Config {
|
|
|
+ storage,
|
|
|
+ status: StatusManager::default(),
|
|
|
+ };
|
|
|
+
|
|
|
+ let asset: Asset = "USD/2".parse().expect("valid asset");
|
|
|
+ let mut pending = Transaction::new_external_deposit(
|
|
|
+ "test reference".to_owned(),
|
|
|
+ "pending".into(),
|
|
|
+ vec![(
|
|
|
+ "alice".parse().expect("account"),
|
|
|
+ asset.from_human("100.99").expect("valid amount"),
|
|
|
+ )],
|
|
|
+ )
|
|
|
+ .expect("valid tx");
|
|
|
+ pending.persist(&config).await.expect("valid insert");
|
|
|
+
|
|
|
+ pending
|
|
|
+ .clone()
|
|
|
+ .change_status(&config, "processing".into(), "some text".to_owned())
|
|
|
+ .await
|
|
|
+ .expect("valid update");
|
|
|
+
|
|
|
+ pending
|
|
|
+ .change_status(
|
|
|
+ &config,
|
|
|
+ "failed".into(),
|
|
|
+ "update from pending to failed (which is not the latest state and should fail)"
|
|
|
+ .to_owned(),
|
|
|
+ )
|
|
|
+ .await
|
|
|
+ .expect_err("stale updates are rejected by storage");
|
|
|
+ }
|
|
|
+
|
|
|
+ pub async fn transaction<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|
|
@@ -281,7 +321,7 @@ pub mod test {
|
|
|
assert!(storage.get_transaction(deposit.id()).await.is_ok());
|
|
|
}
|
|
|
|
|
|
- pub async fn transaction_not_available_until_commit<'a, T>(storage: &'a T)
|
|
|
+ pub async fn transaction_not_available_until_commit<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|
|
@@ -307,7 +347,7 @@ pub mod test {
|
|
|
assert!(storage.get_transaction(deposit.id()).await.is_ok());
|
|
|
}
|
|
|
|
|
|
- pub async fn does_not_update_spent_payments<'a, T>(storage: &'a T)
|
|
|
+ pub async fn does_not_update_spent_payments<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|
|
@@ -364,7 +404,7 @@ pub mod test {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub async fn spend_spendable_payments<'a, T>(storage: &'a T)
|
|
|
+ pub async fn spend_spendable_payments<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|
|
@@ -407,7 +447,7 @@ pub mod test {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub async fn does_not_spend_unspendable_payments<'a, T>(storage: &'a T)
|
|
|
+ pub async fn does_not_spend_unspendable_payments<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|
|
@@ -453,7 +493,7 @@ pub mod test {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub async fn sorted_unspent_payments<'a, T>(storage: &'a T)
|
|
|
+ pub async fn sorted_unspent_payments<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|
|
@@ -513,7 +553,7 @@ pub mod test {
|
|
|
assert!(at_least_one_negative_amount);
|
|
|
}
|
|
|
|
|
|
- pub async fn relate_account_to_transaction<T>(storage: &T)
|
|
|
+ pub async fn relate_account_to_transaction<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|
|
@@ -580,7 +620,7 @@ pub mod test {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub async fn not_spendable_new_payments_not_spendable<T>(storage: &T)
|
|
|
+ pub async fn not_spendable_new_payments_not_spendable<T>(storage: T)
|
|
|
where
|
|
|
T: Storage,
|
|
|
{
|