mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
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:
@@ -39,6 +39,6 @@ tokio = { version = "1", features = ["time"] }
|
||||
|
||||
processor = { package = "serai-processor", path = "../../processor", features = ["bitcoin", "monero"] }
|
||||
|
||||
dockertest = "0.3"
|
||||
dockertest = "0.4"
|
||||
serai-docker-tests = { path = "../docker" }
|
||||
serai-message-queue-tests = { path = "../message-queue" }
|
||||
|
||||
@@ -12,8 +12,8 @@ use messages::{ProcessorMessage, CoordinatorMessage};
|
||||
use serai_message_queue::{Service, Metadata, client::MessageQueue};
|
||||
|
||||
use dockertest::{
|
||||
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition,
|
||||
DockerOperations,
|
||||
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy,
|
||||
TestBodySpecification, DockerOperations,
|
||||
};
|
||||
|
||||
mod networks;
|
||||
@@ -28,16 +28,16 @@ pub fn processor_instance(
|
||||
network: NetworkId,
|
||||
port: u32,
|
||||
message_queue_key: <Ristretto as Ciphersuite>::F,
|
||||
) -> Composition {
|
||||
) -> TestBodySpecification {
|
||||
serai_docker_tests::build("processor".to_string());
|
||||
|
||||
let mut entropy = [0; 32];
|
||||
OsRng.fill_bytes(&mut entropy);
|
||||
|
||||
Composition::with_image(
|
||||
TestBodySpecification::with_image(
|
||||
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())),
|
||||
("ENTROPY".to_string(), hex::encode(entropy)),
|
||||
@@ -63,7 +63,7 @@ pub fn processor_instance(
|
||||
pub type Handles = (String, String, String);
|
||||
pub fn processor_stack(
|
||||
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 (coord_key, message_queue_keys, message_queue_composition) =
|
||||
@@ -77,37 +77,48 @@ pub fn processor_stack(
|
||||
let unique_id = {
|
||||
let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0));
|
||||
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
|
||||
};
|
||||
|
||||
let mut compositions = vec![];
|
||||
let mut handles = vec![];
|
||||
for composition in [network_composition, message_queue_composition, processor_composition] {
|
||||
let handle = composition.handle();
|
||||
for (name, composition) in [
|
||||
(
|
||||
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(
|
||||
composition
|
||||
.with_start_policy(StartPolicy::Strict)
|
||||
.with_container_name(format!("{handle}-{}", &unique_id))
|
||||
.with_log_options(Some(LogOptions {
|
||||
composition.set_start_policy(StartPolicy::Strict).set_handle(handle.clone()).set_log_options(
|
||||
Some(LogOptions {
|
||||
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,
|
||||
})),
|
||||
}),
|
||||
),
|
||||
);
|
||||
handles.push(compositions.last().unwrap().handle());
|
||||
handles.push(handle);
|
||||
}
|
||||
|
||||
let processor_composition = compositions.last_mut().unwrap();
|
||||
processor_composition.inject_container_name(handles.remove(0), "NETWORK_RPC_HOSTNAME");
|
||||
processor_composition.inject_container_name(handles.remove(0), "MESSAGE_QUEUE_RPC");
|
||||
processor_composition.inject_container_name(handles[0].clone(), "NETWORK_RPC_HOSTNAME");
|
||||
processor_composition.inject_container_name(handles[1].clone(), "MESSAGE_QUEUE_RPC");
|
||||
|
||||
(
|
||||
(compositions[0].handle(), compositions[1].handle(), compositions[2].handle()),
|
||||
coord_key,
|
||||
compositions,
|
||||
)
|
||||
((handles[0].clone(), handles[1].clone(), handles[2].clone()), coord_key, compositions)
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
|
||||
@@ -11,7 +11,7 @@ use serai_client::{
|
||||
in_instructions::primitives::{InInstruction, RefundableInInstruction, Shorthand},
|
||||
};
|
||||
|
||||
use dockertest::{PullPolicy, Image, StartPolicy, Composition, DockerOperations};
|
||||
use dockertest::{PullPolicy, Image, StartPolicy, TestBodySpecification, DockerOperations};
|
||||
|
||||
use crate::*;
|
||||
|
||||
@@ -21,13 +21,13 @@ pub const RPC_PASS: &str = "seraidex";
|
||||
pub const BTC_PORT: u32 = 8332;
|
||||
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());
|
||||
|
||||
let mut composition = Composition::with_image(
|
||||
let composition = TestBodySpecification::with_image(
|
||||
Image::with_repository("serai-dev-bitcoin").pull_policy(PullPolicy::Never),
|
||||
)
|
||||
.with_cmd(vec![
|
||||
.replace_cmd(vec![
|
||||
"bitcoind".to_string(),
|
||||
"-txindex".to_string(),
|
||||
"-regtest".to_string(),
|
||||
@@ -36,18 +36,18 @@ pub fn bitcoin_instance() -> (Composition, u32) {
|
||||
"-rpcbind=0.0.0.0".to_string(),
|
||||
"-rpcallowip=0.0.0.0/0".to_string(),
|
||||
"-rpcport=8332".to_string(),
|
||||
]);
|
||||
composition.publish_all_ports();
|
||||
])
|
||||
.set_publish_all_ports(true);
|
||||
(composition, BTC_PORT)
|
||||
}
|
||||
|
||||
pub fn monero_instance() -> (Composition, u32) {
|
||||
pub fn monero_instance() -> (TestBodySpecification, u32) {
|
||||
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),
|
||||
)
|
||||
.with_cmd(vec![
|
||||
.replace_cmd(vec![
|
||||
"monerod".to_string(),
|
||||
"--regtest".to_string(),
|
||||
"--offline".to_string(),
|
||||
@@ -58,12 +58,12 @@ pub fn monero_instance() -> (Composition, u32) {
|
||||
"--confirm-external-bind".to_string(),
|
||||
"--non-interactive".to_string(),
|
||||
])
|
||||
.with_start_policy(StartPolicy::Strict);
|
||||
composition.publish_all_ports();
|
||||
.set_start_policy(StartPolicy::Strict)
|
||||
.set_publish_all_ports(true);
|
||||
(composition, XMR_PORT)
|
||||
}
|
||||
|
||||
pub fn network_instance(network: NetworkId) -> (Composition, u32) {
|
||||
pub fn network_instance(network: NetworkId) -> (TestBodySpecification, u32) {
|
||||
match network {
|
||||
NetworkId::Bitcoin => bitcoin_instance(),
|
||||
NetworkId::Ethereum => todo!(),
|
||||
|
||||
@@ -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) {
|
||||
let mut coordinators = vec![];
|
||||
let mut test = DockerTest::new();
|
||||
let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
|
||||
for _ in 0 .. COORDINATORS {
|
||||
let (handles, coord_key, compositions) = processor_stack(network);
|
||||
coordinators.push((handles, coord_key));
|
||||
for composition in compositions {
|
||||
test.add_composition(composition);
|
||||
test.provide_container(composition);
|
||||
}
|
||||
}
|
||||
(coordinators, test)
|
||||
|
||||
Reference in New Issue
Block a user