From 10bedddcc4295a575f55660c7e7f5537030bff75 Mon Sep 17 00:00:00 2001 From: Itay Tsabary <itayt@starkware.co> Date: Mon, 4 Nov 2024 19:22:56 +0200 Subject: [PATCH] chore(tests-integration): dump additional data + use temp dirs commit-id:5307e63d --- .../src/bin/run_test_rpc_state_reader.rs | 2 +- .../src/integration_test_config_utils.rs | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/tests-integration/src/bin/run_test_rpc_state_reader.rs b/crates/tests-integration/src/bin/run_test_rpc_state_reader.rs index 9afbc08eff..2a78f4b51b 100644 --- a/crates/tests-integration/src/bin/run_test_rpc_state_reader.rs +++ b/crates/tests-integration/src/bin/run_test_rpc_state_reader.rs @@ -29,7 +29,7 @@ async fn main() -> anyhow::Result<()> { // Note: the batcher storage file handle is passed as a reference to maintain its ownership in // this scope, such that the handle is not dropped and the storage is maintained. - dump_config_file_changes(config, required_params)?; + dump_config_file_changes(config, required_params); // Keep the program running so the rpc state reader server, its storage, and the batcher // storage, are all maintained. diff --git a/crates/tests-integration/src/integration_test_config_utils.rs b/crates/tests-integration/src/integration_test_config_utils.rs index bef874bb5d..d59a48b2c0 100644 --- a/crates/tests-integration/src/integration_test_config_utils.rs +++ b/crates/tests-integration/src/integration_test_config_utils.rs @@ -4,9 +4,9 @@ use std::io::Write; use serde_json::{json, Value}; use starknet_sequencer_node::config::test_utils::RequiredParams; use starknet_sequencer_node::config::SequencerNodeConfig; +use tempfile::tempdir; use tokio::io::Result; use tracing::info; - // TODO(Tsabary): Move here all config-related functions from "integration_test_utils.rs". // TODO(Tsabary): Wrap dumped config files in a temp dir. @@ -43,10 +43,7 @@ macro_rules! config_fields_to_json { /// cargo run --bin starknet_sequencer_node -- --config_file NODE_CONFIG_CHANGES_FILE_PATH /// Transaction generator: /// cargo run --bin run_test_tx_generator -- --config_file TX_GEN_CONFIG_CHANGES_FILE_PATH -pub fn dump_config_file_changes( - config: SequencerNodeConfig, - required_params: RequiredParams, -) -> anyhow::Result<()> { +pub fn dump_config_file_changes(config: SequencerNodeConfig, required_params: RequiredParams) { // Dump config changes file for the sequencer node. let json_data = config_fields_to_json!( required_params.chain_id, @@ -59,29 +56,31 @@ pub fn dump_config_file_changes( config.http_server_config.port, config.consensus_manager_config.consensus_config.start_height, ); - dump_json_data(json_data, NODE_CONFIG_CHANGES_FILE_PATH)?; + dump_json_data(json_data, NODE_CONFIG_CHANGES_FILE_PATH).unwrap(); // Dump config changes file for the transaction generator. let json_data = config_fields_to_json!( required_params.chain_id, + required_params.eth_fee_token_address, + required_params.strk_fee_token_address, config.http_server_config.ip, config.http_server_config.port, ); - dump_json_data(json_data, TX_GEN_CONFIG_CHANGES_FILE_PATH)?; - - Ok(()) + dump_json_data(json_data, TX_GEN_CONFIG_CHANGES_FILE_PATH).unwrap(); } /// Dumps the input JSON data to a file at the specified path. fn dump_json_data(json_data: Value, path: &str) -> Result<()> { + let dir = tempdir()?; + let temp_dir_path = dir.path().join(path); // Serialize the JSON data to a pretty-printed string let json_string = serde_json::to_string_pretty(&json_data).unwrap(); // Write the JSON string to a file - let mut file = File::create(path)?; + let mut file = File::create(&temp_dir_path)?; file.write_all(json_string.as_bytes())?; - info!("Writing required config changes to: {:?}", path); + info!("Writing required config changes to: {:?}", temp_dir_path); Ok(()) }