Skip to content

Commit

Permalink
feat(jstzd,jstz_node): serialize jstz node config
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Dec 6, 2024
1 parent 2086049 commit 8330a51
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
23 changes: 22 additions & 1 deletion crates/jstz_node/src/config.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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");
}
}
2 changes: 1 addition & 1 deletion crates/jstzd/src/task/jstzd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions crates/jstzd/tests/jstzd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 8330a51

Please sign in to comment.