mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-03 21:15:22 +01:00
feat: itests select db
This commit is contained in:
@@ -21,6 +21,8 @@ anyhow = "1"
|
||||
cdk = { path = "../cdk", version = "0.4.0", features = ["mint", "wallet"] }
|
||||
cdk-cln = { path = "../cdk-cln", version = "0.4.0" }
|
||||
cdk-axum = { path = "../cdk-axum"}
|
||||
cdk-sqlite = { path = "../cdk-sqlite"}
|
||||
cdk-redb = { path = "../cdk-redb"}
|
||||
cdk-fake-wallet = { path = "../cdk-fake-wallet" }
|
||||
tower-http = { version = "0.4.4", features = ["cors"] }
|
||||
futures = { version = "0.3.28", default-features = false, features = ["executor"] }
|
||||
|
||||
@@ -4,7 +4,7 @@ use anyhow::Result;
|
||||
use axum::Router;
|
||||
use bip39::Mnemonic;
|
||||
use cdk::{
|
||||
cdk_database::mint_memory::MintMemoryDatabase,
|
||||
cdk_database::{self, MintDatabase},
|
||||
cdk_lightning::MintLightning,
|
||||
mint::{FeeReserve, Mint},
|
||||
nuts::{CurrencyUnit, MeltMethodSettings, MintInfo, MintMethodSettings},
|
||||
@@ -140,7 +140,10 @@ pub async fn create_cln_backend(cln_client: &ClnClient) -> Result<CdkCln> {
|
||||
.await?)
|
||||
}
|
||||
|
||||
pub async fn create_mint() -> Result<Mint> {
|
||||
pub async fn create_mint<D>(database: D) -> Result<Mint>
|
||||
where
|
||||
D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,
|
||||
{
|
||||
let nuts = cdk::nuts::Nuts::new()
|
||||
.nut07(true)
|
||||
.nut08(true)
|
||||
@@ -161,7 +164,7 @@ pub async fn create_mint() -> Result<Mint> {
|
||||
&get_mint_url(),
|
||||
&mnemonic.to_seed_normalized(""),
|
||||
mint_info,
|
||||
Arc::new(MintMemoryDatabase::default()),
|
||||
Arc::new(database),
|
||||
supported_units,
|
||||
)
|
||||
.await?;
|
||||
@@ -169,7 +172,10 @@ pub async fn create_mint() -> Result<Mint> {
|
||||
Ok(mint)
|
||||
}
|
||||
|
||||
pub async fn start_cln_mint() -> Result<()> {
|
||||
pub async fn start_cln_mint<D>(addr: &str, port: u16, database: D) -> Result<()>
|
||||
where
|
||||
D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,
|
||||
{
|
||||
let default_filter = "debug";
|
||||
|
||||
let sqlx_filter = "sqlx=warn";
|
||||
@@ -183,7 +189,7 @@ pub async fn start_cln_mint() -> Result<()> {
|
||||
// Parse input
|
||||
tracing_subscriber::fmt().with_env_filter(env_filter).init();
|
||||
|
||||
let mint = create_mint().await?;
|
||||
let mint = create_mint(database).await?;
|
||||
let cln_client = init_cln_client().await?;
|
||||
|
||||
let cln_backend = create_cln_backend(&cln_client).await?;
|
||||
@@ -240,12 +246,7 @@ pub async fn start_cln_mint() -> Result<()> {
|
||||
});
|
||||
}
|
||||
println!("Staring Axum server");
|
||||
axum::Server::bind(
|
||||
&format!("{}:{}", "127.0.0.1", 8085)
|
||||
.as_str()
|
||||
.parse()
|
||||
.unwrap(),
|
||||
)
|
||||
axum::Server::bind(&format!("{}:{}", addr, port).as_str().parse().unwrap())
|
||||
.serve(mint_service.into_make_service())
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
use std::env;
|
||||
|
||||
use anyhow::Result;
|
||||
use cdk::cdk_database::mint_memory::MintMemoryDatabase;
|
||||
use cdk_integration_tests::init_regtest::{
|
||||
fund_ln, init_bitcoin_client, init_bitcoind, init_cln, init_cln_client, init_lnd,
|
||||
fund_ln, get_temp_dir, init_bitcoin_client, init_bitcoind, init_cln, init_cln_client, init_lnd,
|
||||
init_lnd_client, open_channel, start_cln_mint,
|
||||
};
|
||||
use cdk_redb::MintRedbDatabase;
|
||||
use cdk_sqlite::MintSqliteDatabase;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
@@ -34,7 +39,26 @@ async fn main() -> Result<()> {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
start_cln_mint().await?;
|
||||
let addr = "127.0.0.1";
|
||||
let port = 8085;
|
||||
|
||||
let mint_db_kind = env::var("MINT_DATABASE")?;
|
||||
|
||||
match mint_db_kind.as_str() {
|
||||
"MEMORY" => {
|
||||
start_cln_mint(addr, port, MintMemoryDatabase::default()).await?;
|
||||
}
|
||||
"SQLITE" => {
|
||||
let sqlite_db = MintSqliteDatabase::new(&get_temp_dir().join("mint")).await?;
|
||||
sqlite_db.migrate().await;
|
||||
start_cln_mint(addr, port, sqlite_db).await?;
|
||||
}
|
||||
"REDB" => {
|
||||
let redb_db = MintRedbDatabase::new(&get_temp_dir().join("mint")).unwrap();
|
||||
start_cln_mint(addr, port, redb_db).await?;
|
||||
}
|
||||
_ => panic!("Unknown mint db type"),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -642,7 +642,8 @@ impl Mint {
|
||||
|
||||
self.localstore
|
||||
.update_mint_quote_state(&mint_request.quote, MintQuoteState::Paid)
|
||||
.await?;
|
||||
.await
|
||||
.unwrap();
|
||||
return Err(Error::BlindedMessageAlreadySigned);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ if [[ ! -d "$cdk_itests" ]]; then
|
||||
fi
|
||||
|
||||
echo "Temp directory created: $cdk_itests"
|
||||
export MINT_DATABASE="SQLITE";
|
||||
|
||||
cargo build -p cdk-integration-tests
|
||||
cargo build --bin cdk-integration-tests
|
||||
@@ -80,7 +81,7 @@ done
|
||||
|
||||
|
||||
# Run cargo test
|
||||
cargo test -p cdk-integration-tests
|
||||
cargo test -p cdk-integration-tests --test regtest
|
||||
|
||||
# Capture the exit status of cargo test
|
||||
test_status=$?
|
||||
|
||||
Reference in New Issue
Block a user