mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Upgrade testcontainers from 0.12 to 0.14 (#1552)
* Upgrade testcontainers from 0.12 to 0.14 * minor cleanup --------- Co-authored-by: Byron Hambly <bhambly@blockstream.com>
This commit is contained in:
parent
9c5914ff7a
commit
b2ca1b5f8c
43
Cargo.lock
generated
43
Cargo.lock
generated
@ -366,7 +366,7 @@ dependencies = [
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"testcontainers 0.14.0",
|
||||
"testcontainers",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
@ -896,16 +896,6 @@ dependencies = [
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-mac"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-mac"
|
||||
version = "0.11.1"
|
||||
@ -1598,16 +1588,6 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46"
|
||||
|
||||
[[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"
|
||||
version = "0.11.0"
|
||||
@ -2468,7 +2448,7 @@ dependencies = [
|
||||
"monero-rpc",
|
||||
"rand 0.7.3",
|
||||
"spectral",
|
||||
"testcontainers 0.12.0",
|
||||
"testcontainers",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber 0.2.25",
|
||||
@ -2504,7 +2484,7 @@ dependencies = [
|
||||
"monero-harness",
|
||||
"monero-rpc",
|
||||
"rand 0.7.3",
|
||||
"testcontainers 0.12.0",
|
||||
"testcontainers",
|
||||
"tokio",
|
||||
"tracing-subscriber 0.2.25",
|
||||
]
|
||||
@ -4363,7 +4343,7 @@ dependencies = [
|
||||
"structopt",
|
||||
"strum 0.26.1",
|
||||
"tempfile",
|
||||
"testcontainers 0.12.0",
|
||||
"testcontainers",
|
||||
"thiserror",
|
||||
"time 0.3.34",
|
||||
"tokio",
|
||||
@ -4467,21 +4447,6 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "testcontainers"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5e3ed6e3598dbf32cba8cb356b881c085e0adea57597f387723430dd94b4084"
|
||||
dependencies = [
|
||||
"hex",
|
||||
"hmac 0.10.1",
|
||||
"log",
|
||||
"rand 0.8.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.9.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "testcontainers"
|
||||
version = "0.14.0"
|
||||
|
@ -11,7 +11,7 @@ futures = "0.3"
|
||||
monero-rpc = { path = "../monero-rpc" }
|
||||
rand = "0.7"
|
||||
spectral = "0.6"
|
||||
testcontainers = "0.12"
|
||||
testcontainers = "0.14"
|
||||
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "macros" ] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "tracing-log" ] }
|
||||
|
@ -1,6 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use testcontainers::core::{Container, Docker, WaitForMessage};
|
||||
use testcontainers::Image;
|
||||
use testcontainers::{core::WaitFor, Image, ImageArgs};
|
||||
|
||||
pub const MONEROD_DAEMON_CONTAINER_NAME: &str = "monerod";
|
||||
pub const MONEROD_DEFAULT_NETWORK: &str = "monero_network";
|
||||
@ -13,43 +11,22 @@ pub const MONEROD_DEFAULT_NETWORK: &str = "monero_network";
|
||||
/// this doesn't matter.
|
||||
pub const RPC_PORT: u16 = 18081;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Monerod {
|
||||
args: MonerodArgs,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Monerod;
|
||||
|
||||
impl Image for Monerod {
|
||||
type Args = MonerodArgs;
|
||||
type EnvVars = HashMap<String, String>;
|
||||
type Volumes = HashMap<String, String>;
|
||||
type EntryPoint = str;
|
||||
|
||||
fn descriptor(&self) -> String {
|
||||
"rinocommunity/monero:v0.18.1.2".to_owned()
|
||||
fn name(&self) -> String {
|
||||
"rinocommunity/monero".into()
|
||||
}
|
||||
|
||||
fn wait_until_ready<D: Docker>(&self, container: &Container<'_, D, Self>) {
|
||||
container
|
||||
.logs()
|
||||
.stdout
|
||||
.wait_for_message("RPC server started ok")
|
||||
.unwrap();
|
||||
fn tag(&self) -> String {
|
||||
"v0.18.1.2".into()
|
||||
}
|
||||
|
||||
fn args(&self) -> <Self as Image>::Args {
|
||||
self.args.clone()
|
||||
}
|
||||
|
||||
fn volumes(&self) -> Self::Volumes {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn env_vars(&self) -> Self::EnvVars {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn with_args(self, args: <Self as Image>::Args) -> Self {
|
||||
Self { args }
|
||||
fn ready_conditions(&self) -> Vec<WaitFor> {
|
||||
vec![WaitFor::message_on_stdout("RPC server started ok")]
|
||||
}
|
||||
|
||||
fn entrypoint(&self) -> Option<String> {
|
||||
@ -58,43 +35,22 @@ impl Image for Monerod {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct MoneroWalletRpc {
|
||||
args: MoneroWalletRpcArgs,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct MoneroWalletRpc;
|
||||
|
||||
impl Image for MoneroWalletRpc {
|
||||
type Args = MoneroWalletRpcArgs;
|
||||
type EnvVars = HashMap<String, String>;
|
||||
type Volumes = HashMap<String, String>;
|
||||
type EntryPoint = str;
|
||||
|
||||
fn descriptor(&self) -> String {
|
||||
"rinocommunity/monero:v0.18.1.2".to_owned()
|
||||
fn name(&self) -> String {
|
||||
"rinocommunity/monero".into()
|
||||
}
|
||||
|
||||
fn wait_until_ready<D: Docker>(&self, container: &Container<'_, D, Self>) {
|
||||
container
|
||||
.logs()
|
||||
.stdout
|
||||
.wait_for_message("Run server thread name: RPC")
|
||||
.unwrap();
|
||||
fn tag(&self) -> String {
|
||||
"v0.18.1.2".into()
|
||||
}
|
||||
|
||||
fn args(&self) -> <Self as Image>::Args {
|
||||
self.args.clone()
|
||||
}
|
||||
|
||||
fn volumes(&self) -> Self::Volumes {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn env_vars(&self) -> Self::EnvVars {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn with_args(self, args: <Self as Image>::Args) -> Self {
|
||||
Self { args }
|
||||
fn ready_conditions(&self) -> Vec<WaitFor> {
|
||||
vec![WaitFor::message_on_stdout("Run server thread name: RPC")]
|
||||
}
|
||||
|
||||
fn entrypoint(&self) -> Option<String> {
|
||||
@ -104,10 +60,9 @@ impl Image for MoneroWalletRpc {
|
||||
}
|
||||
|
||||
impl MoneroWalletRpc {
|
||||
pub fn new(name: &str, daemon_address: String) -> Self {
|
||||
Self {
|
||||
args: MoneroWalletRpcArgs::new(name, daemon_address),
|
||||
}
|
||||
pub fn new(name: &str, daemon_address: String) -> (Self, MoneroWalletRpcArgs) {
|
||||
let args = MoneroWalletRpcArgs::new(name, daemon_address);
|
||||
(Self, args)
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,6 +146,12 @@ impl IntoIterator for MonerodArgs {
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageArgs for MonerodArgs {
|
||||
fn into_iterator(self) -> Box<dyn Iterator<Item = String>> {
|
||||
Box::new(self.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MoneroWalletRpcArgs {
|
||||
pub disable_rpc_login: bool,
|
||||
@ -200,12 +161,6 @@ pub struct MoneroWalletRpcArgs {
|
||||
pub daemon_address: String,
|
||||
}
|
||||
|
||||
impl Default for MoneroWalletRpcArgs {
|
||||
fn default() -> Self {
|
||||
unimplemented!("A default instance for `MoneroWalletRpc` doesn't make sense because we always need to connect to a node.")
|
||||
}
|
||||
}
|
||||
|
||||
impl MoneroWalletRpcArgs {
|
||||
pub fn new(wallet_name: &str, daemon_address: String) -> Self {
|
||||
Self {
|
||||
@ -247,3 +202,9 @@ impl IntoIterator for MoneroWalletRpcArgs {
|
||||
args.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageArgs for MoneroWalletRpcArgs {
|
||||
fn into_iterator(self) -> Box<dyn Iterator<Item = String>> {
|
||||
Box::new(self.into_iter())
|
||||
}
|
||||
}
|
||||
|
@ -20,17 +20,20 @@
|
||||
//! every BLOCK_TIME_SECS seconds.
|
||||
//!
|
||||
//! Also provides standalone JSON RPC clients for monerod and monero-wallet-rpc.
|
||||
pub mod image;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::image::{MONEROD_DAEMON_CONTAINER_NAME, MONEROD_DEFAULT_NETWORK, RPC_PORT};
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use testcontainers::clients::Cli;
|
||||
use testcontainers::{Container, RunnableImage};
|
||||
use tokio::time;
|
||||
|
||||
use monero_rpc::monerod;
|
||||
use monero_rpc::monerod::MonerodRpc as _;
|
||||
use monero_rpc::wallet::{self, GetAddress, MoneroWalletRpc as _, Refreshed, Transfer};
|
||||
use std::time::Duration;
|
||||
use testcontainers::clients::Cli;
|
||||
use testcontainers::{Container, Docker, RunArgs};
|
||||
use tokio::time;
|
||||
|
||||
use crate::image::{MONEROD_DAEMON_CONTAINER_NAME, MONEROD_DEFAULT_NETWORK, RPC_PORT};
|
||||
|
||||
pub mod image;
|
||||
|
||||
/// How often we mine a block.
|
||||
const BLOCK_TIME_SECS: u64 = 1;
|
||||
@ -56,8 +59,8 @@ impl<'c> Monero {
|
||||
additional_wallets: Vec<&'static str>,
|
||||
) -> Result<(
|
||||
Self,
|
||||
Container<'c, Cli, image::Monerod>,
|
||||
Vec<Container<'c, Cli, image::MoneroWalletRpc>>,
|
||||
Container<'c, image::Monerod>,
|
||||
Vec<Container<'c, image::MoneroWalletRpc>>,
|
||||
)> {
|
||||
let prefix = format!("{}_", random_prefix());
|
||||
let monerod_name = format!("{}{}", prefix, MONEROD_DAEMON_CONTAINER_NAME);
|
||||
@ -221,15 +224,14 @@ impl<'c> Monerod {
|
||||
cli: &'c Cli,
|
||||
name: String,
|
||||
network: String,
|
||||
) -> Result<(Self, Container<'c, Cli, image::Monerod>)> {
|
||||
) -> Result<(Self, Container<'c, image::Monerod>)> {
|
||||
let image = image::Monerod::default();
|
||||
let run_args = RunArgs::default()
|
||||
.with_name(name.clone())
|
||||
let image: RunnableImage<image::Monerod> = RunnableImage::from(image)
|
||||
.with_container_name(name.clone())
|
||||
.with_network(network.clone());
|
||||
let container = cli.run_with_args(image, run_args);
|
||||
let monerod_rpc_port = container
|
||||
.get_host_port(RPC_PORT)
|
||||
.context("port not exposed")?;
|
||||
|
||||
let container = cli.run(image);
|
||||
let monerod_rpc_port = container.get_host_port_ipv4(RPC_PORT);
|
||||
|
||||
Ok((
|
||||
Self {
|
||||
@ -262,19 +264,15 @@ impl<'c> MoneroWalletRpc {
|
||||
name: &str,
|
||||
monerod: &Monerod,
|
||||
prefix: String,
|
||||
) -> Result<(Self, Container<'c, Cli, image::MoneroWalletRpc>)> {
|
||||
) -> Result<(Self, Container<'c, image::MoneroWalletRpc>)> {
|
||||
let daemon_address = format!("{}:{}", monerod.name, RPC_PORT);
|
||||
let image = image::MoneroWalletRpc::new(name, daemon_address);
|
||||
let (image, args) = image::MoneroWalletRpc::new(name, daemon_address);
|
||||
let image = RunnableImage::from((image, args))
|
||||
.with_container_name(format!("{}{}", prefix, name))
|
||||
.with_network(monerod.network.clone());
|
||||
|
||||
let network = monerod.network.clone();
|
||||
let run_args = RunArgs::default()
|
||||
// prefix the container name so we can run multiple tests
|
||||
.with_name(format!("{}{}", prefix, name))
|
||||
.with_network(network.clone());
|
||||
let container = cli.run_with_args(image, run_args);
|
||||
let wallet_rpc_port = container
|
||||
.get_host_port(RPC_PORT)
|
||||
.context("port not exposed")?;
|
||||
let container = cli.run(image);
|
||||
let wallet_rpc_port = container.get_host_port_ipv4(RPC_PORT);
|
||||
|
||||
let client = wallet::Client::localhost(wallet_rpc_port)?;
|
||||
|
||||
|
@ -14,6 +14,6 @@ rand = "0.7"
|
||||
curve25519-dalek = "3"
|
||||
monero-harness = { path = "../monero-harness" }
|
||||
rand = "0.7"
|
||||
testcontainers = "0.12"
|
||||
testcontainers = "0.14"
|
||||
tokio = { version = "1", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs" ] }
|
||||
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "chrono", "tracing-log" ] }
|
||||
|
@ -61,13 +61,12 @@ mod tests {
|
||||
use monero_harness::image::Monerod;
|
||||
use monero_rpc::monerod::{Client, GetOutputsOut};
|
||||
use testcontainers::clients::Cli;
|
||||
use testcontainers::Docker;
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_outs_for_key_offsets() {
|
||||
let cli = Cli::default();
|
||||
let container = cli.run(Monerod::default());
|
||||
let rpc_client = Client::localhost(container.get_host_port(18081).unwrap()).unwrap();
|
||||
let rpc_client = Client::localhost(container.get_host_port_ipv4(18081)).unwrap();
|
||||
rpc_client.generateblocks(150, "498AVruCDWgP9Az9LjMm89VWjrBrSZ2W2K3HFBiyzzrRjUJWUcCVxvY1iitfuKoek2FdX6MKGAD9Qb1G1P8QgR5jPmmt3Vj".to_owned()).await.unwrap();
|
||||
let wallet = Wallet {
|
||||
client: rpc_client.clone(),
|
||||
|
@ -85,7 +85,7 @@ serde_cbor = "0.11"
|
||||
serial_test = "3.0"
|
||||
spectral = "0.6"
|
||||
tempfile = "3"
|
||||
testcontainers = "0.12"
|
||||
testcontainers = "0.14"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1"
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use testcontainers::core::{Container, Docker, WaitForMessage};
|
||||
use testcontainers::Image;
|
||||
use std::collections::BTreeMap;
|
||||
use testcontainers::{core::WaitFor, Image, ImageArgs};
|
||||
|
||||
pub const RPC_USER: &str = "admin";
|
||||
pub const RPC_PASSWORD: &str = "123";
|
||||
@ -10,57 +9,27 @@ pub const DATADIR: &str = "/home/bdk";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Bitcoind {
|
||||
args: BitcoindArgs,
|
||||
entrypoint: Option<String>,
|
||||
volume: Option<String>,
|
||||
volumes: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl Image for Bitcoind {
|
||||
type Args = BitcoindArgs;
|
||||
type EnvVars = HashMap<String, String>;
|
||||
type Volumes = HashMap<String, String>;
|
||||
type EntryPoint = str;
|
||||
|
||||
fn descriptor(&self) -> String {
|
||||
"coblox/bitcoin-core:0.21.0".to_string()
|
||||
fn name(&self) -> String {
|
||||
"coblox/bitcoin-core".into()
|
||||
}
|
||||
|
||||
fn wait_until_ready<D: Docker>(&self, container: &Container<'_, D, Self>) {
|
||||
container
|
||||
.logs()
|
||||
.stdout
|
||||
.wait_for_message("init message: Done loading")
|
||||
.unwrap();
|
||||
fn tag(&self) -> String {
|
||||
"0.21.0".into()
|
||||
}
|
||||
|
||||
fn args(&self) -> <Self as Image>::Args {
|
||||
self.args.clone()
|
||||
fn ready_conditions(&self) -> Vec<WaitFor> {
|
||||
vec![WaitFor::message_on_stdout("init message: Done loading")]
|
||||
}
|
||||
|
||||
fn volumes(&self) -> Self::Volumes {
|
||||
let mut volumes = HashMap::new();
|
||||
match self.volume.clone() {
|
||||
None => {}
|
||||
Some(volume) => {
|
||||
volumes.insert(volume, DATADIR.to_string());
|
||||
}
|
||||
}
|
||||
volumes
|
||||
}
|
||||
|
||||
fn env_vars(&self) -> Self::EnvVars {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn with_args(self, args: <Self as Image>::Args) -> Self {
|
||||
Bitcoind { args, ..self }
|
||||
}
|
||||
|
||||
fn with_entrypoint(self, entrypoint: &Self::EntryPoint) -> Self {
|
||||
Self {
|
||||
entrypoint: Some(entrypoint.to_string()),
|
||||
..self
|
||||
}
|
||||
fn volumes(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
|
||||
Box::new(self.volumes.iter())
|
||||
}
|
||||
|
||||
fn entrypoint(&self) -> Option<String> {
|
||||
@ -71,16 +40,15 @@ impl Image for Bitcoind {
|
||||
impl Default for Bitcoind {
|
||||
fn default() -> Self {
|
||||
Bitcoind {
|
||||
args: BitcoindArgs::default(),
|
||||
entrypoint: Some("/usr/bin/bitcoind".into()),
|
||||
volume: None,
|
||||
volumes: BTreeMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Bitcoind {
|
||||
pub fn with_volume(mut self, volume: String) -> Self {
|
||||
self.volume = Some(volume);
|
||||
self.volumes.insert(volume, DATADIR.to_string());
|
||||
self
|
||||
}
|
||||
}
|
||||
@ -109,7 +77,6 @@ impl IntoIterator for BitcoindArgs {
|
||||
format!("-rpcuser={}", RPC_USER),
|
||||
format!("-rpcpassword={}", RPC_PASSWORD),
|
||||
"-printtoconsole".to_string(),
|
||||
"-rest".to_string(),
|
||||
"-fallbackfee=0.0002".to_string(),
|
||||
format!("-datadir={}", DATADIR),
|
||||
format!("-rpcport={}", RPC_PORT),
|
||||
@ -120,3 +87,9 @@ impl IntoIterator for BitcoindArgs {
|
||||
args.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageArgs for BitcoindArgs {
|
||||
fn into_iterator(self) -> Box<dyn Iterator<Item = String>> {
|
||||
Box::new(self.into_iter())
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::harness::bitcoind;
|
||||
use bitcoin::Network;
|
||||
use std::collections::HashMap;
|
||||
use testcontainers::core::{Container, Docker, WaitForMessage};
|
||||
use testcontainers::Image;
|
||||
use testcontainers::{core::WaitFor, Image, ImageArgs};
|
||||
|
||||
pub const HTTP_PORT: u16 = 60401;
|
||||
pub const RPC_PORT: u16 = 3002;
|
||||
@ -13,50 +13,25 @@ pub struct Electrs {
|
||||
args: ElectrsArgs,
|
||||
entrypoint: Option<String>,
|
||||
wait_for_message: String,
|
||||
volume: String,
|
||||
volumes: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl Image for Electrs {
|
||||
type Args = ElectrsArgs;
|
||||
type EnvVars = HashMap<String, String>;
|
||||
type Volumes = HashMap<String, String>;
|
||||
type EntryPoint = str;
|
||||
|
||||
fn descriptor(&self) -> String {
|
||||
format!("vulpemventures/electrs:{}", self.tag)
|
||||
fn name(&self) -> String {
|
||||
"vulpemventures/electrs".into()
|
||||
}
|
||||
|
||||
fn wait_until_ready<D: Docker>(&self, container: &Container<'_, D, Self>) {
|
||||
container
|
||||
.logs()
|
||||
.stderr
|
||||
.wait_for_message(&self.wait_for_message)
|
||||
.unwrap();
|
||||
fn tag(&self) -> String {
|
||||
self.tag.clone()
|
||||
}
|
||||
|
||||
fn args(&self) -> <Self as Image>::Args {
|
||||
self.args.clone()
|
||||
fn ready_conditions(&self) -> Vec<WaitFor> {
|
||||
vec![WaitFor::message_on_stderr(self.wait_for_message.clone())]
|
||||
}
|
||||
|
||||
fn volumes(&self) -> Self::Volumes {
|
||||
let mut volumes = HashMap::new();
|
||||
volumes.insert(self.volume.clone(), bitcoind::DATADIR.to_string());
|
||||
volumes
|
||||
}
|
||||
|
||||
fn env_vars(&self) -> Self::EnvVars {
|
||||
HashMap::new()
|
||||
}
|
||||
|
||||
fn with_args(self, args: <Self as Image>::Args) -> Self {
|
||||
Electrs { args, ..self }
|
||||
}
|
||||
|
||||
fn with_entrypoint(self, entrypoint: &Self::EntryPoint) -> Self {
|
||||
Self {
|
||||
entrypoint: Some(entrypoint.to_string()),
|
||||
..self
|
||||
}
|
||||
fn volumes(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
|
||||
Box::new(self.volumes.iter())
|
||||
}
|
||||
|
||||
fn entrypoint(&self) -> Option<String> {
|
||||
@ -71,7 +46,7 @@ impl Default for Electrs {
|
||||
args: ElectrsArgs::default(),
|
||||
entrypoint: Some("/build/electrs".into()),
|
||||
wait_for_message: "Running accept thread".to_string(),
|
||||
volume: uuid::Uuid::new_v4().to_string(),
|
||||
volumes: BTreeMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,7 +60,7 @@ impl Electrs {
|
||||
}
|
||||
|
||||
pub fn with_volume(mut self, volume: String) -> Self {
|
||||
self.volume = volume;
|
||||
self.volumes.insert(volume, bitcoind::DATADIR.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
@ -93,6 +68,11 @@ impl Electrs {
|
||||
self.args.daemon_rpc_addr = name;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn self_and_args(self) -> (Self, ElectrsArgs) {
|
||||
let args = self.args.clone();
|
||||
(self, args)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -137,7 +117,7 @@ impl IntoIterator for ElectrsArgs {
|
||||
}
|
||||
|
||||
args.push("-vvvvv".to_string());
|
||||
args.push(format!("--daemon-dir=={}", self.daemon_dir.as_str()));
|
||||
args.push(format!("--daemon-dir={}", self.daemon_dir.as_str()));
|
||||
args.push(format!("--daemon-rpc-addr={}", self.daemon_rpc_addr));
|
||||
args.push(format!("--cookie={}", self.cookie));
|
||||
args.push(format!("--http-addr={}", self.http_addr));
|
||||
@ -147,3 +127,9 @@ impl IntoIterator for ElectrsArgs {
|
||||
args.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageArgs for ElectrsArgs {
|
||||
fn into_iterator(self) -> Box<dyn Iterator<Item = String>> {
|
||||
Box::new(self.into_iter())
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ use swap::seed::Seed;
|
||||
use swap::{asb, bitcoin, cli, env, monero};
|
||||
use tempfile::{tempdir, NamedTempFile};
|
||||
use testcontainers::clients::Cli;
|
||||
use testcontainers::{Container, Docker, RunArgs};
|
||||
use testcontainers::{Container, RunnableImage};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
use tokio::task::JoinHandle;
|
||||
@ -61,10 +61,7 @@ where
|
||||
let alice_starting_balances =
|
||||
StartingBalances::new(bitcoin::Amount::ZERO, xmr_amount, Some(10));
|
||||
|
||||
let electrs_rpc_port = containers
|
||||
.electrs
|
||||
.get_host_port(electrs::RPC_PORT)
|
||||
.expect("Could not map electrs rpc port");
|
||||
let electrs_rpc_port = containers.electrs.get_host_port_ipv4(electrs::RPC_PORT);
|
||||
|
||||
let alice_seed = Seed::random().unwrap();
|
||||
let (alice_bitcoin_wallet, alice_monero_wallet) = init_test_wallets(
|
||||
@ -146,14 +143,14 @@ where
|
||||
async fn init_containers(cli: &Cli) -> (Monero, Containers<'_>) {
|
||||
let prefix = random_prefix();
|
||||
let bitcoind_name = format!("{}_{}", prefix, "bitcoind");
|
||||
let (bitcoind, bitcoind_url) =
|
||||
let (_bitcoind, bitcoind_url, mapped_port) =
|
||||
init_bitcoind_container(cli, prefix.clone(), bitcoind_name.clone(), prefix.clone())
|
||||
.await
|
||||
.expect("could not init bitcoind");
|
||||
let electrs = init_electrs_container(cli, prefix.clone(), bitcoind_name, prefix)
|
||||
let electrs = init_electrs_container(cli, prefix.clone(), bitcoind_name, prefix, mapped_port)
|
||||
.await
|
||||
.expect("could not init electrs");
|
||||
let (monero, monerod_container, monero_wallet_rpc_containers) =
|
||||
let (monero, _monerod_container, _monero_wallet_rpc_containers) =
|
||||
Monero::new(cli, vec![MONERO_WALLET_NAME_ALICE, MONERO_WALLET_NAME_BOB])
|
||||
.await
|
||||
.unwrap();
|
||||
@ -162,9 +159,9 @@ async fn init_containers(cli: &Cli) -> (Monero, Containers<'_>) {
|
||||
monero,
|
||||
Containers {
|
||||
bitcoind_url,
|
||||
bitcoind,
|
||||
monerod_container,
|
||||
monero_wallet_rpc_containers,
|
||||
_bitcoind,
|
||||
_monerod_container,
|
||||
_monero_wallet_rpc_containers,
|
||||
electrs,
|
||||
},
|
||||
)
|
||||
@ -175,29 +172,28 @@ async fn init_bitcoind_container(
|
||||
volume: String,
|
||||
name: String,
|
||||
network: String,
|
||||
) -> Result<(Container<'_, Cli, bitcoind::Bitcoind>, Url)> {
|
||||
) -> Result<(Container<'_, bitcoind::Bitcoind>, Url, u16)> {
|
||||
let image = bitcoind::Bitcoind::default().with_volume(volume);
|
||||
let image = RunnableImage::from(image)
|
||||
.with_container_name(name)
|
||||
.with_network(network);
|
||||
|
||||
let run_args = RunArgs::default().with_name(name).with_network(network);
|
||||
|
||||
let docker = cli.run_with_args(image, run_args);
|
||||
let a = docker
|
||||
.get_host_port(bitcoind::RPC_PORT)
|
||||
.context("Could not map bitcoind rpc port")?;
|
||||
let docker = cli.run(image);
|
||||
let port = docker.get_host_port_ipv4(bitcoind::RPC_PORT);
|
||||
|
||||
let bitcoind_url = {
|
||||
let input = format!(
|
||||
"http://{}:{}@localhost:{}",
|
||||
bitcoind::RPC_USER,
|
||||
bitcoind::RPC_PASSWORD,
|
||||
a
|
||||
port
|
||||
);
|
||||
Url::parse(&input).unwrap()
|
||||
};
|
||||
|
||||
init_bitcoind(bitcoind_url.clone(), 5).await?;
|
||||
|
||||
Ok((docker, bitcoind_url.clone()))
|
||||
Ok((docker, bitcoind_url.clone(), bitcoind::RPC_PORT))
|
||||
}
|
||||
|
||||
pub async fn init_electrs_container(
|
||||
@ -205,16 +201,18 @@ pub async fn init_electrs_container(
|
||||
volume: String,
|
||||
bitcoind_container_name: String,
|
||||
network: String,
|
||||
) -> Result<Container<'_, Cli, electrs::Electrs>> {
|
||||
let bitcoind_rpc_addr = format!("{}:{}", bitcoind_container_name, bitcoind::RPC_PORT);
|
||||
port: u16,
|
||||
) -> Result<Container<'_, electrs::Electrs>> {
|
||||
let bitcoind_rpc_addr = format!("{}:{}", bitcoind_container_name, port);
|
||||
let image = electrs::Electrs::default()
|
||||
.with_volume(volume)
|
||||
.with_daemon_rpc_addr(bitcoind_rpc_addr)
|
||||
.with_tag("latest");
|
||||
let image = RunnableImage::from(image.self_and_args())
|
||||
.with_network(network.clone())
|
||||
.with_container_name(format!("{}_electrs", network));
|
||||
|
||||
let run_args = RunArgs::default().with_network(network);
|
||||
|
||||
let docker = cli.run_with_args(image, run_args);
|
||||
let docker = cli.run(image);
|
||||
|
||||
Ok(docker)
|
||||
}
|
||||
@ -952,13 +950,12 @@ pub async fn mint(node_url: Url, address: bitcoin::Address, amount: bitcoin::Amo
|
||||
}
|
||||
|
||||
// This is just to keep the containers alive
|
||||
#[allow(dead_code)]
|
||||
struct Containers<'a> {
|
||||
bitcoind_url: Url,
|
||||
bitcoind: Container<'a, Cli, bitcoind::Bitcoind>,
|
||||
monerod_container: Container<'a, Cli, image::Monerod>,
|
||||
monero_wallet_rpc_containers: Vec<Container<'a, Cli, image::MoneroWalletRpc>>,
|
||||
electrs: Container<'a, Cli, electrs::Electrs>,
|
||||
_bitcoind: Container<'a, bitcoind::Bitcoind>,
|
||||
_monerod_container: Container<'a, image::Monerod>,
|
||||
_monero_wallet_rpc_containers: Vec<Container<'a, image::MoneroWalletRpc>>,
|
||||
electrs: Container<'a, electrs::Electrs>,
|
||||
}
|
||||
|
||||
pub mod alice_run_until {
|
||||
|
Loading…
Reference in New Issue
Block a user