use crate::{ asset_manager::AssetDefinition, storage::sqlite::SQLite, storage::Storage, AccountId, Amount, AssetManager, Error, Ledger, Status, TransactionId, }; use sqlx::sqlite::SqlitePoolOptions; #[allow(unused)] pub async fn get_file_asset_manager_and_ledger<'a>(name: &str) -> (AssetManager, Ledger) { let pool = SqlitePoolOptions::new() .max_connections(1) .idle_timeout(None) .max_lifetime(None) .connect(format!("sqlite:///tmp/{}.db", name).as_str()) .await .expect("pool"); let assets = AssetManager::new(vec![ AssetDefinition::new(1, "BTC", 8), AssetDefinition::new(2, "USD", 4), ]); let db = SQLite::new(pool, assets.clone()); db.setup().await.expect("setup"); (assets.clone(), Ledger::new(db, assets)) } pub async fn get_asset_manager_and_ledger() -> (AssetManager, Ledger) { let pool = SqlitePoolOptions::new() .max_connections(1) .idle_timeout(None) .max_lifetime(None) .connect(":memory:") .await .expect("pool"); let assets = AssetManager::new(vec![ AssetDefinition::new(1, "BTC", 8), AssetDefinition::new(2, "USD", 4), ]); let db = SQLite::new(pool, assets.clone()); db.setup().await.expect("setup"); (assets.clone(), Ledger::new(db, assets)) } pub async fn withdrawal( ledger: &Ledger, account_id: &AccountId, status: Status, amount: Amount, ) -> Result { Ok(ledger .withdrawal(account_id, amount, status, "Test".to_owned()) .await? .id() .clone()) } pub async fn deposit(ledger: &Ledger, account_id: &AccountId, amount: Amount) -> TransactionId where S: Storage + Send + Sync, { ledger .deposit(account_id, amount, Status::Settled, "Test".to_owned()) .await .expect("valid tx") .id() .clone() } mod deposit; mod negative_deposit; mod tx; mod withdrawal;