Skip to content

Commit

Permalink
chore(tests-integration): dump additional data + use temp dirs
Browse files Browse the repository at this point in the history
commit-id:5307e63d
  • Loading branch information
Itay-Tsabary-Starkware committed Nov 5, 2024
1 parent 2315831 commit 10beddd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 10 additions & 11 deletions crates/tests-integration/src/integration_test_config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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,
Expand All @@ -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(())
}

Expand Down

0 comments on commit 10beddd

Please sign in to comment.