From 101d9c2578dd59981183c3943a08fa1a4b171855 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Mon, 26 Aug 2024 13:44:24 +0530 Subject: [PATCH 1/2] Add template provider to integration test --- roles/Cargo.lock | 392 +++++++++++++++++++- roles/tests-integration/Cargo.toml | 4 + roles/tests-integration/tests/common/mod.rs | 151 ++++++++ 3 files changed, 539 insertions(+), 8 deletions(-) diff --git a/roles/Cargo.lock b/roles/Cargo.lock index 03c5acf6c4..af5f8304fb 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -17,6 +17,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "aead" version = "0.5.2" @@ -121,6 +127,18 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-attributes" version = "1.1.2" @@ -354,11 +372,27 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.7.2", "object", "rustc-demangle", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.7" @@ -371,6 +405,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "binary_codec_sv2" version = "1.2.0" @@ -395,17 +435,60 @@ version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0694ea59225b0c5f3cb405ff3f670e4828358ed26aec49dc352f730f0cb1a8a3" dependencies = [ - "bech32", + "bech32 0.9.1", "bitcoin_hashes 0.11.0", "secp256k1 0.24.3", ] +[[package]] +name = "bitcoin" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" +dependencies = [ + "base58ck", + "bech32 0.11.0", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.1", + "hex_lit", + "secp256k1 0.29.0", + "serde", +] + [[package]] name = "bitcoin-internals" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + +[[package]] +name = "bitcoin-units" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" +dependencies = [ + "bitcoin-internals 0.3.0", + "serde", +] + [[package]] name = "bitcoin_hashes" version = "0.3.2" @@ -427,8 +510,56 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", - "hex-conservative", + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.1", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative 0.2.1", + "serde", +] + +[[package]] +name = "bitcoincore-rpc" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedd23ae0fd321affb4bbbc36126c6f49a32818dc6b979395d24da8c9d4e80ee" +dependencies = [ + "bitcoincore-rpc-json", + "jsonrpc", + "log", + "serde", + "serde_json", +] + +[[package]] +name = "bitcoincore-rpc-json" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8909583c5fab98508e80ef73e5592a651c954993dc6b7739963257d19f0e71a" +dependencies = [ + "bitcoin 0.32.2", + "serde", + "serde_json", +] + +[[package]] +name = "bitcoind" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ee5cf6a9903ff9cc808494c1232b0e9f6eef6600913d0d69fe1cb5c428f25b9" +dependencies = [ + "anyhow", + "bitcoincore-rpc", + "log", + "tempfile", + "which", ] [[package]] @@ -701,6 +832,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-utils" version = "0.8.19" @@ -768,6 +908,12 @@ dependencies = [ "const-random", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "env_logger" version = "0.7.1" @@ -864,6 +1010,28 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", +] + +[[package]] +name = "flate2" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +dependencies = [ + "crc32fast", + "miniz_oxide 0.8.0", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1120,6 +1288,30 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "hex_lit" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "1.1.0" @@ -1247,6 +1439,12 @@ dependencies = [ [[package]] name = "integration-test" version = "0.1.0" +dependencies = [ + "bitcoind", + "flate2", + "minreq", + "tar", +] [[package]] name = "io-lifetimes" @@ -1351,6 +1549,18 @@ dependencies = [ "serde", ] +[[package]] +name = "jsonrpc" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf" +dependencies = [ + "base64 0.13.1", + "minreq", + "serde", + "serde_json", +] + [[package]] name = "key-utils" version = "1.1.0" @@ -1494,6 +1704,30 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "minreq" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763d142cdff44aaadd9268bebddb156ef6c65a0e13486bb81673cf2d8739f9b0" +dependencies = [ + "log", + "once_cell", + "rustls", + "rustls-webpki", + "serde", + "serde_json", + "webpki-roots", +] + [[package]] name = "mio" version = "0.8.11" @@ -1657,7 +1891,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.1", "smallvec", "windows-targets 0.52.5", ] @@ -1906,6 +2140,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.1" @@ -1944,6 +2187,21 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "roles_logic_sv2" version = "1.2.1" @@ -1968,7 +2226,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "base64", + "base64 0.21.7", "bitflags 2.5.0", "serde", "serde_derive", @@ -1978,7 +2236,7 @@ dependencies = [ name = "rpc_sv2" version = "1.0.0" dependencies = [ - "base64", + "base64 0.21.7", "hex", "http-body-util", "hyper", @@ -2031,6 +2289,28 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.18" @@ -2043,6 +2323,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "secp256k1" version = "0.24.3" @@ -2064,6 +2354,18 @@ dependencies = [ "secp256k1-sys 0.9.2", ] +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" +dependencies = [ + "bitcoin_hashes 0.13.0", + "rand", + "secp256k1-sys 0.10.0", + "serde", +] + [[package]] name = "secp256k1-sys" version = "0.6.1" @@ -2082,6 +2384,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" +dependencies = [ + "cc", +] + [[package]] name = "serde" version = "1.0.200" @@ -2213,11 +2524,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "stratum-common" version = "1.0.0" dependencies = [ - "bitcoin", + "bitcoin 0.29.2", "secp256k1 0.28.2", ] @@ -2285,6 +2602,30 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tar" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb797dad5fb5b76fcf519e702f4a589483b5ef06567f160c392832c1f5e44909" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "tempfile" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fcd239983515c23a32fb82099f97d0b11b8c72f654ed659363a95c3dad7a53" +dependencies = [ + "cfg-if", + "fastrand 2.1.0", + "once_cell", + "rustix 0.38.34", + "windows-sys 0.52.0", +] + [[package]] name = "template_distribution_sv2" version = "1.0.2" @@ -2575,6 +2916,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "utf8parse" version = "0.2.1" @@ -2696,6 +3043,24 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix 0.38.34", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2875,6 +3240,17 @@ dependencies = [ "memchr", ] +[[package]] +name = "xattr" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" +dependencies = [ + "libc", + "linux-raw-sys 0.4.13", + "rustix 0.38.34", +] + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/roles/tests-integration/Cargo.toml b/roles/tests-integration/Cargo.toml index 6eaed2218f..00eab65fa5 100644 --- a/roles/tests-integration/Cargo.toml +++ b/roles/tests-integration/Cargo.toml @@ -4,6 +4,10 @@ version = "0.1.0" edition = "2021" [dependencies] +bitcoind = "0.36.0" +flate2 = "1.0.32" +minreq = { version = "2.12.0", features = ["https"] } +tar = "0.4.41" [lib] path = "tests/common/mod.rs" diff --git a/roles/tests-integration/tests/common/mod.rs b/roles/tests-integration/tests/common/mod.rs index 8b13789179..56e12f2006 100644 --- a/roles/tests-integration/tests/common/mod.rs +++ b/roles/tests-integration/tests/common/mod.rs @@ -1 +1,152 @@ +use bitcoind::{bitcoincore_rpc::RpcApi, BitcoinD, Conf}; +use flate2::read::GzDecoder; +use std::{ + env, + fs::{create_dir_all, File}, + io::{BufReader, Read}, + path::{Path, PathBuf}, +}; +use tar::Archive; +const VERSION_TP: &str = "0.1.7"; + +fn download_bitcoind_tarball(download_url: &str) -> Vec { + let response = minreq::get(download_url) + .send() + .expect(&format!("Cannot reach URL: {}", download_url)); + assert_eq!( + response.status_code, 200, + "URL {} didn't return 200", + download_url + ); + response.as_bytes().to_vec() +} + +fn read_tarball_from_file(path: &str) -> Vec { + let file = File::open(path).unwrap_or_else(|_| { + panic!( + "Cannot find {:?} specified with env var BITCOIND_TARBALL_FILE", + path + ) + }); + let mut reader = BufReader::new(file); + let mut buffer = Vec::new(); + reader.read_to_end(&mut buffer).unwrap(); + buffer +} + +fn unpack_tarball(tarball_bytes: &[u8], destination: &Path) { + let decoder = GzDecoder::new(tarball_bytes); + let mut archive = Archive::new(decoder); + for mut entry in archive.entries().unwrap().flatten() { + if let Ok(file) = entry.path() { + if file.ends_with("bitcoind") { + entry.unpack_in(destination).unwrap(); + } + } + } +} + +fn get_bitcoind_filename(os: &str, arch: &str) -> String { + match (os, arch) { + ("macos", "aarch64") => format!("bitcoin-sv2-tp-{}-arm64-apple-darwin.tar.gz", VERSION_TP), + ("macos", "x86_64") => format!("bitcoin-sv2-tp-{}-x86_64-apple-darwin.tar.gz", VERSION_TP), + ("linux", "x86_64") => format!("bitcoin-sv2-tp-{}-x86_64-linux-gnu.tar.gz", VERSION_TP), + ("linux", "aarch64") => format!("bitcoin-sv2-tp-{}-aarch64-linux-gnu.tar.gz", VERSION_TP), + _ => format!( + "bitcoin-sv2-tp-{}-x86_64-apple-darwin-unsigned.zip", + VERSION_TP + ), + } +} + +pub struct TemplateProvider { + bitcoind: BitcoinD, +} + +impl TemplateProvider { + pub fn start() -> Self { + let temp_dir = PathBuf::from("/tmp/.template-provider/"); + + let mut conf = Conf::default(); + conf.args.extend(vec![ + "-txindex=1", + "-sv2", + "-sv2port=8442", + "-debug=sv2", + "-sv2interval=20", + "-sv2feedelta=1000", + "-loglevel=sv2:trace", + ]); + conf.staticdir = Some(temp_dir.join(".bitcoin")); + + let os = env::consts::OS; + let arch = env::consts::ARCH; + let download_filename = get_bitcoind_filename(os, arch); + let bitcoin_exe_home = temp_dir + .join(format!("bitcoin-sv2-tp-{}", VERSION_TP)) + .join("bin"); + + if !bitcoin_exe_home.exists() { + let tarball_bytes = match env::var("BITCOIND_TARBALL_FILE") { + Ok(path) => read_tarball_from_file(&path), + Err(_) => { + let download_endpoint = + env::var("BITCOIND_DOWNLOAD_ENDPOINT").unwrap_or_else(|_| { + "https://github.com/Sjors/bitcoin/releases/download".to_owned() + }); + let url = format!( + "{}/sv2-tp-{}/{}", + download_endpoint, VERSION_TP, download_filename + ); + download_bitcoind_tarball(&url) + } + }; + + if let Some(parent) = bitcoin_exe_home.parent() { + create_dir_all(parent).unwrap(); + } + + unpack_tarball(&tarball_bytes, &temp_dir); + + if os == "macos" { + let bitcoind_binary = bitcoin_exe_home.join("bitcoind"); + std::process::Command::new("codesign") + .arg("--sign") + .arg("-") + .arg(&bitcoind_binary) + .output() + .expect("Failed to sign bitcoind binary"); + } + } + + env::set_var("BITCOIND_EXE", bitcoin_exe_home.join("bitcoind")); + let exe_path = bitcoind::exe_path().unwrap(); + + let bitcoind = BitcoinD::with_conf(exe_path, &conf).unwrap(); + + TemplateProvider { bitcoind } + } + + pub fn stop(&self) { + let _ = self.bitcoind.client.stop().unwrap(); + } + + pub fn generate_blocks(&self, n: u64) { + let mining_address = self + .bitcoind + .client + .get_new_address(None, None) + .unwrap() + .require_network(bitcoind::bitcoincore_rpc::bitcoin::Network::Regtest) + .unwrap(); + self.bitcoind + .client + .generate_to_address(n, &mining_address) + .unwrap(); + } + + pub fn get_block_count(&self) -> u64 { + self.bitcoind.client.get_block_count().unwrap() + } +} From 8c8b687ec582db61b44d2388197d428161a9f176 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Wed, 4 Sep 2024 13:13:42 +0300 Subject: [PATCH 2/2] Make TP test module port configurable This enables running multiple TP's across different tests simultaneously. --- roles/tests-integration/tests/common/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/roles/tests-integration/tests/common/mod.rs b/roles/tests-integration/tests/common/mod.rs index 56e12f2006..5d37b39d5e 100644 --- a/roles/tests-integration/tests/common/mod.rs +++ b/roles/tests-integration/tests/common/mod.rs @@ -13,7 +13,7 @@ const VERSION_TP: &str = "0.1.7"; fn download_bitcoind_tarball(download_url: &str) -> Vec { let response = minreq::get(download_url) .send() - .expect(&format!("Cannot reach URL: {}", download_url)); + .unwrap_or_else(|_| panic!("Cannot reach URL: {}", download_url)); assert_eq!( response.status_code, 200, "URL {} didn't return 200", @@ -65,14 +65,16 @@ pub struct TemplateProvider { } impl TemplateProvider { - pub fn start() -> Self { - let temp_dir = PathBuf::from("/tmp/.template-provider/"); + pub fn start(port: u16) -> Self { + let path_name = format!("/tmp/.template-provider-{}", port); + let temp_dir = PathBuf::from(&path_name); let mut conf = Conf::default(); + let port = format!("-sv2port={}", port); conf.args.extend(vec![ "-txindex=1", "-sv2", - "-sv2port=8442", + &port, "-debug=sv2", "-sv2interval=20", "-sv2feedelta=1000",