mirror of
https://github.com/logos-co/nomos-node.git
synced 2026-08-31 11:31:09 +00:00
145 lines
4.9 KiB
Rust
145 lines
4.9 KiB
Rust
use std::{fs, time::Duration};
|
|
|
|
use lb_node::{
|
|
UserConfig,
|
|
config::{RunConfig, deployment::DeploymentSettings},
|
|
};
|
|
use lb_tests::nodes::validator::Validator;
|
|
use lb_utils::net::{get_available_tcp_port, get_available_udp_port};
|
|
use tokio::{process::Command, task::JoinSet, time::sleep};
|
|
|
|
const SERVER_BIN: &str = "../../target/debug/logos-blockchain-cfgsync-server";
|
|
const CLIENT_BIN: &str = "../../target/debug/logos-blockchain-cfgsync-client";
|
|
const SERVER_CFG: &str = "./tests/cfgsync.yaml";
|
|
|
|
#[ignore = "For local debugging"]
|
|
#[tokio::test]
|
|
async fn test_deploy_setup_stage() {
|
|
// Start the configuration server
|
|
let mut server = std::process::Command::new(SERVER_BIN)
|
|
.arg("--mode")
|
|
.arg("setup")
|
|
.arg("--entropy-file")
|
|
.arg("tests/test_entropy")
|
|
.arg(SERVER_CFG)
|
|
.spawn()
|
|
.expect("server failed");
|
|
|
|
sleep(Duration::from_secs(1)).await;
|
|
|
|
// Collect all UserConfigs by running clients.
|
|
// Genesis is only generated after all init nodes registers.
|
|
let mut client_tasks = JoinSet::new();
|
|
for i in 0..4 {
|
|
let net_port = get_available_udp_port().expect("no free port for network");
|
|
let blend_port = get_available_udp_port().expect("no free port for blend");
|
|
let api_port = get_available_tcp_port().expect("no free port for api");
|
|
let out = format!(".tmp_node_{i}.yaml");
|
|
|
|
client_tasks.spawn(async move {
|
|
let status = Command::new(CLIENT_BIN)
|
|
.env("CFG_FILE_PATH", &out)
|
|
.env("CFG_SERVER_ADDR", "http://127.0.0.1:4400")
|
|
.env("CFG_HOST_IP", format!("127.0.0.{i}"))
|
|
.env("CFG_HOST_IDENTIFIER", format!("node-{i}"))
|
|
.env("CFG_NETWORK_PORT", net_port.to_string())
|
|
.env("CFG_BLEND_PORT", blend_port.to_string())
|
|
.env("CFG_API_PORT", api_port.to_string())
|
|
.status()
|
|
.await
|
|
.expect("client failed");
|
|
|
|
assert!(status.success(), "Client for node {i} failed");
|
|
|
|
let yaml = fs::read_to_string(&out).expect("read failed");
|
|
let user_config: UserConfig =
|
|
serde_yaml::from_str(&yaml).expect("UserConfig parse failed");
|
|
|
|
(i, user_config, api_port)
|
|
});
|
|
}
|
|
|
|
let mut user_configs = Vec::new();
|
|
while let Some(res) = client_tasks.join_next().await {
|
|
user_configs.push(res.unwrap());
|
|
}
|
|
|
|
// Download the shared deployment config with new genesis.
|
|
let response = reqwest::get("http://127.0.0.1:4400/deployment-settings")
|
|
.await
|
|
.unwrap();
|
|
let response = response.error_for_status().unwrap();
|
|
let yaml_bytes = response.bytes().await.unwrap();
|
|
let deployment: DeploymentSettings = serde_yaml::from_slice(&yaml_bytes).unwrap();
|
|
|
|
// Spawn the nodes.
|
|
let mut nodes = Vec::new();
|
|
for (i, user_config, api) in user_configs {
|
|
let run_config = RunConfig {
|
|
user: user_config,
|
|
deployment: deployment.clone(),
|
|
};
|
|
|
|
println!(">>>> Spawning Node {i} http://localhost:{api}/cryptarchia/info");
|
|
let node = Validator::spawn(run_config).await.expect("spawn failed");
|
|
nodes.push(node);
|
|
}
|
|
|
|
println!("\nAll nodes spawned. Use Ctrl+C to shutdown.\n");
|
|
tokio::signal::ctrl_c().await.unwrap();
|
|
|
|
drop(nodes);
|
|
server.kill().unwrap();
|
|
server.wait().unwrap();
|
|
}
|
|
|
|
#[ignore = "For local debugging"]
|
|
#[tokio::test]
|
|
async fn test_deploy_run_stage() {
|
|
let server = std::process::Command::new(SERVER_BIN)
|
|
.arg("--mode")
|
|
.arg("run")
|
|
.arg("--entropy-file")
|
|
.arg("tests/test_entropy")
|
|
.arg("--storage-path")
|
|
.arg("cfgsync-deployment-settings.yaml")
|
|
.arg(SERVER_CFG)
|
|
.spawn()
|
|
.expect("server failed to start in run mode");
|
|
|
|
sleep(Duration::from_secs(15)).await;
|
|
|
|
let response = reqwest::get("http://127.0.0.1:4400/deployment-settings")
|
|
.await
|
|
.expect("Failed to hit deployment-settings endpoint");
|
|
let yaml_bytes = response.bytes().await.unwrap();
|
|
let deployment: DeploymentSettings = serde_yaml::from_slice(&yaml_bytes).unwrap();
|
|
|
|
let mut nodes = Vec::new();
|
|
|
|
for i in 0..4 {
|
|
let node_cfg_path = format!(".tmp_node_{i}.yaml");
|
|
|
|
let user_yaml = fs::read_to_string(&node_cfg_path).expect("Node config file missing.");
|
|
let user_config: UserConfig =
|
|
serde_yaml::from_str(&user_yaml).expect("Failed to parse user config");
|
|
|
|
let run_config = RunConfig {
|
|
user: user_config,
|
|
deployment: deployment.clone(),
|
|
};
|
|
|
|
println!(">>>> Spawning Node {i} from disk (.tmp_node_{i}.yaml)");
|
|
let node = Validator::spawn(run_config)
|
|
.await
|
|
.expect("Node spawn failed");
|
|
nodes.push(node);
|
|
}
|
|
|
|
println!("\nIndependent network spawned from disk. Press Ctrl+C to terminate.\n");
|
|
|
|
tokio::signal::ctrl_c().await.unwrap();
|
|
drop(nodes);
|
|
drop(server);
|
|
}
|