From ad76a791dc4c969a2147295ecc97f694eaf8f152 Mon Sep 17 00:00:00 2001 From: ngutech21 Date: Fri, 13 Dec 2024 08:38:21 +0100 Subject: [PATCH] chore: upgrade testcontainers --- Cargo.lock | 357 ++++++++++++++++----- Cargo.toml | 4 +- docker-compose.yml | 2 +- integrationtests/tests/tests_lnbitsmock.rs | 15 +- integrationtests/tests/tests_lnd.rs | 37 ++- integrationtests/tests/tests_moksha_cli.rs | 15 +- moksha-mint/src/mint.rs | 65 ++-- moksha-mint/src/server.rs | 89 +++-- 8 files changed, 377 insertions(+), 207 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a01cdfef..61b1a480 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -523,14 +523,54 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bollard" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d41711ad46fda47cd701f6908e59d1bd6b9a2b7464c0d0aeab95c6d37096ff8a" +dependencies = [ + "base64 0.22.1", + "bollard-stubs", + "bytes", + "futures-core", + "futures-util", + "hex", + "home", + "http 1.2.0", + "http-body-util", + "hyper 1.5.1", + "hyper-named-pipe", + "hyper-rustls 0.27.3", + "hyper-util", + "hyperlocal", + "log", + "pin-project-lite", + "rustls 0.23.20", + "rustls-native-certs", + "rustls-pemfile 2.2.0", + "rustls-pki-types", + "serde", + "serde_derive", + "serde_json", + "serde_repr", + "serde_urlencoded", + "thiserror 1.0.69", + "tokio", + "tokio-util", + "tower-service", + "url", + "winapi", +] + [[package]] name = "bollard-stubs" -version = "1.42.0-rc.3" +version = "1.45.0-rc.26.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed59b5c00048f48d7af971b71f800fdf23e858844a6f9e4d32ca72e9399e7864" +checksum = "6d7c5415e3a6bc6d3e99eff6268e488fd4ee25e7b28c10f08fa6760bd9de16e4" dependencies = [ "serde", - "serde_with 1.14.0", + "serde_repr", + "serde_with", ] [[package]] @@ -671,7 +711,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.1", + "strsim", ] [[package]] @@ -898,38 +938,14 @@ dependencies = [ "typenum", ] -[[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core 0.13.4", - "darling_macro 0.13.4", -] - [[package]] name = "darling" version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ - "darling_core 0.20.10", - "darling_macro 0.20.10", -] - -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.10.0", - "syn 1.0.109", + "darling_core", + "darling_macro", ] [[package]] @@ -942,28 +958,17 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.11.1", + "strsim", "syn 2.0.90", ] -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core 0.13.4", - "quote", - "syn 1.0.109", -] - [[package]] name = "darling_macro" version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ - "darling_core 0.20.10", + "darling_core", "quote", "syn 2.0.90", ] @@ -1075,6 +1080,17 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "docker_credential" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31951f49556e34d90ed28342e1df7e1cb7a229c4cab0aecc627b5d91edd41d07" +dependencies = [ + "base64 0.21.7", + "serde", + "serde_json", +] + [[package]] name = "dotenvy" version = "0.15.7" @@ -1216,6 +1232,18 @@ dependencies = [ "subtle", ] +[[package]] +name = "filetime" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +dependencies = [ + "cfg-if", + "libc", + "libredox", + "windows-sys 0.59.0", +] + [[package]] name = "fixedbitset" version = "0.4.2" @@ -1715,6 +1743,21 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-named-pipe" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b7d8abf35697b81a825e386fc151e0d503e8cb5fcb93cc8669c376dfd6f278" +dependencies = [ + "hex", + "hyper 1.5.1", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", + "winapi", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -1778,6 +1821,21 @@ dependencies = [ "tracing", ] +[[package]] +name = "hyperlocal" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "986c5ce3b994526b3cd75578e62554abd09f0899d6206de48b3e96ab34ccc8c7" +dependencies = [ + "hex", + "http-body-util", + "hyper 1.5.1", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + [[package]] name = "iana-time-zone" version = "0.1.61" @@ -2136,6 +2194,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ "bitflags 2.6.0", "libc", + "redox_syscall 0.5.8", ] [[package]] @@ -2336,7 +2395,7 @@ dependencies = [ "secp256k1 0.29.1", "serde", "serde_json", - "serde_with 3.11.0", + "serde_with", "thiserror 1.0.69", "url", "utoipa", @@ -2538,6 +2597,12 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "opentelemetry" version = "0.22.0" @@ -2672,11 +2737,36 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.8", "smallvec", "windows-targets 0.52.6", ] +[[package]] +name = "parse-display" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914a1c2265c98e2446911282c6ac86d8524f495792c38c5bd884f80499c7538a" +dependencies = [ + "parse-display-derive", + "regex", + "regex-syntax 0.8.5", +] + +[[package]] +name = "parse-display-derive" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ae7800a4c974efd12df917266338e79a7a74415173caf7e70aa0a0707345281" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "regex-syntax 0.8.5", + "structmeta", + "syn 2.0.90", +] + [[package]] name = "paste" version = "1.0.15" @@ -3119,6 +3209,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.8" @@ -3443,6 +3542,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5bfb394eeed242e909609f56089eecfe5fda225042e8b171791b9c95f5931e5" +dependencies = [ + "openssl-probe", + "rustls-pemfile 2.2.0", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -3512,6 +3624,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -3603,6 +3724,29 @@ dependencies = [ "cc", ] +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.216" @@ -3656,6 +3800,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -3668,16 +3823,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_with" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" -dependencies = [ - "serde", - "serde_with_macros 1.5.2", -] - [[package]] name = "serde_with" version = "3.11.0" @@ -3692,29 +3837,17 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "serde_with_macros 3.11.0", + "serde_with_macros", "time", ] -[[package]] -name = "serde_with_macros" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" -dependencies = [ - "darling 0.13.4", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "serde_with_macros" version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" dependencies = [ - "darling 0.20.10", + "darling", "proc-macro2", "quote", "syn 2.0.90", @@ -4071,15 +4204,32 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] -name = "strsim" -version = "0.11.1" +name = "structmeta" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +checksum = "2e1575d8d40908d70f6fd05537266b90ae71b15dbbe7a8b7dffa2b759306d329" +dependencies = [ + "proc-macro2", + "quote", + "structmeta-derive", + "syn 2.0.90", +] + +[[package]] +name = "structmeta-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "152a0b65a590ff6c3da95cabe2353ee04e6167c896b28e3b14478c2636c922fc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] [[package]] name = "subtle" @@ -4177,26 +4327,38 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "testcontainers" -version = "0.15.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83d2931d7f521af5bae989f716c3fa43a6af9af7ec7a5e21b59ae40878cec00" +checksum = "5f40cc2bd72e17f328faf8ca7687fe337e61bccd8acf9674fa78dd3792b045e1" dependencies = [ + "async-trait", + "bollard", "bollard-stubs", + "bytes", + "docker_credential", + "either", + "etcetera", "futures", - "hex", - "hmac", "log", - "rand", + "memchr", + "parse-display", + "pin-project-lite", "serde", "serde_json", - "sha2", + "serde_with", + "thiserror 1.0.69", + "tokio", + "tokio-stream", + "tokio-tar", + "tokio-util", + "url", ] [[package]] name = "testcontainers-modules" -version = "0.3.7" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8debb5e215d9e89ea93255fffff00bf037ea44075d7a2669a21a8a988d6b52fd" +checksum = "064a2677e164cad39ef3c1abddb044d5a25c49d27005804563d8c4227aac8bd0" dependencies = [ "testcontainers", ] @@ -4410,6 +4572,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-tar" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5714c010ca3e5c27114c1cdeb9d14641ace49874aa5626d7149e47aedace75" +dependencies = [ + "filetime", + "futures-core", + "libc", + "redox_syscall 0.3.5", + "tokio", + "tokio-stream", + "xattr", +] + [[package]] name = "tokio-util" version = "0.7.13" @@ -4800,6 +4977,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -5059,7 +5237,7 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "372d5b87f58ec45c384ba03563b03544dc5fadc3983e434b286913f5b4a9bb6d" dependencies = [ - "redox_syscall", + "redox_syscall 0.5.8", "wasite", ] @@ -5303,6 +5481,17 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +[[package]] +name = "xattr" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" +dependencies = [ + "libc", + "linux-raw-sys", + "rustix", +] + [[package]] name = "yansi" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index bf7eb42e..4f5d9a6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/docker-compose.yml b/docker-compose.yml index e36a577b..e654382c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: database: - image: "postgres:16.2-alpine" + image: "postgres:16.6-alpine" container_name: moksha-mint-db ports: - 5432:5432 diff --git a/integrationtests/tests/tests_lnbitsmock.rs b/integrationtests/tests/tests_lnbitsmock.rs index 64e13a87..69622f78 100644 --- a/integrationtests/tests/tests_lnbitsmock.rs +++ b/integrationtests/tests/tests_lnbitsmock.rs @@ -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 { diff --git a/integrationtests/tests/tests_lnd.rs b/integrationtests/tests/tests_lnd.rs index 49580edf..85d87164 100644 --- a/integrationtests/tests/tests_lnd.rs +++ b/integrationtests/tests/tests_lnd.rs @@ -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?; @@ -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?; @@ -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?; diff --git a/integrationtests/tests/tests_moksha_cli.rs b/integrationtests/tests/tests_moksha_cli.rs index 137d1723..30610346 100644 --- a/integrationtests/tests/tests_moksha_cli.rs +++ b/integrationtests/tests/tests_moksha_cli.rs @@ -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?; diff --git a/moksha-mint/src/mint.rs b/moksha-mint/src/mint.rs index 1c8673d9..81b90612 100644 --- a/moksha-mint/src/mint.rs +++ b/moksha-mint/src/mint.rs @@ -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?; @@ -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?; @@ -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?; @@ -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?; @@ -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?; @@ -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?; @@ -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?; @@ -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(|_| { @@ -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(), @@ -750,8 +730,11 @@ mod tests { Ok(db) } - fn create_postgres_image() -> RunnableImage { - let node = Postgres::default().with_host_auth(); - RunnableImage::from(node).with_tag("16.2-alpine") + async fn create_postgres_image() -> anyhow::Result> { + Ok(Postgres::default() + .with_host_auth() + .with_tag("16.6-alpine") + .start() + .await?) } } diff --git a/moksha-mint/src/server.rs b/moksha-mint/src/server.rs index aed51483..22720ee4 100644 --- a/moksha-mint/src/server.rs +++ b/moksha-mint/src/server.rs @@ -288,7 +288,8 @@ mod tests { primitives::{CurrencyUnit, KeysResponse, MintInfoResponse}, }; - use testcontainers::{clients::Cli, RunnableImage}; + use testcontainers::runners::AsyncRunner; + use testcontainers::{ContainerAsync, ImageExt}; use testcontainers_modules::postgres::Postgres; use tower::ServiceExt; @@ -301,11 +302,9 @@ mod tests { #[tokio::test] async fn test_get_keys() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); - - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let node = create_postgres_image().await?; + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/v1/keys").body(Body::empty())?) .await?; @@ -319,11 +318,9 @@ mod tests { #[tokio::test] async fn test_get_keysets() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); - - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let node = create_postgres_image().await?; + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/v1/keysets").body(Body::empty())?) .await?; @@ -350,9 +347,12 @@ mod tests { Ok(db) } - fn create_postgres_image() -> RunnableImage { - let node = Postgres::default().with_host_auth(); - RunnableImage::from(node).with_tag("16.2-alpine") + async fn create_postgres_image() -> anyhow::Result> { + Ok(Postgres::default() + .with_host_auth() + .with_tag("16.6-alpine") + .start() + .await?) } async fn create_mock_mint(info: MintInfoConfig, db_port: u16) -> anyhow::Result { @@ -377,11 +377,9 @@ mod tests { #[tokio::test] async fn test_get_keys_v1() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); - - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let node = create_postgres_image().await?; + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/v1/keys").body(Body::empty())?) .await?; @@ -399,11 +397,10 @@ mod tests { #[tokio::test] async fn test_get_keysets_v1() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); + let node = create_postgres_image().await?; - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/v1/keysets").body(Body::empty())?) .await?; @@ -418,11 +415,9 @@ mod tests { #[tokio::test] async fn test_get_v1_keys() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); - - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let node = create_postgres_image().await?; + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/v1/keys").body(Body::empty())?) .await?; @@ -440,11 +435,9 @@ mod tests { #[tokio::test] async fn test_get_v1_keys_id_invalid() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); - - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let node = create_postgres_image().await?; + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot( Request::builder() @@ -459,11 +452,9 @@ mod tests { #[tokio::test] async fn test_get_v1_keys_id() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); - - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let node = create_postgres_image().await?; + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot( Request::builder() @@ -489,11 +480,9 @@ mod tests { #[tokio::test] async fn test_get_v1_keysets() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); - - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let node = create_postgres_image().await?; + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/v1/keysets").body(Body::empty())?) .await?; @@ -511,11 +500,10 @@ mod tests { #[tokio::test] async fn test_get_health() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); + let node = create_postgres_image().await?; - let app = app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432)).await?); + let app = + app(create_mock_mint(Default::default(), node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/health").body(Body::empty())?) .await?; @@ -526,9 +514,7 @@ mod tests { #[tokio::test] async fn test_get_info() -> anyhow::Result<()> { - let docker = Cli::default(); - let image = create_postgres_image(); - let node = docker.run(image); + let node = create_postgres_image().await?; let mint_info_settings = MintInfoConfig { name: Some("Bob's Cashu mint".to_string()), @@ -537,7 +523,8 @@ mod tests { description_long: Some("A mint for testing long".to_string()), ..Default::default() }; - let app = app(create_mock_mint(mint_info_settings, node.get_host_port_ipv4(5432)).await?); + let app = + app(create_mock_mint(mint_info_settings, node.get_host_port_ipv4(5432).await?).await?); let response = app .oneshot(Request::builder().uri("/v1/info").body(Body::empty())?) .await?;