Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade testcontainers #331

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
357 changes: 273 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ serde_json = "1.0.133"
serde_with = "3.11.0"
sqlx = { version = "0.8.2", default-features = false }
tempfile = "3.14.0"
testcontainers = "0.15.0"
testcontainers-modules = "0.3.6"
testcontainers = "0.23.1"
testcontainers-modules = "0.11.4"
thiserror = "1.0.61"
tokio = "1.42.0"
tonic = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
database:
image: "postgres:16.2-alpine"
image: "postgres:16.6-alpine"
container_name: moksha-mint-db
ports:
- 5432:5432
Expand Down
15 changes: 9 additions & 6 deletions integrationtests/tests/tests_lnbitsmock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ use moksha_wallet::wallet::WalletBuilder;
use mokshamint::lightning::{lnbits::LnbitsLightningSettings, LightningType};
use reqwest::Url;
use std::time::Duration;
use testcontainers::{clients, RunnableImage};
use testcontainers::runners::AsyncRunner;
use testcontainers::ImageExt;
use testcontainers_modules::postgres::Postgres;
use tokio::time::{sleep_until, Instant};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
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();
let img = RunnableImage::from(node).with_tag("16.2-alpine");
let node = docker.run(img);
let host_port = node.get_host_port_ipv4(5432);

let node = Postgres::default()
.with_host_auth()
.with_tag("16.6-alpine")
.start()
.await?;
let host_port = node.get_host_port_ipv4(5432).await?;

// start lnbits
let _lnbits_thread = tokio::spawn(async {
Expand Down
37 changes: 21 additions & 16 deletions integrationtests/tests/tests_lnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ use mokshamint::{
};
use reqwest::Url;

use testcontainers::{clients, RunnableImage};
use testcontainers::runners::AsyncRunner;
use testcontainers::ImageExt;
use testcontainers_modules::postgres::Postgres;
use tokio::time::{sleep_until, Instant};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
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();
let img = RunnableImage::from(node).with_tag("16.2-alpine");
let node = docker.run(img);
let host_port = node.get_host_port_ipv4(5432);

let node = Postgres::default()
.with_host_auth()
.with_tag("16.6-alpine")
.start()
.await?;
let host_port = node.get_host_port_ipv4(5432).await?;

fund_mint_lnd(2_000_000).await?;

Expand Down Expand Up @@ -129,11 +132,12 @@ async fn test_btc_onchain_mint_melt() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_bolt11_mint() -> 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();
let img = RunnableImage::from(node).with_tag("16.2-alpine");
let node = docker.run(img);
let host_port = node.get_host_port_ipv4(5432);
let node = Postgres::default()
.with_host_auth()
.with_tag("16.6-alpine")
.start()
.await?;
let host_port = node.get_host_port_ipv4(5432).await?;

fund_mint_lnd(2_000_000).await?;
open_channel_with_wallet(500_000).await?;
Expand Down Expand Up @@ -224,11 +228,12 @@ async fn test_bolt11_mint() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_bolt11_send() -> 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();
let img = RunnableImage::from(node).with_tag("16.2-alpine");
let node = docker.run(img);
let host_port = node.get_host_port_ipv4(5432);
let node = Postgres::default()
.with_host_auth()
.with_tag("16.6-alpine")
.start()
.await?;
let host_port = node.get_host_port_ipv4(5432).await?;

fund_mint_lnd(2_000_000).await?;
open_channel_with_wallet(500_000).await?;
Expand Down
15 changes: 9 additions & 6 deletions integrationtests/tests/tests_moksha_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ use itests::{
setup::{fund_mint_lnd, start_mint},
};
use mokshamint::lightning::{lnd::LndLightningSettings, LightningType};
use testcontainers::{clients, RunnableImage};

use testcontainers::runners::AsyncRunner;
use testcontainers::ImageExt;
use testcontainers_modules::postgres::Postgres;

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_cli() -> anyhow::Result<()> {
let docker = clients::Cli::default();
let node = Postgres::default().with_host_auth();
let img = RunnableImage::from(node).with_tag("16.2-alpine");
let node = docker.run(img);
let host_port = node.get_host_port_ipv4(5432);
let node = Postgres::default()
.with_host_auth()
.with_tag("16.6-alpine")
.start()
.await?;
let host_port = node.get_host_port_ipv4(5432).await?;

fund_mint_lnd(2_000_000).await?;

Expand Down
65 changes: 24 additions & 41 deletions moksha-mint/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,18 +459,16 @@ mod tests {
use pretty_assertions::assert_eq;
use std::str::FromStr;
use std::sync::Arc;
use testcontainers::clients::Cli;
use testcontainers::RunnableImage;
use testcontainers::runners::AsyncRunner;
use testcontainers::{ContainerAsync, ImageExt};
use testcontainers_modules::postgres::Postgres;

#[tokio::test]
async fn test_fee_reserve() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);
let node = create_postgres_image().await?;

let mint = create_mint_from_mocks(
create_mock_db_empty(node.get_host_port_ipv4(5432)).await?,
create_mock_db_empty(node.get_host_port_ipv4(5432).await?).await?,
None,
)
.await?;
Expand All @@ -481,12 +479,10 @@ mod tests {

#[tokio::test]
async fn test_create_blindsignatures() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);
let node = create_postgres_image().await?;

let mint = create_mint_from_mocks(
create_mock_db_empty(node.get_host_port_ipv4(5432)).await?,
create_mock_db_empty(node.get_host_port_ipv4(5432).await?).await?,
None,
)
.await?;
Expand Down Expand Up @@ -514,14 +510,11 @@ mod tests {

#[tokio::test]
async fn test_mint_empty() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);

let node = create_postgres_image().await?;
let mut lightning = MockLightning::new();
lightning.expect_is_invoice_paid().returning(|_| Ok(true));
let mint = create_mint_from_mocks(
create_mock_db_pending_invoice(node.get_host_port_ipv4(5432)).await?,
create_mock_db_pending_invoice(node.get_host_port_ipv4(5432).await?).await?,
Some(lightning),
)
.await?;
Expand All @@ -544,14 +537,12 @@ mod tests {

#[tokio::test]
async fn test_mint_valid() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);
let node = create_postgres_image().await?;

let mut lightning = MockLightning::new();
lightning.expect_is_invoice_paid().returning(|_| Ok(true));
let mint = create_mint_from_mocks(
create_mock_db_pending_invoice(node.get_host_port_ipv4(5432)).await?,
create_mock_db_pending_invoice(node.get_host_port_ipv4(5432).await?).await?,
Some(lightning),
)
.await?;
Expand All @@ -574,13 +565,10 @@ mod tests {

#[tokio::test]
async fn test_swap_zero() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);

let node = create_postgres_image().await?;
let blinded_messages = vec![];
let mint = create_mint_from_mocks(
create_mock_db_empty(node.get_host_port_ipv4(5432)).await?,
create_mock_db_empty(node.get_host_port_ipv4(5432).await?).await?,
None,
)
.await?;
Expand All @@ -594,12 +582,9 @@ mod tests {

#[tokio::test]
async fn test_swap_64_in_20() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);

let node = create_postgres_image().await?;
let mint = create_mint_from_mocks(
create_mock_db_empty(node.get_host_port_ipv4(5432)).await?,
create_mock_db_empty(node.get_host_port_ipv4(5432).await?).await?,
None,
)
.await?;
Expand All @@ -620,11 +605,9 @@ mod tests {

#[tokio::test]
async fn test_swap_duplicate_key() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);
let node = create_postgres_image().await?;
let mint = create_mint_from_mocks(
create_mock_db_empty(node.get_host_port_ipv4(5432)).await?,
create_mock_db_empty(node.get_host_port_ipv4(5432).await?).await?,
None,
)
.await?;
Expand All @@ -641,10 +624,7 @@ mod tests {
/// melt 20 sats with 60 tokens and receive 40 tokens as change
async fn test_melt_overpay() -> anyhow::Result<()> {
use lightning_invoice::Bolt11Invoice as LNInvoice;
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);

let node = create_postgres_image().await?;
let mut lightning = MockLightning::new();

lightning.expect_decode_invoice().returning(|_| {
Expand All @@ -661,7 +641,7 @@ mod tests {
.map_err(|_err: LightningError| MokshaMintError::InvoiceNotFound("".to_string()))
});

let db = create_mock_db_empty(node.get_host_port_ipv4(5432)).await?;
let db = create_mock_db_empty(node.get_host_port_ipv4(5432).await?).await?;

let mint = Mint::new(
// "TEST_PRIVATE_KEY".to_string(),
Expand Down Expand Up @@ -750,8 +730,11 @@ mod tests {
Ok(db)
}

fn create_postgres_image() -> RunnableImage<Postgres> {
let node = Postgres::default().with_host_auth();
RunnableImage::from(node).with_tag("16.2-alpine")
async fn create_postgres_image() -> anyhow::Result<ContainerAsync<Postgres>> {
Ok(Postgres::default()
.with_host_auth()
.with_tag("16.6-alpine")
.start()
.await?)
}
}
Loading
Loading