Files
cdk/crates/cdk-integration-tests/tests/mint.rs
thesimplekid fa67271cca Int tests (#685)
* Here's a commit message for this change:

refactor: Move mint tests to fake_wallet.rs and add descriptive comments

refactor: pure wallet/mint does not need arc

refactor: Consolidate NUT-06 test into single function and remove redundant module

docs: Add comments explaining test purposes in integration tests file

refactor: Remove anyhow and replace with expect for error handling

refactor: use expect in pure tests

feat: Add configurable database type via environment variable for test mint and wallet

refactor: Update database initialization in test mint and wallet creation

feat: Add temporary directory support for redb and sqlite databases in tests

feat: Add database type argument to test commands in justfile

ci: Add build matrix for pure-itest with memory, sqlite, and redb databases

refactor: use expect in pure tests

refactor: Move and refactor `test_swap_unbalanced` from mint to integration tests pure

refactor: move mint tests to pure tests

docs: Add detailed comments explaining test file purposes for mint and integration tests

refactor: Extract keyset ID retrieval into a reusable function

test: Add concurrent double-spend test with 3 swap transactions

refactor: Simplify concurrent swap request processing and error handling

test: Add check to verify all proofs are marked as spent in concurrent double-spend test

refactor: Optimize proof state retrieval in concurrent double-spend test

feat: Add test for concurrent melt race condition with same proofs

fix: Update concurrent melt test to use melt quote and handle errors

refactor: melt concurrrent

refactor: Rename test function for clarity in concurrent double-spend scenario

refactor: Modify test_concurrent_double_spend_melt to manually create melt requests in mint tasks

feat: con melt test

refactor: Optimize proof state handling and error recovery in check_spendable

refactor: Extract helper method to reset proofs to original state

fix: reset y states

fix: reset y states

* fix: acces of priv feilds

* fix: add extra migrate
2025-03-27 12:48:36 +00:00

93 lines
2.8 KiB
Rust

//! Mint tests
//!
//! This file contains tests that focus on the mint's internal functionality without client interaction.
//! These tests verify the mint's behavior in isolation, such as keyset management, database operations,
//! and other mint-specific functionality that doesn't require wallet clients.
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use anyhow::Result;
use bip39::Mnemonic;
use cdk::cdk_database::MintDatabase;
use cdk::mint::{MintBuilder, MintMeltLimits};
use cdk::nuts::{CurrencyUnit, PaymentMethod};
use cdk::types::{FeeReserve, QuoteTTL};
use cdk_fake_wallet::FakeWallet;
use cdk_sqlite::mint::memory;
pub const MINT_URL: &str = "http://127.0.0.1:8088";
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_correct_keyset() -> Result<()> {
let mnemonic = Mnemonic::generate(12)?;
let fee_reserve = FeeReserve {
min_fee_reserve: 1.into(),
percent_fee_reserve: 1.0,
};
let database = memory::empty().await.expect("valid db instance");
let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
let mut mint_builder = MintBuilder::new();
let localstore = Arc::new(database);
mint_builder = mint_builder.with_localstore(localstore.clone());
mint_builder = mint_builder
.add_ln_backend(
CurrencyUnit::Sat,
PaymentMethod::Bolt11,
MintMeltLimits::new(1, 5_000),
Arc::new(fake_wallet),
)
.await?;
mint_builder = mint_builder
.with_name("regtest mint".to_string())
.with_description("regtest mint".to_string())
.with_seed(mnemonic.to_seed_normalized("").to_vec());
let mint = mint_builder.build().await?;
localstore
.set_mint_info(mint_builder.mint_info.clone())
.await?;
let quote_ttl = QuoteTTL::new(10000, 10000);
localstore.set_quote_ttl(quote_ttl).await?;
mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0).await?;
mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0).await?;
let active = mint.localstore.get_active_keysets().await?;
let active = active
.get(&CurrencyUnit::Sat)
.expect("There is a keyset for unit");
let keyset_info = mint
.localstore
.get_keyset_info(active)
.await?
.expect("There is keyset");
assert!(keyset_info.derivation_path_index == Some(2));
let mint = mint_builder.build().await?;
let active = mint.localstore.get_active_keysets().await?;
let active = active
.get(&CurrencyUnit::Sat)
.expect("There is a keyset for unit");
let keyset_info = mint
.localstore
.get_keyset_info(active)
.await?
.expect("There is keyset");
assert!(keyset_info.derivation_path_index == Some(2));
Ok(())
}