Skip to content

Commit

Permalink
chore(tests-integration): clean config dump function
Browse files Browse the repository at this point in the history
commit-id:43c39252
  • Loading branch information
Itay-Tsabary-Starkware committed Nov 11, 2024
1 parent 93b97c7 commit 9e35673
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
34 changes: 7 additions & 27 deletions crates/tests-integration/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use std::path::PathBuf;
use serde_json::{json, Value};
use starknet_sequencer_node::config::test_utils::RequiredParams;
use starknet_sequencer_node::config::SequencerNodeConfig;
use tempfile::TempDir;
use tracing::info;
// TODO(Tsabary): Move here all config-related functions from "integration_test_utils.rs".

const NODE_CONFIG_CHANGES_FILE_PATH: &str = "node_integration_test_config_changes.json";
const TX_GEN_CONFIG_CHANGES_FILE_PATH: &str = "tx_gen_integration_test_config_changes.json";

/// A utility macro that takes a list of config fields and returns a json dictionary with "field
/// name : field value" entries, where prefixed "config." name is removed from the entry key.
Expand All @@ -36,18 +34,12 @@ macro_rules! config_fields_to_json {
};
}

// TODO(Tsabary): fix comment after removing run_test_tx_generator.
/// Returns config files to be supplied for the sequencer node and the transaction generator. Then
///
/// Sequencer node:
/// 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(
/// Creates a config file for the sequencer node for the end to end integration test.
pub(crate) fn dump_config_file_changes(
config: &SequencerNodeConfig,
required_params: RequiredParams,
dir: &TempDir,
) -> (PathBuf, PathBuf) {
dir: PathBuf,
) -> PathBuf {
// Dump config changes file for the sequencer node.
let json_data = config_fields_to_json!(
required_params.chain_id,
Expand All @@ -63,24 +55,12 @@ pub fn dump_config_file_changes(
let node_config_path = dump_json_data(json_data, NODE_CONFIG_CHANGES_FILE_PATH, dir);
assert!(node_config_path.exists(), "File does not exist: {:?}", node_config_path);

// TODO(Tsabary): should be deprecated.
// 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,
);
let tx_gen_config_path = dump_json_data(json_data, TX_GEN_CONFIG_CHANGES_FILE_PATH, dir);
assert!(tx_gen_config_path.exists(), "File does not exist: {:?}", tx_gen_config_path);

(node_config_path, tx_gen_config_path)
node_config_path
}

/// Dumps the input JSON data to a file at the specified path.
fn dump_json_data(json_data: Value, path: &str, dir: &TempDir) -> PathBuf {
let temp_dir_path = dir.path().join(path);
fn dump_json_data(json_data: Value, path: &str, dir: PathBuf) -> PathBuf {
let temp_dir_path = dir.join(path);
// Serialize the JSON data to a pretty-printed string
let json_string = serde_json::to_string_pretty(&json_data).unwrap();

Expand Down
10 changes: 5 additions & 5 deletions crates/tests-integration/src/integration_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ impl IntegrationTestSetup {
let (config, required_params) =
create_config(rpc_server_addr, storage_for_test.batcher_storage_config).await;

// 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.
let node_config_dir_handle = tempdir().unwrap();
// TODO(Tsabary): pass path instead of temp dir.
let (node_config_path, _) =
dump_config_file_changes(&config, required_params, &node_config_dir_handle);
let node_config_path = dump_config_file_changes(
&config,
required_params,
node_config_dir_handle.path().to_path_buf(),
);

// Wait for the node to start.
let MonitoringEndpointConfig { ip, port } = config.monitoring_endpoint_config;
Expand Down

0 comments on commit 9e35673

Please sign in to comment.