1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- use crate::{
- storage::{sqlite::SQLite, Storage},
- AccountId, Amount, Error, Ledger, RevId, Status,
- };
- use sqlx::sqlite::SqlitePoolOptions;
- use std::sync::Arc;
- #[allow(unused)]
- pub async fn get_file_asset_manager_and_ledger<'a>(name: &str) -> Arc<Ledger<SQLite>> {
- 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 db = SQLite::new(pool);
- db.setup().await.expect("setup");
- Ledger::new(db.into())
- }
- pub async fn get_asset_manager_and_ledger() -> Arc<Ledger<SQLite>> {
- let pool = SqlitePoolOptions::new()
- .max_connections(1)
- .idle_timeout(None)
- .max_lifetime(None)
- .connect(":memory:")
- .await
- .expect("pool");
- let db = SQLite::new(pool);
- db.setup().await.expect("setup");
- Ledger::new(db.into())
- }
- pub async fn withdrawal(
- ledger: &Ledger<SQLite>,
- account_id: &AccountId,
- status: Status,
- amount: Amount,
- ) -> Result<RevId, Error> {
- Ok(ledger
- .withdrawal(account_id, amount, status, "Test".to_owned())
- .await?
- .revision_id
- .clone())
- }
- pub async fn deposit<S>(ledger: &Ledger<S>, account_id: &AccountId, amount: Amount) -> RevId
- where
- S: Storage + Send + Sync,
- {
- ledger
- .deposit(
- account_id,
- amount,
- "settled".into(),
- vec![],
- "Test".to_owned(),
- )
- .await
- .expect("valid tx")
- .revision_id
- .clone()
- }
- mod deposit;
- mod negative_deposit;
- mod tx;
- mod withdrawal;
|