Skip to content

Commit

Permalink
Update serai-client, remove reliance on the existence of a handle fn
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Oct 23, 2023
1 parent 20bb961 commit 25b4228
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 139 deletions.
109 changes: 38 additions & 71 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substrate/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ schnorrkel = { path = "../../crypto/schnorrkel", package = "frost-schnorrkel" }

tokio = "1"

dockertest = "0.3"
dockertest = "0.4"
serai-docker-tests = { path = "../../tests/docker" }

[features]
Expand Down
23 changes: 12 additions & 11 deletions substrate/client/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,38 @@ macro_rules! serai_test {
#[tokio::test]
async fn $name() {
use dockertest::{
PullPolicy, StartPolicy, LogOptions, LogAction, LogPolicy, LogSource, Image, Composition,
DockerTest,
PullPolicy, StartPolicy, LogOptions, LogAction, LogPolicy, LogSource, Image,
TestBodySpecification, DockerTest,
};

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),
)
.with_cmd(vec![
.replace_cmd(vec![
"serai-node".to_string(),
"--dev".to_string(),
"--unsafe-rpc-external".to_string(),
"--rpc-cors".to_string(),
"all".to_string(),
])
.with_start_policy(StartPolicy::Strict)
.with_log_options(Some(LogOptions {
.set_publish_all_ports(true)
.set_handle(handle)
.set_start_policy(StartPolicy::Strict)
.set_log_options(Some(LogOptions {
action: LogAction::Forward,
policy: LogPolicy::Always,
source: LogSource::Both,
}));
composition.publish_all_ports();

let handle = composition.handle();

let mut test = DockerTest::new();
test.add_composition(composition);
test.provide_container(composition);
test.run_async(|ops| async move {
// 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);
// Bound execution to 60 seconds
for _ in 0 .. 60 {
Expand Down
2 changes: 1 addition & 1 deletion tests/coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ serde_json = { version = "1", default-features = false }

tokio = { version = "1", features = ["time"] }

dockertest = "0.3"
dockertest = "0.4"
serai-docker-tests = { path = "../docker" }
serai-message-queue-tests = { path = "../message-queue" }
25 changes: 14 additions & 11 deletions tests/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,36 @@ pub fn coordinator_stack(

let mut compositions = vec![];
let mut handles = vec![];
for composition in [serai_composition, message_queue_composition, coordinator_composition] {
let name = format!("{}-{}", composition.handle(), &unique_id);
for (name, composition) in [
("serai_node", serai_composition),
("message_queue", message_queue_composition),
("coordinator", coordinator_composition),
] {
let handle = format!("coordinator-{name}-{}", &unique_id);

compositions.push(
composition
.set_start_policy(StartPolicy::Strict)
.set_handle(name.clone())
.set_log_options(Some(LogOptions {
composition.set_start_policy(StartPolicy::Strict).set_handle(handle.clone()).set_log_options(
Some(LogOptions {
action: if std::env::var("GITHUB_CI") == Ok("true".to_string()) {
LogAction::Forward
} else {
LogAction::ForwardToFile { path: logs_path.clone() }
},
policy: LogPolicy::Always,
source: LogSource::Both,
})),
}),
),
);

handles.push(compositions.last().unwrap().handle());
handles.push(handle);
}

let coordinator_composition = compositions.last_mut().unwrap();
coordinator_composition.inject_container_name(handles.remove(0), "SERAI_HOSTNAME");
coordinator_composition.inject_container_name(handles.remove(0), "MESSAGE_QUEUE_RPC");
coordinator_composition.inject_container_name(handles[0].clone(), "SERAI_HOSTNAME");
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],
compositions,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/full-stack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ serai-client = { path = "../../substrate/client", features = ["serai"] }

tokio = { version = "1", features = ["time"] }

dockertest = "0.3"
dockertest = "0.4"
serai-docker-tests = { path = "../docker" }
serai-message-queue-tests = { path = "../message-queue" }
serai-processor-tests = { path = "../processor" }
Expand Down
Loading

0 comments on commit 25b4228

Please sign in to comment.