feat: tests on lnd node

This commit is contained in:
thesimplekid
2025-01-24 14:40:10 +00:00
parent 486f98bc8b
commit 67be74abb8
7 changed files with 97 additions and 18 deletions

View File

@@ -5,7 +5,9 @@ use axum::Router;
use cdk::mint::Mint;
use tokio::sync::Notify;
use tower_http::cors::CorsLayer;
use tracing::instrument;
#[instrument(skip_all)]
pub async fn start_mint(addr: &str, port: u16, mint: Mint) -> Result<()> {
let mint_arc = Arc::new(mint);

View File

@@ -1,5 +1,5 @@
use std::env;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use anyhow::Result;
@@ -14,6 +14,7 @@ use ln_regtest_rs::bitcoin_client::BitcoinClient;
use ln_regtest_rs::bitcoind::Bitcoind;
use ln_regtest_rs::ln_client::{ClnClient, LightningClient, LndClient};
use ln_regtest_rs::lnd::Lnd;
use tracing::instrument;
use crate::init_mint::start_mint;
@@ -93,11 +94,11 @@ pub fn get_lnd_dir(name: &str) -> PathBuf {
dir
}
pub fn get_lnd_cert_file_path(lnd_dir: &PathBuf) -> PathBuf {
pub fn get_lnd_cert_file_path(lnd_dir: &Path) -> PathBuf {
lnd_dir.join("tls.cert")
}
pub fn get_lnd_macaroon_path(lnd_dir: &PathBuf) -> PathBuf {
pub fn get_lnd_macaroon_path(lnd_dir: &Path) -> PathBuf {
lnd_dir.join("data/chain/bitcoin/regtest/admin.macaroon")
}
@@ -147,6 +148,7 @@ pub async fn create_lnd_backend(lnd_client: &LndClient) -> Result<CdkLnd> {
.await?)
}
#[instrument(skip_all)]
pub async fn create_mint<D, L>(addr: &str, port: u16, database: D, lighting: L) -> Result<()>
where
D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,

View File

@@ -15,7 +15,8 @@ use cdk::nuts::{
use cdk::wallet::client::{HttpClient, MintConnector};
use cdk::wallet::{Wallet, WalletSubscription};
use cdk_integration_tests::init_regtest::{
get_cln_dir, get_lnd_dir, get_mint_url, get_mint_ws_url, LND_RPC_ADDR,
get_cln_dir, get_lnd_cert_file_path, get_lnd_dir, get_lnd_macaroon_path, get_mint_port,
get_mint_url, get_mint_ws_url, LND_RPC_ADDR, LND_TWO_RPC_ADDR,
};
use futures::{SinkExt, StreamExt};
use lightning_invoice::Bolt11Invoice;
@@ -258,7 +259,10 @@ async fn test_pay_invoice_twice() -> Result<()> {
let mint_quote = wallet.mint_quote(100.into(), None).await?;
lnd_client.pay_invoice(mint_quote.request).await?;
lnd_client
.pay_invoice(mint_quote.request)
.await
.expect("Could not pay invoice");
let proofs = wallet
.mint(&mint_quote.id, SplitTarget::default(), None)
@@ -343,13 +347,33 @@ async fn test_internal_payment() -> Result<()> {
.await
.unwrap();
let cln_one_dir = get_cln_dir("one");
let cln_client = ClnClient::new(cln_one_dir.clone(), None).await?;
let check_paid = match get_mint_port() {
8085 => {
let cln_one_dir = get_cln_dir("one");
let cln_client = ClnClient::new(cln_one_dir.clone(), None).await?;
let payment_hash = Bolt11Invoice::from_str(&mint_quote.request)?;
let check_paid = cln_client
.check_incoming_payment_status(&payment_hash.payment_hash().to_string())
.await?;
let payment_hash = Bolt11Invoice::from_str(&mint_quote.request)?;
cln_client
.check_incoming_payment_status(&payment_hash.payment_hash().to_string())
.await
.expect("Could not check invoice")
}
8087 => {
let lnd_two_dir = get_lnd_dir("two");
let lnd_client = LndClient::new(
format!("https://{}", LND_TWO_RPC_ADDR),
get_lnd_cert_file_path(&lnd_two_dir),
get_lnd_macaroon_path(&lnd_two_dir),
)
.await?;
let payment_hash = Bolt11Invoice::from_str(&mint_quote.request)?;
lnd_client
.check_incoming_payment_status(&payment_hash.payment_hash().to_string())
.await
.expect("Could not check invoice")
}
_ => panic!("Unknown mint port"),
};
match check_paid {
InvoiceStatus::Unpaid => (),