From 8c83f7e2e15e6c7909ab1b7e57d2177119f1570f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 16 Feb 2021 17:09:09 +1100 Subject: [PATCH] Upgrade to testcontainers v0.12 --- Cargo.lock | 41 +++++++++++++++++++++++++++++--- monero-harness/Cargo.toml | 2 +- monero-harness/src/image.rs | 15 +----------- monero-harness/src/lib.rs | 22 +++++++++-------- swap/Cargo.toml | 2 +- swap/tests/testutils/bitcoind.rs | 6 +---- swap/tests/testutils/electrs.rs | 6 +---- 7 files changed, 55 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4b7b63c..3249c494 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,7 +321,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "testcontainers", + "testcontainers 0.11.0", "thiserror", "tokio 1.0.2", "tracing", @@ -726,6 +726,16 @@ dependencies = [ "subtle 2.4.0", ] +[[package]] +name = "crypto-mac" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" +dependencies = [ + "generic-array 0.14.4", + "subtle 2.4.0", +] + [[package]] name = "csv" version = "1.1.5" @@ -1382,6 +1392,16 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "hmac" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" +dependencies = [ + "crypto-mac 0.10.0", + "digest 0.9.0", +] + [[package]] name = "hmac-drbg" version = "0.2.0" @@ -2008,7 +2028,7 @@ dependencies = [ "serde", "serde_json", "spectral", - "testcontainers", + "testcontainers 0.12.0", "tokio 1.0.2", "tracing", "tracing-log", @@ -3513,7 +3533,7 @@ dependencies = [ "structopt", "strum", "tempfile", - "testcontainers", + "testcontainers 0.12.0", "thiserror", "time", "tokio 1.0.2", @@ -3602,6 +3622,21 @@ dependencies = [ "sha2 0.9.2", ] +[[package]] +name = "testcontainers" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5e3ed6e3598dbf32cba8cb356b881c085e0adea57597f387723430dd94b4084" +dependencies = [ + "hex 0.4.2", + "hmac 0.10.1", + "log", + "rand 0.8.2", + "serde", + "serde_json", + "sha2 0.9.2", +] + [[package]] name = "textwrap" version = "0.11.0" diff --git a/monero-harness/Cargo.toml b/monero-harness/Cargo.toml index 44d4e782..a9704b0a 100644 --- a/monero-harness/Cargo.toml +++ b/monero-harness/Cargo.toml @@ -14,7 +14,7 @@ reqwest = { version = "0.11", default-features = false, features = ["json", "nat serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" spectral = "0.6" -testcontainers = "0.11" +testcontainers = "0.12" tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "time", "macros"] } tracing = "0.1" tracing-log = "0.1" diff --git a/monero-harness/src/image.rs b/monero-harness/src/image.rs index 81cc8723..b2342602 100644 --- a/monero-harness/src/image.rs +++ b/monero-harness/src/image.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, env::var, thread::sleep, time::Duration}; use testcontainers::{ - core::{Container, Docker, Port, WaitForMessage}, + core::{Container, Docker, WaitForMessage}, Image, }; @@ -13,7 +13,6 @@ pub const WALLET_RPC_PORT: u16 = 48083; pub struct Monero { tag: String, args: Args, - ports: Option>, entrypoint: Option, wait_for_message: String, } @@ -57,10 +56,6 @@ impl Image for Monero { HashMap::new() } - fn ports(&self) -> Option> { - self.ports.clone() - } - fn with_args(self, args: ::Args) -> Self { Monero { args, ..self } } @@ -82,7 +77,6 @@ impl Default for Monero { Monero { tag: "v0.16.0.3".into(), args: Args::default(), - ports: None, entrypoint: Some("".into()), wait_for_message: "core RPC server started ok".to_string(), } @@ -97,13 +91,6 @@ impl Monero { } } - pub fn with_mapped_port>(mut self, port: P) -> Self { - let mut ports = self.ports.unwrap_or_default(); - ports.push(port.into()); - self.ports = Some(ports); - self - } - pub fn wallet(name: &str, daemon_address: String) -> Self { let wallet = WalletArgs::new(name, daemon_address, WALLET_RPC_PORT); let default = Monero::default(); diff --git a/monero-harness/src/lib.rs b/monero-harness/src/lib.rs index 477418e3..2601fae3 100644 --- a/monero-harness/src/lib.rs +++ b/monero-harness/src/lib.rs @@ -183,13 +183,14 @@ impl<'c> Monerod { let monerod_rpc_port: u16 = port_check::free_local_port().ok_or_else(|| anyhow!("Could not retrieve free port"))?; - let image = image::Monero::default().with_mapped_port(Port { - local: monerod_rpc_port, - internal: MONEROD_RPC_PORT, - }); + let image = image::Monero::default(); let run_args = RunArgs::default() .with_name(name.clone()) - .with_network(network.clone()); + .with_network(network.clone()) + .with_mapped_port(Port { + local: monerod_rpc_port, + internal: MONEROD_RPC_PORT, + }); let docker = cli.run_with_args(image, run_args); Ok(( @@ -227,15 +228,16 @@ impl<'c> MoneroWalletRpc { port_check::free_local_port().ok_or_else(|| anyhow!("Could not retrieve free port"))?; let daemon_address = format!("{}:{}", monerod.name, MONEROD_RPC_PORT); - let image = image::Monero::wallet(&name, daemon_address).with_mapped_port(Port { - local: wallet_rpc_port, - internal: WALLET_RPC_PORT, - }); + let image = image::Monero::wallet(&name, daemon_address); let network = monerod.network.clone(); let run_args = RunArgs::default() .with_name(name) - .with_network(network.clone()); + .with_network(network.clone()) + .with_mapped_port(Port { + local: wallet_rpc_port, + internal: WALLET_RPC_PORT, + }); let docker = cli.run_with_args(image, run_args); // create new wallet diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 23bafb11..faeee257 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -71,4 +71,4 @@ port_check = "0.1" serde_cbor = "0.11" spectral = "0.6" tempfile = "3" -testcontainers = "0.11" +testcontainers = "0.12" diff --git a/swap/tests/testutils/bitcoind.rs b/swap/tests/testutils/bitcoind.rs index 3ab4f447..c151a38e 100644 --- a/swap/tests/testutils/bitcoind.rs +++ b/swap/tests/testutils/bitcoind.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use testcontainers::{ - core::{Container, Docker, Port, WaitForMessage}, + core::{Container, Docker, WaitForMessage}, Image, }; @@ -55,10 +55,6 @@ impl Image for Bitcoind { HashMap::new() } - fn ports(&self) -> Option> { - None - } - fn with_args(self, args: ::Args) -> Self { Bitcoind { args, ..self } } diff --git a/swap/tests/testutils/electrs.rs b/swap/tests/testutils/electrs.rs index 5507f1e5..0917f920 100644 --- a/swap/tests/testutils/electrs.rs +++ b/swap/tests/testutils/electrs.rs @@ -2,7 +2,7 @@ use crate::testutils::bitcoind; use bitcoin::Network; use std::collections::HashMap; use testcontainers::{ - core::{Container, Docker, Port, WaitForMessage}, + core::{Container, Docker, WaitForMessage}, Image, }; @@ -51,10 +51,6 @@ impl Image for Electrs { HashMap::new() } - fn ports(&self) -> Option> { - None - } - fn with_args(self, args: ::Args) -> Self { Electrs { args, ..self } }