Skip to content

Commit

Permalink
feat(jstzd): serialize rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Dec 6, 2024
1 parent 4fed084 commit 909db37
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/jstzd/src/task/jstzd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 @@ -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))
Expand Down
39 changes: 37 additions & 2 deletions crates/octez/src/async/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
})
);
}
}

0 comments on commit 909db37

Please sign in to comment.