dockertest 0.4 (#406)

* Updates to modern dockertest

* More updates to latest dockertest

* Update Cargo.lock to dockertest with handle restored

* clippy coordinator tests

* clippy full-stack tests

* Remove kayabaNerve branch for official repo's latest commit hash

* Update serai-client, remove reliance on the existence of a handle fn

* Don't use the hex encoding of unique_id in dockertests

Gets our hostnames just below 64 bytes, resolving test failures on at least
Debian-based systems.

* Use Network::Isolated for all dockertest instances

* Correct error from prior commit's edits
This commit is contained in:
Luke Parker 2023-10-23 06:59:38 -04:00 committed by GitHub
parent 0d23964762
commit c4bdbdde11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 178 additions and 196 deletions

109
Cargo.lock generated
View file

@ -647,11 +647,11 @@ dependencies = [
[[package]] [[package]]
name = "bollard" name = "bollard"
version = "0.13.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82e7850583ead5f8bbef247e2a3c37a19bd576e8420cd262a6711921827e1e5" checksum = "f03db470b3c0213c47e978da93200259a1eb4dae2e5512cba9955e2b540a6fc6"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.21.4",
"bollard-stubs", "bollard-stubs",
"bytes", "bytes",
"futures-core", "futures-core",
@ -665,6 +665,7 @@ dependencies = [
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"serde_repr",
"serde_urlencoded", "serde_urlencoded",
"thiserror", "thiserror",
"tokio", "tokio",
@ -675,11 +676,12 @@ dependencies = [
[[package]] [[package]]
name = "bollard-stubs" name = "bollard-stubs"
version = "1.42.0-rc.3" version = "1.43.0-rc.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed59b5c00048f48d7af971b71f800fdf23e858844a6f9e4d32ca72e9399e7864" checksum = "b58071e8fd9ec1e930efd28e3a90c1251015872a2ce49f81f36421b86466932e"
dependencies = [ dependencies = [
"serde", "serde",
"serde_repr",
"serde_with", "serde_with",
] ]
@ -886,6 +888,7 @@ dependencies = [
"iana-time-zone", "iana-time-zone",
"js-sys", "js-sys",
"num-traits", "num-traits",
"serde",
"wasm-bindgen", "wasm-bindgen",
"windows-targets", "windows-targets",
] ]
@ -1485,16 +1488,6 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[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]] [[package]]
name = "darling" name = "darling"
version = "0.14.4" version = "0.14.4"
@ -1515,20 +1508,6 @@ dependencies = [
"darling_macro 0.20.3", "darling_macro 0.20.3",
] ]
[[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",
"syn 1.0.109",
]
[[package]] [[package]]
name = "darling_core" name = "darling_core"
version = "0.14.4" version = "0.14.4"
@ -1557,17 +1536,6 @@ dependencies = [
"syn 2.0.38", "syn 2.0.38",
] ]
[[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]] [[package]]
name = "darling_macro" name = "darling_macro"
version = "0.14.4" version = "0.14.4"
@ -1656,6 +1624,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
dependencies = [ dependencies = [
"powerfmt", "powerfmt",
"serde",
] ]
[[package]] [[package]]
@ -1691,12 +1660,6 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "diff"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
[[package]] [[package]]
name = "difflib" name = "difflib"
version = "0.4.0" version = "0.4.0"
@ -1847,13 +1810,13 @@ dependencies = [
[[package]] [[package]]
name = "dockertest" name = "dockertest"
version = "0.3.1" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce5e89cd7c59faf3cf0e31369fce2382807dd794d4fcce6380adcefdf5987796" checksum = "88933ed892cc8f5be247da11a1cd86a5c64802ac0172982e8aeb8315cb6dacfa"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"base64 0.13.1", "base64 0.21.4",
"bollard", "bollard",
"dyn-clone", "dyn-clone",
"futures", "futures",
@ -3616,6 +3579,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"hashbrown 0.12.3", "hashbrown 0.12.3",
"serde",
] ]
[[package]] [[package]]
@ -3948,16 +3912,14 @@ dependencies = [
[[package]] [[package]]
name = "lalrpop" name = "lalrpop"
version = "0.20.0" version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da4081d44f4611b66c6dd725e6de3169f9f63905421e8626fcb86b6a898998b8" checksum = "83be602e051ada38d90c7841092adabeb585197afe9dabb20e4f8375cc87846e"
dependencies = [ dependencies = [
"ascii-canvas", "ascii-canvas",
"bit-set", "bit-set",
"diff",
"ena", "ena",
"is-terminal", "itertools 0.11.0",
"itertools 0.10.5",
"lalrpop-util", "lalrpop-util",
"petgraph", "petgraph",
"regex", "regex",
@ -3970,9 +3932,9 @@ dependencies = [
[[package]] [[package]]
name = "lalrpop-util" name = "lalrpop-util"
version = "0.20.0" version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f35c735096c0293d313e8f2a641627472b83d01b937177fe76e5e2708d31e0d" checksum = "365d88f9d803538a06641e6736f21d95ecf9226dc1693421212e62c405cdd199"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
@ -8674,6 +8636,17 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_repr"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
]
[[package]] [[package]]
name = "serde_spanned" name = "serde_spanned"
version = "0.6.3" version = "0.6.3"
@ -8697,24 +8670,18 @@ dependencies = [
[[package]] [[package]]
name = "serde_with" name = "serde_with"
version = "1.14.0" version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23"
dependencies = [ dependencies = [
"base64 0.21.4",
"chrono",
"hex",
"indexmap 1.9.3",
"indexmap 2.0.2",
"serde", "serde",
"serde_with_macros", "serde_json",
] "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]] [[package]]

View file

@ -43,7 +43,7 @@ schnorrkel = { path = "../../crypto/schnorrkel", package = "frost-schnorrkel" }
tokio = "1" tokio = "1"
dockertest = "0.3" dockertest = "0.4"
serai-docker-tests = { path = "../../tests/docker" } serai-docker-tests = { path = "../../tests/docker" }
[features] [features]

View file

@ -9,37 +9,38 @@ macro_rules! serai_test {
#[tokio::test] #[tokio::test]
async fn $name() { async fn $name() {
use dockertest::{ use dockertest::{
PullPolicy, StartPolicy, LogOptions, LogAction, LogPolicy, LogSource, Image, Composition, PullPolicy, StartPolicy, LogOptions, LogAction, LogPolicy, LogSource, Image,
DockerTest, TestBodySpecification, DockerTest,
}; };
serai_docker_tests::build("serai".to_string()); serai_docker_tests::build("serai".to_string());
let mut composition = Composition::with_image( let handle = concat!("serai_client-serai_node-", stringify!($name));
let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never),
) )
.with_cmd(vec![ .replace_cmd(vec![
"serai-node".to_string(), "serai-node".to_string(),
"--dev".to_string(), "--dev".to_string(),
"--unsafe-rpc-external".to_string(), "--unsafe-rpc-external".to_string(),
"--rpc-cors".to_string(), "--rpc-cors".to_string(),
"all".to_string(), "all".to_string(),
]) ])
.with_start_policy(StartPolicy::Strict) .set_publish_all_ports(true)
.with_log_options(Some(LogOptions { .set_handle(handle)
.set_start_policy(StartPolicy::Strict)
.set_log_options(Some(LogOptions {
action: LogAction::Forward, action: LogAction::Forward,
policy: LogPolicy::Always, policy: LogPolicy::Always,
source: LogSource::Both, source: LogSource::Both,
})); }));
composition.publish_all_ports();
let handle = composition.handle(); let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
test.provide_container(composition);
let mut test = DockerTest::new();
test.add_composition(composition);
test.run_async(|ops| async move { test.run_async(|ops| async move {
// Sleep until the Substrate RPC starts // Sleep until the Substrate RPC starts
let serai_rpc = ops.handle(&handle).host_port(9944).unwrap(); let serai_rpc = ops.handle(handle).host_port(9944).unwrap();
let serai_rpc = format!("ws://{}:{}", serai_rpc.0, serai_rpc.1); let serai_rpc = format!("ws://{}:{}", serai_rpc.0, serai_rpc.1);
// Bound execution to 60 seconds // Bound execution to 60 seconds
for _ in 0 .. 60 { for _ in 0 .. 60 {

View file

@ -36,6 +36,6 @@ serde_json = { version = "1", default-features = false }
tokio = { version = "1", features = ["time"] } tokio = { version = "1", features = ["time"] }
dockertest = "0.3" dockertest = "0.4"
serai-docker-tests = { path = "../docker" } serai-docker-tests = { path = "../docker" }
serai-message-queue-tests = { path = "../message-queue" } serai-message-queue-tests = { path = "../message-queue" }

View file

@ -18,8 +18,8 @@ use serai_message_queue::{Service, Metadata, client::MessageQueue};
use serai_client::Serai; use serai_client::Serai;
use dockertest::{ use dockertest::{
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition, PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy,
DockerOperations, TestBodySpecification, DockerOperations,
}; };
#[cfg(test)] #[cfg(test)]
@ -30,13 +30,13 @@ static UNIQUE_ID: OnceLock<Mutex<u16>> = OnceLock::new();
pub fn coordinator_instance( pub fn coordinator_instance(
name: &str, name: &str,
message_queue_key: <Ristretto as Ciphersuite>::F, message_queue_key: <Ristretto as Ciphersuite>::F,
) -> Composition { ) -> TestBodySpecification {
serai_docker_tests::build("coordinator".to_string()); serai_docker_tests::build("coordinator".to_string());
Composition::with_image( TestBodySpecification::with_image(
Image::with_repository("serai-dev-coordinator").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-coordinator").pull_policy(PullPolicy::Never),
) )
.with_env( .replace_env(
[ [
("MESSAGE_QUEUE_KEY".to_string(), hex::encode(message_queue_key.to_repr())), ("MESSAGE_QUEUE_KEY".to_string(), hex::encode(message_queue_key.to_repr())),
("DB_PATH".to_string(), "./coordinator-db".to_string()), ("DB_PATH".to_string(), "./coordinator-db".to_string()),
@ -53,13 +53,13 @@ pub fn coordinator_instance(
) )
} }
pub fn serai_composition(name: &str) -> Composition { pub fn serai_composition(name: &str) -> TestBodySpecification {
serai_docker_tests::build("serai".to_string()); serai_docker_tests::build("serai".to_string());
let mut composition = Composition::with_image( TestBodySpecification::with_image(
Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never),
) )
.with_cmd(vec![ .replace_cmd(vec![
"serai-node".to_string(), "serai-node".to_string(),
"--unsafe-rpc-external".to_string(), "--unsafe-rpc-external".to_string(),
"--rpc-cors".to_string(), "--rpc-cors".to_string(),
@ -67,13 +67,14 @@ pub fn serai_composition(name: &str) -> Composition {
"--chain".to_string(), "--chain".to_string(),
"local".to_string(), "local".to_string(),
format!("--{}", name.to_lowercase()), format!("--{}", name.to_lowercase()),
]); ])
composition.publish_all_ports(); .set_publish_all_ports(true)
composition
} }
pub type Handles = (String, String, String); pub type Handles = (String, String, String);
pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<Composition>) { pub fn coordinator_stack(
name: &str,
) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<TestBodySpecification>) {
let serai_composition = serai_composition(name); let serai_composition = serai_composition(name);
let (coord_key, message_queue_keys, message_queue_composition) = let (coord_key, message_queue_keys, message_queue_composition) =
@ -87,7 +88,7 @@ pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F,
let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0)); let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0));
let mut unique_id_lock = unique_id_mutex.lock().unwrap(); let mut unique_id_lock = unique_id_mutex.lock().unwrap();
let first = *unique_id_lock == 0; let first = *unique_id_lock == 0;
let unique_id = hex::encode(unique_id_lock.to_be_bytes()); let unique_id = *unique_id_lock;
*unique_id_lock += 1; *unique_id_lock += 1;
(first, unique_id) (first, unique_id)
}; };
@ -107,14 +108,16 @@ pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F,
let mut compositions = vec![]; let mut compositions = vec![];
let mut handles = vec![]; let mut handles = vec![];
for composition in [serai_composition, message_queue_composition, coordinator_composition] { for (name, composition) in [
let name = format!("{}-{}", composition.handle(), &unique_id); ("serai_node", serai_composition),
("message_queue", message_queue_composition),
("coordinator", coordinator_composition),
] {
let handle = format!("coordinator-{name}-{unique_id}");
compositions.push( compositions.push(
composition composition.set_start_policy(StartPolicy::Strict).set_handle(handle.clone()).set_log_options(
.with_start_policy(StartPolicy::Strict) Some(LogOptions {
.with_container_name(name.clone())
.with_log_options(Some(LogOptions {
action: if std::env::var("GITHUB_CI") == Ok("true".to_string()) { action: if std::env::var("GITHUB_CI") == Ok("true".to_string()) {
LogAction::Forward LogAction::Forward
} else { } else {
@ -122,18 +125,19 @@ pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F,
}, },
policy: LogPolicy::Always, policy: LogPolicy::Always,
source: LogSource::Both, source: LogSource::Both,
})), }),
),
); );
handles.push(compositions.last().unwrap().handle()); handles.push(handle);
} }
let coordinator_composition = compositions.last_mut().unwrap(); let coordinator_composition = compositions.last_mut().unwrap();
coordinator_composition.inject_container_name(handles.remove(0), "SERAI_HOSTNAME"); coordinator_composition.inject_container_name(handles[0].clone(), "SERAI_HOSTNAME");
coordinator_composition.inject_container_name(handles.remove(0), "MESSAGE_QUEUE_RPC"); coordinator_composition.inject_container_name(handles[1].clone(), "MESSAGE_QUEUE_RPC");
( (
(compositions[0].handle(), compositions[1].handle(), compositions[2].handle()), (handles[0].clone(), handles[1].clone(), handles[2].clone()),
message_queue_keys[&NetworkId::Bitcoin], message_queue_keys[&NetworkId::Bitcoin],
compositions, compositions,
) )

View file

@ -22,7 +22,7 @@ pub(crate) static ONE_AT_A_TIME: OnceLock<Mutex<()>> = OnceLock::new();
pub(crate) fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) { pub(crate) fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) {
let mut coordinators = vec![]; let mut coordinators = vec![];
let mut test = DockerTest::new(); let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
for i in 0 .. COORDINATORS { for i in 0 .. COORDINATORS {
let (handles, coord_key, compositions) = coordinator_stack(match i { let (handles, coord_key, compositions) = coordinator_stack(match i {
0 => "Alice", 0 => "Alice",
@ -35,7 +35,7 @@ pub(crate) fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, Dock
}); });
coordinators.push((handles, coord_key)); coordinators.push((handles, coord_key));
for composition in compositions { for composition in compositions {
test.add_composition(composition); test.provide_container(composition);
} }
} }
(coordinators, test) (coordinators, test)

View file

@ -34,7 +34,7 @@ serai-client = { path = "../../substrate/client", features = ["serai"] }
tokio = { version = "1", features = ["time"] } tokio = { version = "1", features = ["time"] }
dockertest = "0.3" dockertest = "0.4"
serai-docker-tests = { path = "../docker" } serai-docker-tests = { path = "../docker" }
serai-message-queue-tests = { path = "../message-queue" } serai-message-queue-tests = { path = "../message-queue" }
serai-processor-tests = { path = "../processor" } serai-processor-tests = { path = "../processor" }

View file

@ -7,7 +7,7 @@ use std::{
use serai_client::{primitives::NetworkId, Serai}; use serai_client::{primitives::NetworkId, Serai};
use dockertest::{ use dockertest::{
LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition, DockerOperations, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, TestBodySpecification, DockerOperations,
}; };
#[cfg(test)] #[cfg(test)]
@ -31,7 +31,7 @@ pub struct Handles {
serai: String, serai: String,
} }
pub fn full_stack(name: &str) -> (Handles, Vec<Composition>) { pub fn full_stack(name: &str) -> (Handles, Vec<TestBodySpecification>) {
let (coord_key, message_queue_keys, message_queue_composition) = message_queue_instance(); let (coord_key, message_queue_keys, message_queue_composition) = message_queue_instance();
let (bitcoin_composition, bitcoin_port) = network_instance(NetworkId::Bitcoin); let (bitcoin_composition, bitcoin_port) = network_instance(NetworkId::Bitcoin);
@ -51,7 +51,7 @@ pub fn full_stack(name: &str) -> (Handles, Vec<Composition>) {
let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0)); let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0));
let mut unique_id_lock = unique_id_mutex.lock().unwrap(); let mut unique_id_lock = unique_id_mutex.lock().unwrap();
let first = *unique_id_lock == 0; let first = *unique_id_lock == 0;
let unique_id = hex::encode(unique_id_lock.to_be_bytes()); let unique_id = *unique_id_lock;
*unique_id_lock += 1; *unique_id_lock += 1;
(first, unique_id) (first, unique_id)
}; };
@ -71,22 +71,19 @@ pub fn full_stack(name: &str) -> (Handles, Vec<Composition>) {
let mut compositions = vec![]; let mut compositions = vec![];
let mut handles = vec![]; let mut handles = vec![];
for composition in [ for (name, composition) in [
message_queue_composition, ("message_queue", message_queue_composition),
bitcoin_composition, ("bitcoin", bitcoin_composition),
bitcoin_processor_composition, ("bitcoin_processor", bitcoin_processor_composition),
monero_composition, ("monero", monero_composition),
monero_processor_composition, ("monero_processor", monero_processor_composition),
coordinator_composition, ("coordinator", coordinator_composition),
serai_composition, ("serai", serai_composition),
] { ] {
let name = format!("{}-{}", composition.handle(), &unique_id); let handle = format!("full_stack-{name}-{unique_id}");
compositions.push( compositions.push(
composition composition.set_start_policy(StartPolicy::Strict).set_handle(handle.clone()).set_log_options(
.with_start_policy(StartPolicy::Strict) Some(LogOptions {
.with_container_name(name.clone())
.with_log_options(Some(LogOptions {
action: if std::env::var("GITHUB_CI") == Ok("true".to_string()) { action: if std::env::var("GITHUB_CI") == Ok("true".to_string()) {
LogAction::Forward LogAction::Forward
} else { } else {
@ -94,19 +91,19 @@ pub fn full_stack(name: &str) -> (Handles, Vec<Composition>) {
}, },
policy: LogPolicy::Always, policy: LogPolicy::Always,
source: LogSource::Both, source: LogSource::Both,
})), }),
),
); );
handles.push(handle);
handles.push(compositions.last().unwrap().handle());
} }
let handles = Handles { let handles = Handles {
message_queue: handles.remove(0), message_queue: handles[0].clone(),
bitcoin: (handles.remove(0), bitcoin_port), bitcoin: (handles[1].clone(), bitcoin_port),
bitcoin_processor: handles.remove(0), bitcoin_processor: handles[2].clone(),
monero: (handles.remove(0), monero_port), monero: (handles[3].clone(), monero_port),
monero_processor: handles.remove(0), monero_processor: handles[4].clone(),
coordinator: handles.remove(0), coordinator: handles[5].clone(),
serai: handles.remove(0), serai: handles[6].clone(),
}; };
{ {

View file

@ -13,7 +13,7 @@ pub(crate) static ONE_AT_A_TIME: OnceLock<Mutex<()>> = OnceLock::new();
pub(crate) fn new_test() -> (Vec<Handles>, DockerTest) { pub(crate) fn new_test() -> (Vec<Handles>, DockerTest) {
let mut validators = vec![]; let mut validators = vec![];
let mut test = DockerTest::new(); let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
for i in 0 .. VALIDATORS { for i in 0 .. VALIDATORS {
let (handles, compositions) = full_stack(match i { let (handles, compositions) = full_stack(match i {
0 => "Alice", 0 => "Alice",
@ -26,7 +26,7 @@ pub(crate) fn new_test() -> (Vec<Handles>, DockerTest) {
}); });
validators.push(handles); validators.push(handles);
for composition in compositions { for composition in compositions {
test.add_composition(composition); test.provide_container(composition);
} }
} }
(validators, test) (validators, test)

View file

@ -25,5 +25,5 @@ serai-primitives = { path = "../../substrate/primitives" }
serai-message-queue = { path = "../../message-queue" } serai-message-queue = { path = "../../message-queue" }
tokio = { version = "1", features = ["time"] } tokio = { version = "1", features = ["time"] }
dockertest = "0.3" dockertest = "0.4"
serai-docker-tests = { path = "../docker" } serai-docker-tests = { path = "../docker" }

View file

@ -9,11 +9,13 @@ use ciphersuite::{
use serai_primitives::NetworkId; use serai_primitives::NetworkId;
use dockertest::{PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, Composition}; use dockertest::{
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, TestBodySpecification,
};
pub type MessageQueuePrivateKey = <Ristretto as Ciphersuite>::F; pub type MessageQueuePrivateKey = <Ristretto as Ciphersuite>::F;
pub fn instance( pub fn instance(
) -> (MessageQueuePrivateKey, HashMap<NetworkId, MessageQueuePrivateKey>, Composition) { ) -> (MessageQueuePrivateKey, HashMap<NetworkId, MessageQueuePrivateKey>, TestBodySpecification) {
serai_docker_tests::build("message-queue".to_string()); serai_docker_tests::build("message-queue".to_string());
let coord_key = <Ristretto as Ciphersuite>::F::random(&mut OsRng); let coord_key = <Ristretto as Ciphersuite>::F::random(&mut OsRng);
@ -23,15 +25,15 @@ pub fn instance(
(NetworkId::Monero, <Ristretto as Ciphersuite>::F::random(&mut OsRng)), (NetworkId::Monero, <Ristretto as Ciphersuite>::F::random(&mut OsRng)),
]); ]);
let mut composition = Composition::with_image( let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-message-queue").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-message-queue").pull_policy(PullPolicy::Never),
) )
.with_log_options(Some(LogOptions { .set_log_options(Some(LogOptions {
action: LogAction::Forward, action: LogAction::Forward,
policy: LogPolicy::Always, policy: LogPolicy::Always,
source: LogSource::Both, source: LogSource::Both,
})) }))
.with_env( .replace_env(
[ [
("COORDINATOR_KEY".to_string(), hex::encode((Ristretto::generator() * coord_key).to_bytes())), ("COORDINATOR_KEY".to_string(), hex::encode((Ristretto::generator() * coord_key).to_bytes())),
( (
@ -50,8 +52,8 @@ pub fn instance(
("RUST_LOG".to_string(), "serai_message_queue=trace,".to_string()), ("RUST_LOG".to_string(), "serai_message_queue=trace,".to_string()),
] ]
.into(), .into(),
); )
composition.publish_all_ports(); .set_publish_all_ports(true);
(coord_key, priv_keys, composition) (coord_key, priv_keys, composition)
} }
@ -64,9 +66,9 @@ fn basic_functionality() {
use serai_message_queue::{Service, Metadata, client::MessageQueue}; use serai_message_queue::{Service, Metadata, client::MessageQueue};
let mut test = DockerTest::new(); let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
let (coord_key, priv_keys, composition) = instance(); let (coord_key, priv_keys, composition) = instance();
test.add_composition(composition); test.provide_container(composition);
test.run(|ops| async move { test.run(|ops| async move {
// Sleep for a second for the message-queue to boot // Sleep for a second for the message-queue to boot
// It isn't an error to start immediately, it just silences an error // It isn't an error to start immediately, it just silences an error

View file

@ -39,6 +39,6 @@ tokio = { version = "1", features = ["time"] }
processor = { package = "serai-processor", path = "../../processor", features = ["bitcoin", "monero"] } processor = { package = "serai-processor", path = "../../processor", features = ["bitcoin", "monero"] }
dockertest = "0.3" dockertest = "0.4"
serai-docker-tests = { path = "../docker" } serai-docker-tests = { path = "../docker" }
serai-message-queue-tests = { path = "../message-queue" } serai-message-queue-tests = { path = "../message-queue" }

View file

@ -12,8 +12,8 @@ use messages::{ProcessorMessage, CoordinatorMessage};
use serai_message_queue::{Service, Metadata, client::MessageQueue}; use serai_message_queue::{Service, Metadata, client::MessageQueue};
use dockertest::{ use dockertest::{
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition, PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy,
DockerOperations, TestBodySpecification, DockerOperations,
}; };
mod networks; mod networks;
@ -28,16 +28,16 @@ pub fn processor_instance(
network: NetworkId, network: NetworkId,
port: u32, port: u32,
message_queue_key: <Ristretto as Ciphersuite>::F, message_queue_key: <Ristretto as Ciphersuite>::F,
) -> Composition { ) -> TestBodySpecification {
serai_docker_tests::build("processor".to_string()); serai_docker_tests::build("processor".to_string());
let mut entropy = [0; 32]; let mut entropy = [0; 32];
OsRng.fill_bytes(&mut entropy); OsRng.fill_bytes(&mut entropy);
Composition::with_image( TestBodySpecification::with_image(
Image::with_repository("serai-dev-processor").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-processor").pull_policy(PullPolicy::Never),
) )
.with_env( .replace_env(
[ [
("MESSAGE_QUEUE_KEY".to_string(), hex::encode(message_queue_key.to_repr())), ("MESSAGE_QUEUE_KEY".to_string(), hex::encode(message_queue_key.to_repr())),
("ENTROPY".to_string(), hex::encode(entropy)), ("ENTROPY".to_string(), hex::encode(entropy)),
@ -63,7 +63,7 @@ pub fn processor_instance(
pub type Handles = (String, String, String); pub type Handles = (String, String, String);
pub fn processor_stack( pub fn processor_stack(
network: NetworkId, network: NetworkId,
) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<Composition>) { ) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<TestBodySpecification>) {
let (network_composition, network_rpc_port) = network_instance(network); let (network_composition, network_rpc_port) = network_instance(network);
let (coord_key, message_queue_keys, message_queue_composition) = let (coord_key, message_queue_keys, message_queue_composition) =
@ -77,37 +77,48 @@ pub fn processor_stack(
let unique_id = { let unique_id = {
let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0)); let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0));
let mut unique_id_lock = unique_id_mutex.lock().unwrap(); let mut unique_id_lock = unique_id_mutex.lock().unwrap();
let unique_id = hex::encode(unique_id_lock.to_be_bytes()); let unique_id = *unique_id_lock;
*unique_id_lock += 1; *unique_id_lock += 1;
unique_id unique_id
}; };
let mut compositions = vec![]; let mut compositions = vec![];
let mut handles = vec![]; let mut handles = vec![];
for composition in [network_composition, message_queue_composition, processor_composition] { for (name, composition) in [
let handle = composition.handle(); (
match network {
NetworkId::Serai => unreachable!(),
NetworkId::Bitcoin => "bitcoin",
NetworkId::Ethereum => "ethereum",
NetworkId::Monero => "monero",
},
network_composition,
),
("message_queue", message_queue_composition),
("processor", processor_composition),
] {
let handle = format!("processor-{name}-{unique_id}");
compositions.push( compositions.push(
composition composition.set_start_policy(StartPolicy::Strict).set_handle(handle.clone()).set_log_options(
.with_start_policy(StartPolicy::Strict) Some(LogOptions {
.with_container_name(format!("{handle}-{}", &unique_id))
.with_log_options(Some(LogOptions {
action: LogAction::Forward, action: LogAction::Forward,
policy: if handle.contains("processor") { LogPolicy::Always } else { LogPolicy::OnError }, policy: if handle.contains("-processor-") {
LogPolicy::Always
} else {
LogPolicy::OnError
},
source: LogSource::Both, source: LogSource::Both,
})), }),
),
); );
handles.push(compositions.last().unwrap().handle()); handles.push(handle);
} }
let processor_composition = compositions.last_mut().unwrap(); let processor_composition = compositions.last_mut().unwrap();
processor_composition.inject_container_name(handles.remove(0), "NETWORK_RPC_HOSTNAME"); processor_composition.inject_container_name(handles[0].clone(), "NETWORK_RPC_HOSTNAME");
processor_composition.inject_container_name(handles.remove(0), "MESSAGE_QUEUE_RPC"); processor_composition.inject_container_name(handles[1].clone(), "MESSAGE_QUEUE_RPC");
( ((handles[0].clone(), handles[1].clone(), handles[2].clone()), coord_key, compositions)
(compositions[0].handle(), compositions[1].handle(), compositions[2].handle()),
coord_key,
compositions,
)
} }
#[derive(serde::Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]

View file

@ -11,7 +11,7 @@ use serai_client::{
in_instructions::primitives::{InInstruction, RefundableInInstruction, Shorthand}, in_instructions::primitives::{InInstruction, RefundableInInstruction, Shorthand},
}; };
use dockertest::{PullPolicy, Image, StartPolicy, Composition, DockerOperations}; use dockertest::{PullPolicy, Image, StartPolicy, TestBodySpecification, DockerOperations};
use crate::*; use crate::*;
@ -21,13 +21,13 @@ pub const RPC_PASS: &str = "seraidex";
pub const BTC_PORT: u32 = 8332; pub const BTC_PORT: u32 = 8332;
pub const XMR_PORT: u32 = 18081; pub const XMR_PORT: u32 = 18081;
pub fn bitcoin_instance() -> (Composition, u32) { pub fn bitcoin_instance() -> (TestBodySpecification, u32) {
serai_docker_tests::build("bitcoin".to_string()); serai_docker_tests::build("bitcoin".to_string());
let mut composition = Composition::with_image( let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-bitcoin").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-bitcoin").pull_policy(PullPolicy::Never),
) )
.with_cmd(vec![ .replace_cmd(vec![
"bitcoind".to_string(), "bitcoind".to_string(),
"-txindex".to_string(), "-txindex".to_string(),
"-regtest".to_string(), "-regtest".to_string(),
@ -36,18 +36,18 @@ pub fn bitcoin_instance() -> (Composition, u32) {
"-rpcbind=0.0.0.0".to_string(), "-rpcbind=0.0.0.0".to_string(),
"-rpcallowip=0.0.0.0/0".to_string(), "-rpcallowip=0.0.0.0/0".to_string(),
"-rpcport=8332".to_string(), "-rpcport=8332".to_string(),
]); ])
composition.publish_all_ports(); .set_publish_all_ports(true);
(composition, BTC_PORT) (composition, BTC_PORT)
} }
pub fn monero_instance() -> (Composition, u32) { pub fn monero_instance() -> (TestBodySpecification, u32) {
serai_docker_tests::build("monero".to_string()); serai_docker_tests::build("monero".to_string());
let mut composition = Composition::with_image( let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-monero").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-monero").pull_policy(PullPolicy::Never),
) )
.with_cmd(vec![ .replace_cmd(vec![
"monerod".to_string(), "monerod".to_string(),
"--regtest".to_string(), "--regtest".to_string(),
"--offline".to_string(), "--offline".to_string(),
@ -58,12 +58,12 @@ pub fn monero_instance() -> (Composition, u32) {
"--confirm-external-bind".to_string(), "--confirm-external-bind".to_string(),
"--non-interactive".to_string(), "--non-interactive".to_string(),
]) ])
.with_start_policy(StartPolicy::Strict); .set_start_policy(StartPolicy::Strict)
composition.publish_all_ports(); .set_publish_all_ports(true);
(composition, XMR_PORT) (composition, XMR_PORT)
} }
pub fn network_instance(network: NetworkId) -> (Composition, u32) { pub fn network_instance(network: NetworkId) -> (TestBodySpecification, u32) {
match network { match network {
NetworkId::Bitcoin => bitcoin_instance(), NetworkId::Bitcoin => bitcoin_instance(),
NetworkId::Ethereum => todo!(), NetworkId::Ethereum => todo!(),

View file

@ -19,12 +19,12 @@ pub(crate) const THRESHOLD: usize = ((COORDINATORS * 2) / 3) + 1;
fn new_test(network: NetworkId) -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) { fn new_test(network: NetworkId) -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) {
let mut coordinators = vec![]; let mut coordinators = vec![];
let mut test = DockerTest::new(); let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
for _ in 0 .. COORDINATORS { for _ in 0 .. COORDINATORS {
let (handles, coord_key, compositions) = processor_stack(network); let (handles, coord_key, compositions) = processor_stack(network);
coordinators.push((handles, coord_key)); coordinators.push((handles, coord_key));
for composition in compositions { for composition in compositions {
test.add_composition(composition); test.provide_container(composition);
} }
} }
(coordinators, test) (coordinators, test)

View file

@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]
rand_core = "0.6" rand_core = "0.6"
hex = "0.4" hex = "0.4"
dockertest = "0.3" dockertest = "0.4"
serai-docker-tests = { path = "../docker" } serai-docker-tests = { path = "../docker" }
tokio = { version = "1", features = ["time"] } tokio = { version = "1", features = ["time"] }

View file

@ -4,7 +4,7 @@ pub fn reproducibly_builds() {
use rand_core::{RngCore, OsRng}; use rand_core::{RngCore, OsRng};
use dockertest::{PullPolicy, Image, Composition, DockerTest}; use dockertest::{PullPolicy, Image, TestBodySpecification, DockerTest};
const RUNS: usize = 3; const RUNS: usize = 3;
const TIMEOUT: u16 = 180 * 60; // 3 hours const TIMEOUT: u16 = 180 * 60; // 3 hours
@ -16,14 +16,14 @@ pub fn reproducibly_builds() {
OsRng.fill_bytes(id); OsRng.fill_bytes(id);
} }
let mut test = DockerTest::new(); let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
for id in &ids { for id in &ids {
test.add_composition( test.provide_container(
Composition::with_image( TestBodySpecification::with_image(
Image::with_repository("serai-dev-runtime").pull_policy(PullPolicy::Never), Image::with_repository("serai-dev-runtime").pull_policy(PullPolicy::Never),
) )
.with_container_name(format!("runtime-build-{}", hex::encode(id))) .set_handle(format!("runtime-build-{}", hex::encode(id)))
.with_cmd(vec![ .replace_cmd(vec![
"sh".to_string(), "sh".to_string(),
"-c".to_string(), "-c".to_string(),
// Sleep for a minute after building to prevent the container from closing before we // Sleep for a minute after building to prevent the container from closing before we