Skip to content

Commit

Permalink
feat: add itest with nutshell mint
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Mar 19, 2024
1 parent ce9901d commit 2c22ed3
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install just
run: cargo install just
- name: Run Docker Compose
run: docker compose up lnd1 -d
run: docker compose --profile itest up -d
- name: Build
run: cargo build --verbose
- name: chmod data-dir
Expand All @@ -39,7 +39,7 @@ jobs:
with:
submodules: true
- name: Run Docker Compose
run: docker compose up lnd1 -d
run: docker compose --profile itest up -d
- name: Install protobuf-compiler
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Install stable
Expand Down
121 changes: 74 additions & 47 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,6 @@ services:
POSTGRES_DB: moksha-mint
profiles:
- itest
prometheus:
image: "prom/prometheus:v2.45.0"
command:
- "--config.file=/etc/prometheus.yaml"
- "--enable-feature=exemplar-storage"
- "--web.enable-remote-write-receiver"
volumes:
- "./conf/prometheus.yaml:/etc/prometheus.yaml"
ports:
- "127.0.0.1:9090:9090"
tempo:
image: "grafana/tempo:2.4.0"
command:
- "-config.file=/etc/tempo.yaml"
volumes:
- "./conf/tempo.yaml:/etc/tempo.yaml"
ports:
- "127.0.0.1:3200:3200" # Tempo
- "127.0.0.1:4317:4317" # OTLP GRPC
- "127.0.0.1:4318:4318" # OTLP HTTP
grafana:
image: "grafana/grafana:10.2.4"
volumes:
- "./conf/grafana-datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml"
environment:
- "GF_AUTH_ANONYMOUS_ENABLED=true"
- "GF_AUTH_ANONYMOUS_ORG_ROLE=Admin"
- "GF_AUTH_DISABLE_LOGIN_FORM=true"
- "GF_FEATURE_TOGGLES_ENABLE=traceqlEditor"
ports:
- "127.0.0.1:3000:3000"

app:
#image: "docker.io/ngutech21/moksha-mint:latest"
image: "moksha-mint:latest" # for local testing
container_name: moksha-mint
ports:
- 3338:3338
environment:
- MINT_DB_URL=postgres://postgres:postgres@moksha-mint-db/moksha-mint
- MINT_LIGHTNING_BACKEND=Lnd
- MINT_PRIVATE_KEY=supersecretkey
depends_on:
- database
profiles:
- app

bitcoind:
stop_grace_period: 5m
image: btcpayserver/bitcoin:0.21.0
Expand Down Expand Up @@ -94,6 +47,8 @@ services:
- "28335"
ports:
- "18453:18443" #json rpc
profiles:
- itest

lnd1:
depends_on:
Expand Down Expand Up @@ -128,3 +83,75 @@ services:
- "10009"
ports:
- "11001:10009"
profiles:
- itest

nutshell:
image: cashubtc/nutshell:0.15.1
container_name: nutshell
ports:
- "2228:3338"
environment:
- MINT_LIGHTNING_BACKEND=FakeWallet
- MINT_LISTEN_HOST=0.0.0.0
- MINT_LISTEN_PORT=3338
- MINT_PRIVATE_KEY=TEST_PRIVATE_KEY
- MINT_INFO_NAME=nutshell
command: ["poetry", "run", "mint"]
profiles:
- itest

prometheus:
image: "prom/prometheus:v2.45.0"
command:
- "--config.file=/etc/prometheus.yaml"
- "--enable-feature=exemplar-storage"
- "--web.enable-remote-write-receiver"
volumes:
- "./conf/prometheus.yaml:/etc/prometheus.yaml"
ports:
- "127.0.0.1:9090:9090"
profiles:
- tracing

tempo:
image: "grafana/tempo:2.4.0"
command:
- "-config.file=/etc/tempo.yaml"
volumes:
- "./conf/tempo.yaml:/etc/tempo.yaml"
ports:
- "127.0.0.1:3200:3200" # Tempo
- "127.0.0.1:4317:4317" # OTLP GRPC
- "127.0.0.1:4318:4318" # OTLP HTTP
profiles:
- tracing

grafana:
image: "grafana/grafana:10.2.4"
volumes:
- "./conf/grafana-datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml"
environment:
- "GF_AUTH_ANONYMOUS_ENABLED=true"
- "GF_AUTH_ANONYMOUS_ORG_ROLE=Admin"
- "GF_AUTH_DISABLE_LOGIN_FORM=true"
- "GF_FEATURE_TOGGLES_ENABLE=traceqlEditor"
ports:
- "127.0.0.1:3000:3000"
profiles:
- tracing

app:
#image: "docker.io/ngutech21/moksha-mint:latest"
image: "moksha-mint:latest" # for local testing
container_name: moksha-mint
ports:
- 3338:3338
environment:
- MINT_DB_URL=postgres://postgres:postgres@moksha-mint-db/moksha-mint
- MINT_LIGHTNING_BACKEND=Lnd
- MINT_PRIVATE_KEY=supersecretkey
depends_on:
- database
profiles:
- app
2 changes: 1 addition & 1 deletion integrationtests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Before running the tests, ensure that you have the following software installed
Before running the tests you have to start docker containers for the services that the tests depend on. You can do this by running the following command:

```bash
docker compose up lnd1 -d
docker compose --profile itest up -d
```

To run the integration tests, use the `itests` command in your terminal:
Expand Down
6 changes: 6 additions & 0 deletions integrationtests/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ pub async fn start_mint(
.await?;
Ok(())
}

pub fn read_fixture(name: &str) -> anyhow::Result<String> {
let base_dir = std::env::var("CARGO_MANIFEST_DIR")?;
let raw_token = std::fs::read_to_string(format!("{base_dir}/tests/fixtures/{name}"))?;
Ok(raw_token.trim().to_string())
}
10 changes: 2 additions & 8 deletions integrationtests/tests/tests_bolt11_lnbits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use itests::setup::start_mint;
use itests::setup::{read_fixture, start_mint};
use moksha_core::primitives::{CurrencyUnit, PaymentMethod};

use moksha_wallet::client::CashuClient;
Expand All @@ -14,7 +14,7 @@ use testcontainers_modules::postgres::Postgres;
use tokio::time::{sleep_until, Instant};

#[tokio::test(flavor = "multi_thread")]
pub async fn test_integration() -> anyhow::Result<()> {
pub async fn test_bolt11_lnbitsmock() -> anyhow::Result<()> {
// create postgres container that will be destroyed after the test is done
let docker = clients::Cli::default();
let node = Postgres::default().with_host_auth();
Expand Down Expand Up @@ -107,9 +107,3 @@ pub async fn test_integration() -> anyhow::Result<()> {
assert!(!info.nuts.nut4.disabled);
Ok(())
}

fn read_fixture(name: &str) -> anyhow::Result<String> {
let base_dir = std::env::var("CARGO_MANIFEST_DIR")?;
let raw_token = std::fs::read_to_string(format!("{base_dir}/tests/fixtures/{name}"))?;
Ok(raw_token.trim().to_string())
}
2 changes: 1 addition & 1 deletion integrationtests/tests/tests_btc_onchain_lnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use testcontainers::{clients, RunnableImage};
use testcontainers_modules::postgres::Postgres;

#[tokio::test(flavor = "multi_thread")]
async fn test_integration() -> anyhow::Result<()> {
async fn test_btc_onchain_mint_melt() -> anyhow::Result<()> {
// create postgres container that will be destroyed after the test is done
let docker = clients::Cli::default();
let node = Postgres::default().with_host_auth();
Expand Down
66 changes: 66 additions & 0 deletions integrationtests/tests/tests_nutshell_compatibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use itests::setup::read_fixture;
use moksha_core::primitives::{CurrencyUnit, PaymentMethod};
use moksha_wallet::client::CashuClient;
use moksha_wallet::http::CrossPlatformHttpClient;
use moksha_wallet::localstore::sqlite::SqliteLocalStore;
use moksha_wallet::wallet::WalletBuilder;
use std::time::Duration;

use reqwest::Url;

use tokio::time::{sleep_until, Instant};

#[tokio::test(flavor = "multi_thread")]
pub async fn test_nutshell_compatibility() -> anyhow::Result<()> {
let client = CrossPlatformHttpClient::new();
let mint_url = Url::parse("http://127.0.0.1:2228")?;
let keys = client.get_keys(&mint_url).await;
assert!(keys.is_ok());

let keysets = client.get_keysets(&mint_url).await;
assert!(keysets.is_ok());
// create wallet
let localstore = SqliteLocalStore::with_in_memory().await?;
let wallet = WalletBuilder::default()
.with_client(client)
.with_localstore(localstore)
.with_mint_url(mint_url)
.build()
.await?;

// check if mint info is correct
let mint_info = wallet.get_mint_info().await?;
assert_eq!(Some("nutshell".to_owned()), mint_info.name);

// get initial balance
let balance = wallet.get_balance().await?;
assert_eq!(0, balance, "Initial balance should be 0");

// mint some tokens
let mint_amount = 6_000;
let mint_quote = wallet.create_quote_bolt11(mint_amount).await?;
let hash = mint_quote.clone().quote;

sleep_until(Instant::now() + Duration::from_millis(1_000)).await;
let mint_result = wallet
.mint_tokens(&PaymentMethod::Bolt11, mint_amount.into(), hash.clone())
.await?;
assert_eq!(6_000, mint_result.total_amount());

let balance = wallet.get_balance().await?;
assert_eq!(6_000, balance);

// pay ln-invoice
let invoice_1000 = read_fixture("invoice_1000.txt")?;
let quote = wallet
.get_melt_quote_bolt11(invoice_1000.clone(), CurrencyUnit::Sat)
.await?;
let result_pay_invoice = wallet.pay_invoice(&quote, invoice_1000).await;
if result_pay_invoice.is_err() {
println!("error in pay_invoice{:?}", result_pay_invoice);
}
assert!(result_pay_invoice.is_ok());
let balance = wallet.get_balance().await?;
assert_eq!(5_000, balance);
Ok(())
}

0 comments on commit 2c22ed3

Please sign in to comment.