mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 23:55:01 +01:00
Mintd lib (#914)
* 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
This commit is contained in:
@@ -1,4 +1,23 @@
|
||||
//! Integration Test Library
|
||||
//!
|
||||
//! This crate provides shared functionality for CDK integration tests.
|
||||
//! It includes utilities for setting up test environments, funding wallets,
|
||||
//! and common test operations across different test scenarios.
|
||||
//!
|
||||
//! Test Categories Supported:
|
||||
//! - Pure in-memory tests (no external dependencies)
|
||||
//! - Regtest environment tests (with actual Lightning nodes)
|
||||
//! - Authenticated mint tests
|
||||
//! - Multi-mint scenarios
|
||||
//!
|
||||
//! Key Components:
|
||||
//! - Test environment initialization
|
||||
//! - Wallet funding utilities
|
||||
//! - Lightning Network client helpers
|
||||
//! - Proof state management utilities
|
||||
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
@@ -8,13 +27,15 @@ use cdk::nuts::{MintQuoteState, NotificationPayload, State};
|
||||
use cdk::wallet::WalletSubscription;
|
||||
use cdk::Wallet;
|
||||
use cdk_fake_wallet::create_fake_invoice;
|
||||
use init_regtest::{get_lnd_dir, get_mint_url, LND_RPC_ADDR};
|
||||
use init_regtest::{get_lnd_dir, LND_RPC_ADDR};
|
||||
use ln_regtest_rs::ln_client::{LightningClient, LndClient};
|
||||
use tokio::time::{sleep, timeout, Duration};
|
||||
|
||||
pub mod cli;
|
||||
pub mod init_auth_mint;
|
||||
pub mod init_pure_tests;
|
||||
pub mod init_regtest;
|
||||
pub mod shared;
|
||||
|
||||
pub async fn fund_wallet(wallet: Arc<Wallet>, amount: Amount) {
|
||||
let quote = wallet
|
||||
@@ -32,6 +53,20 @@ pub async fn fund_wallet(wallet: Arc<Wallet>, amount: Amount) {
|
||||
.expect("Could not mint");
|
||||
}
|
||||
|
||||
pub fn get_mint_url_from_env() -> String {
|
||||
match env::var("CDK_TEST_MINT_URL") {
|
||||
Ok(url) => url,
|
||||
Err(_) => panic!("Mint url not set"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_second_mint_url_from_env() -> String {
|
||||
match env::var("CDK_TEST_MINT_URL_2") {
|
||||
Ok(url) => url,
|
||||
Err(_) => panic!("Mint url not set"),
|
||||
}
|
||||
}
|
||||
|
||||
// Get all pending from wallet and attempt to swap
|
||||
// Will panic if there are no pending
|
||||
// Will return Ok if swap fails as expected
|
||||
@@ -151,33 +186,9 @@ pub async fn wait_for_mint_to_be_paid(
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the mint URL from environment variable or falls back to default
|
||||
///
|
||||
/// Checks the CDK_TEST_MINT_URL environment variable:
|
||||
/// - If set, returns that URL
|
||||
/// - Otherwise falls back to the default URL from get_mint_url("0")
|
||||
pub fn get_mint_url_from_env() -> String {
|
||||
match env::var("CDK_TEST_MINT_URL") {
|
||||
Ok(url) => url,
|
||||
Err(_) => get_mint_url("0"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the second mint URL from environment variable or falls back to default
|
||||
///
|
||||
/// Checks the CDK_TEST_MINT_URL_2 environment variable:
|
||||
/// - If set, returns that URL
|
||||
/// - Otherwise falls back to the default URL from get_mint_url("1")
|
||||
pub fn get_second_mint_url_from_env() -> String {
|
||||
match env::var("CDK_TEST_MINT_URL_2") {
|
||||
Ok(url) => url,
|
||||
Err(_) => get_mint_url("1"),
|
||||
}
|
||||
}
|
||||
|
||||
// This is the ln wallet we use to send/receive ln payements as the wallet
|
||||
pub async fn init_lnd_client() -> LndClient {
|
||||
let lnd_dir = get_lnd_dir("one");
|
||||
pub async fn init_lnd_client(work_dir: &Path) -> LndClient {
|
||||
let lnd_dir = get_lnd_dir(work_dir, "one");
|
||||
let cert_file = lnd_dir.join("tls.cert");
|
||||
let macaroon_file = lnd_dir.join("data/chain/bitcoin/regtest/admin.macaroon");
|
||||
LndClient::new(format!("https://{LND_RPC_ADDR}"), cert_file, macaroon_file)
|
||||
@@ -189,10 +200,10 @@ pub async fn init_lnd_client() -> LndClient {
|
||||
///
|
||||
/// This is useful for tests that need to pay invoices in regtest mode but
|
||||
/// should be skipped in other environments.
|
||||
pub async fn pay_if_regtest(invoice: &Bolt11Invoice) -> Result<()> {
|
||||
pub async fn pay_if_regtest(work_dir: &Path, invoice: &Bolt11Invoice) -> Result<()> {
|
||||
// Check if the invoice is for the regtest network
|
||||
if invoice.network() == bitcoin::Network::Regtest {
|
||||
let lnd_client = init_lnd_client().await;
|
||||
let lnd_client = init_lnd_client(work_dir).await;
|
||||
lnd_client.pay_invoice(invoice.to_string()).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -220,10 +231,10 @@ pub fn is_regtest_env() -> bool {
|
||||
///
|
||||
/// Uses the is_regtest_env() function to determine whether to
|
||||
/// create a real regtest invoice or a fake one for testing.
|
||||
pub async fn create_invoice_for_env(amount_sat: Option<u64>) -> Result<String> {
|
||||
pub async fn create_invoice_for_env(work_dir: &Path, amount_sat: Option<u64>) -> Result<String> {
|
||||
if is_regtest_env() {
|
||||
// In regtest mode, create a real invoice
|
||||
let lnd_client = init_lnd_client().await;
|
||||
let lnd_client = init_lnd_client(work_dir).await;
|
||||
lnd_client
|
||||
.create_invoice(amount_sat)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user