From 8330a51e42189baea20e0835f03b5384b1db6c01 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 6 Dec 2024 12:07:18 +0000 Subject: [PATCH] feat(jstzd,jstz_node): serialize jstz node config --- crates/jstz_node/src/config.rs | 23 ++++++++++++++++++++++- crates/jstzd/src/task/jstzd.rs | 2 +- crates/jstzd/tests/jstzd_test.rs | 4 ++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/crates/jstz_node/src/config.rs b/crates/jstz_node/src/config.rs index b16f3f789..e65f76ad7 100644 --- a/crates/jstz_node/src/config.rs +++ b/crates/jstz_node/src/config.rs @@ -1,8 +1,9 @@ use std::path::{Path, PathBuf}; use octez::r#async::endpoint::Endpoint; +use serde::Serialize; -#[derive(Clone)] +#[derive(Clone, Serialize)] pub struct JstzNodeConfig { /// The endpoint of the jstz node. pub endpoint: Endpoint, @@ -25,3 +26,23 @@ impl JstzNodeConfig { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_serialize_config() { + let config = JstzNodeConfig::new( + &Endpoint::localhost(8932), + &Endpoint::localhost(8933), + Path::new("/tmp/kernel.log"), + ); + + let json = serde_json::to_value(&config).unwrap(); + + assert_eq!(json["endpoint"], "http://localhost:8932"); + assert_eq!(json["rollup_endpoint"], "http://localhost:8933"); + assert_eq!(json["kernel_log_file"], "/tmp/kernel.log"); + } +} diff --git a/crates/jstzd/src/task/jstzd.rs b/crates/jstzd/src/task/jstzd.rs index a59b03ade..1179ed457 100644 --- a/crates/jstzd/src/task/jstzd.rs +++ b/crates/jstzd/src/task/jstzd.rs @@ -65,7 +65,7 @@ pub struct JstzdConfig { octez_client_config: OctezClientConfig, #[serde(rename(serialize = "octez-rollup"))] octez_rollup_config: OctezRollupConfig, - #[serde(skip_serializing)] + #[serde(rename(serialize = "jstz-node"))] jstz_node_config: JstzNodeConfig, #[serde(skip_serializing)] protocol_params: ProtocolParameter, diff --git a/crates/jstzd/tests/jstzd_test.rs b/crates/jstzd/tests/jstzd_test.rs index 0f9cd46ed..b7937397a 100644 --- a/crates/jstzd/tests/jstzd_test.rs +++ b/crates/jstzd/tests/jstzd_test.rs @@ -259,6 +259,10 @@ async fn fetch_config_test(jstzd_config: JstzdConfig, jstzd_port: u16) { "octez-rollup", serde_json::to_value(jstzd_config.octez_rollup_config()).unwrap(), ), + ( + "jstz-node", + serde_json::to_value(jstzd_config.jstz_node_config()).unwrap(), + ), ] { let res = reqwest::get(&format!("http://localhost:{}/config/{}", jstzd_port, key))