mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-24 23:35:44 +01:00
* feat(cdk-integration-tests): refactor regtest setup and mintd integration - Replace shell-based regtest setup with Rust binary (start_regtest_mints) - Add cdk-mintd crate to workspace and integration tests - Improve environment variable handling for test configurations - Update integration tests to use proper temp directory management - Remove deprecated start_regtest.rs binary - Enhance CLN client connection with retry logic - Simplify regtest shell script (itests.sh) to use new binary - Fix tracing filters and improve error handling in setup - Update dependencies and configurations for integration tests fix: killing chore: comment tests for ci debugging chore: compile Revert "chore: comment tests for ci debugging" This reverts commit bfc594c11cf37caeaa6445cb854ae5567d2da6bd. * chore: sql cipher * fix: removal of sqlite cipher * fix: auth password * refactor(cdk-mintd): improve database password handling and function signatures - Pass database password as parameter instead of parsing CLI args in setup_database - Update function signatures for run_mintd and run_mintd_with_shutdown to accept db_password - Remove direct CLI parsing from database setup logic - Fix auth database initialization to use correct type when sqlcipher feature enabled
99 lines
3.1 KiB
Rust
99 lines
3.1 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.
|
|
//!
|
|
//! Test Categories:
|
|
//! - Keyset rotation and management
|
|
//! - Database transaction handling
|
|
//! - Internal state transitions
|
|
//! - Fee calculation and enforcement
|
|
//! - Proof validation and state management
|
|
|
|
use std::collections::{HashMap, HashSet};
|
|
use std::sync::Arc;
|
|
|
|
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() {
|
|
let mnemonic = Mnemonic::generate(12).unwrap();
|
|
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 localstore = Arc::new(database);
|
|
let mut mint_builder = MintBuilder::new(localstore.clone());
|
|
|
|
mint_builder = mint_builder
|
|
.with_name("regtest mint".to_string())
|
|
.with_description("regtest mint".to_string());
|
|
|
|
mint_builder
|
|
.add_payment_processor(
|
|
CurrencyUnit::Sat,
|
|
PaymentMethod::Bolt11,
|
|
MintMeltLimits::new(1, 5_000),
|
|
Arc::new(fake_wallet),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
// .with_seed(mnemonic.to_seed_normalized("").to_vec());
|
|
|
|
let mint = mint_builder
|
|
.build_with_seed(localstore.clone(), &mnemonic.to_seed_normalized(""))
|
|
.await
|
|
.unwrap();
|
|
let mut tx = localstore.begin_transaction().await.unwrap();
|
|
|
|
let quote_ttl = QuoteTTL::new(10000, 10000);
|
|
tx.set_quote_ttl(quote_ttl).await.unwrap();
|
|
|
|
tx.commit().await.unwrap();
|
|
|
|
let active = mint.get_active_keysets();
|
|
|
|
let active = active
|
|
.get(&CurrencyUnit::Sat)
|
|
.expect("There is a keyset for unit");
|
|
let old_keyset_info = mint.get_keyset_info(active).expect("There is keyset");
|
|
|
|
mint.rotate_keyset(CurrencyUnit::Sat, 32, 0).await.unwrap();
|
|
|
|
let active = mint.get_active_keysets();
|
|
|
|
let active = active
|
|
.get(&CurrencyUnit::Sat)
|
|
.expect("There is a keyset for unit");
|
|
|
|
let keyset_info = mint.get_keyset_info(active).expect("There is keyset");
|
|
|
|
assert_ne!(keyset_info.id, old_keyset_info.id);
|
|
|
|
mint.rotate_keyset(CurrencyUnit::Sat, 32, 0).await.unwrap();
|
|
|
|
let active = mint.get_active_keysets();
|
|
|
|
let active = active
|
|
.get(&CurrencyUnit::Sat)
|
|
.expect("There is a keyset for unit");
|
|
|
|
let new_keyset_info = mint.get_keyset_info(active).expect("There is keyset");
|
|
|
|
assert_ne!(new_keyset_info.id, keyset_info.id);
|
|
}
|