From 909db3755d480068106a04a1ecbdb3a292dcdacf Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 6 Dec 2024 10:32:00 +0000 Subject: [PATCH] feat(jstzd): serialize rollup config --- crates/jstzd/src/task/jstzd.rs | 2 +- crates/jstzd/tests/jstzd_test.rs | 4 ++++ crates/octez/src/async/rollup.rs | 39 ++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/crates/jstzd/src/task/jstzd.rs b/crates/jstzd/src/task/jstzd.rs index 71e2423d5..a59b03ade 100644 --- a/crates/jstzd/src/task/jstzd.rs +++ b/crates/jstzd/src/task/jstzd.rs @@ -63,7 +63,7 @@ pub struct JstzdConfig { baker_config: OctezBakerConfig, #[serde(rename(serialize = "octez-client"))] octez_client_config: OctezClientConfig, - #[serde(skip_serializing)] + #[serde(rename(serialize = "octez-rollup"))] octez_rollup_config: OctezRollupConfig, #[serde(skip_serializing)] jstz_node_config: JstzNodeConfig, diff --git a/crates/jstzd/tests/jstzd_test.rs b/crates/jstzd/tests/jstzd_test.rs index a87a5251e..0f9cd46ed 100644 --- a/crates/jstzd/tests/jstzd_test.rs +++ b/crates/jstzd/tests/jstzd_test.rs @@ -255,6 +255,10 @@ async fn fetch_config_test(jstzd_config: JstzdConfig, jstzd_port: u16) { "octez-baker", serde_json::to_value(jstzd_config.baker_config()).unwrap(), ), + ( + "octez-rollup", + serde_json::to_value(jstzd_config.octez_rollup_config()).unwrap(), + ), ] { let res = reqwest::get(&format!("http://localhost:{}/config/{}", jstzd_port, key)) diff --git a/crates/octez/src/async/rollup.rs b/crates/octez/src/async/rollup.rs index 9c18cc356..af551f80d 100644 --- a/crates/octez/src/async/rollup.rs +++ b/crates/octez/src/async/rollup.rs @@ -3,7 +3,7 @@ use crate::unused_port; use super::{bootstrap::SmartRollupPvmKind, endpoint::Endpoint}; use anyhow::Result; use http::Uri; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::{ path::{Path, PathBuf}, str::FromStr, @@ -119,11 +119,13 @@ impl OctezRollupConfigBuilder { } } -#[derive(Clone)] +#[derive(Clone, Serialize)] pub struct OctezRollupConfig { pub binary_path: PathBuf, pub octez_client_base_dir: PathBuf, pub octez_node_endpoint: Endpoint, + // TODO: https://linear.app/tezos/issue/JSTZ-243/include-rollup-data-dir-in-config + #[serde(skip_serializing)] pub data_dir: RollupDataDir, pub address: SmartRollupHash, pub operator: String, @@ -257,4 +259,37 @@ mod test { Some(PathBuf::from("/tmp/kernel_debug.log")) ); } + + #[test] + fn serialize_config() { + let config = OctezRollupConfigBuilder::new( + Endpoint::localhost(1234), + PathBuf::from("/base_dir"), + SmartRollupHash::from_str("sr1PuFMgaRUN12rKQ3J2ae5psNtwCxPNmGNK").unwrap(), + "operator".to_owned(), + PathBuf::from("/tmp/boot_sector.hex"), + ) + .set_kernel_debug_file(Path::new("/tmp/kernel_debug.log")) + .set_data_dir(RollupDataDir::TempWithPreImages { + preimages_dir: PathBuf::from("/tmp/pre_images"), + }) + .build() + .unwrap(); + + let json = serde_json::to_value(config.clone()).unwrap(); + assert_eq!( + json, + serde_json::json!({ + "binary_path": "octez-smart-rollup-node", + "octez_client_base_dir": "/base_dir", + "octez_node_endpoint": "http://localhost:1234", + "pvm_kind": "wasm_2_0_0", + "address": "sr1PuFMgaRUN12rKQ3J2ae5psNtwCxPNmGNK", + "operator": "operator", + "boot_sector_file": "/tmp/boot_sector.hex", + "rpc_endpoint": format!("http://127.0.0.1:{}", config.rpc_endpoint.port()), + "kernel_debug_file": "/tmp/kernel_debug.log" + }) + ); + } }