Files
cdk/crates/cdk-integration-tests/tests/integration_tests_pure.rs
C f7d9a1b5db Drop the in-memory database (#613)
* Drop the in-memory database

Fixes #607

This PR drops the implementation of in-memory database traits.

They are useful for testing purposes since the tests should test our codebase
and assume the database works as expected (although a follow-up PR should write
a sanity test suite for all database trait implementors).

As complexity is worth with database requirements to simplify complexity and
add more robustness, for instance, with the following plans to add support for
transactions or buffered writes, it would become more complex and
time-consuming to support a correct database trait. This PR drops the
implementation and replaces it with a SQLite memory instance

* Remove OnceCell<Mint>

Without this change, a single Mint is shared for all tests, and the first tests
to run and shutdown makes the other databases (not-reachable, as dropping the
tokio engine would also drop the database instance).

There is no real reason, other than perhaps performance. The mint should
perhaps run in their own tokio engine and share channels as API interfaces, or
a new instance should be created in each tests

* Fixed bug with foreign keys

[1] https://gist.github.com/crodas/bad00997c63bd5ac58db3c5bd90747ed

* Show more debug on failure

* Remove old code

* Remove old references to WalletMemoryDatabase
2025-03-04 19:44:34 +00:00

46 lines
1.4 KiB
Rust

use std::assert_eq;
use cdk::amount::SplitTarget;
use cdk::nuts::nut00::ProofsMethods;
use cdk::wallet::SendKind;
use cdk::Amount;
use cdk_integration_tests::init_pure_tests::{
create_and_start_test_mint, create_test_wallet_for_mint, fund_wallet,
};
#[tokio::test]
async fn test_swap_to_send() -> anyhow::Result<()> {
let mint_bob = create_and_start_test_mint().await?;
let wallet_alice = create_test_wallet_for_mint(mint_bob.clone()).await?;
// Alice gets 64 sats
fund_wallet(wallet_alice.clone(), 64).await?;
let balance_alice = wallet_alice.total_balance().await?;
assert_eq!(Amount::from(64), balance_alice);
// Alice wants to send 40 sats, which internally swaps
let token = wallet_alice
.send(
Amount::from(40),
None,
None,
&SplitTarget::None,
&SendKind::OnlineExact,
false,
)
.await?;
assert_eq!(Amount::from(40), token.proofs().total_amount()?);
assert_eq!(Amount::from(24), wallet_alice.total_balance().await?);
// Alice sends cashu, Carol receives
let wallet_carol = create_test_wallet_for_mint(mint_bob.clone()).await?;
let received_amount = wallet_carol
.receive_proofs(token.proofs(), SplitTarget::None, &[], &[])
.await?;
assert_eq!(Amount::from(40), received_amount);
assert_eq!(Amount::from(40), wallet_carol.total_balance().await?);
Ok(())
}