diff --git a/crates/starknet_integration_tests/src/config_utils.rs b/crates/starknet_integration_tests/src/config_utils.rs index 9ce1ccb13f..e567613f2a 100644 --- a/crates/starknet_integration_tests/src/config_utils.rs +++ b/crates/starknet_integration_tests/src/config_utils.rs @@ -3,13 +3,13 @@ use std::io::Write; use std::path::PathBuf; use papyrus_config::dumping::{combine_config_map_and_pointers, SerializeConfig}; -use serde_json::{Map, Value}; +use serde_json::Value; use starknet_sequencer_node::config::node_config::{ SequencerNodeConfig, CONFIG_NON_POINTERS_WHITELIST, CONFIG_POINTERS, }; -use starknet_sequencer_node::config::test_utils::RequiredParams; +use starknet_sequencer_node::config::test_utils::{config_to_preset, RequiredParams}; use tracing::info; // TODO(Tsabary): Move here all config-related functions from "integration_test_utils.rs". @@ -56,43 +56,6 @@ fn dump_json_data(json_data: Value, path: &str, dir: PathBuf) -> PathBuf { temp_dir_path } -/// Transforms a nested JSON dictionary object into a simplified JSON dictionary object by -/// extracting specific values from the inner dictionaries. -/// -/// # Parameters -/// - `config_map`: A reference to a `serde_json::Value` that must be a JSON dictionary object. Each -/// key in the object maps to another JSON dictionary object. -/// -/// # Returns -/// - A `serde_json::Value` dictionary object where: -/// - Each key is preserved from the top-level dictionary. -/// - Each value corresponds to the `"value"` field of the nested JSON dictionary under the -/// original key. -/// -/// # Panics -/// This function panics if the provided `config_map` is not a JSON dictionary object. -fn config_to_preset(config_map: &Value) -> Value { - // Ensure the config_map is a JSON object. - if let Value::Object(map) = config_map { - let mut result = Map::new(); - - for (key, value) in map { - if let Value::Object(inner_map) = value { - // Extract the value. - if let Some(inner_value) = inner_map.get("value") { - // Add it to the result map - result.insert(key.clone(), inner_value.clone()); - } - } - } - - // Return the transformed result as a JSON object. - Value::Object(result) - } else { - panic!("Config map is not a JSON object: {:?}", config_map); - } -} - /// Merges required parameters into an existing preset JSON object. /// /// # Parameters diff --git a/crates/starknet_sequencer_node/src/config/test_utils.rs b/crates/starknet_sequencer_node/src/config/test_utils.rs index c28a9759e5..4c6a53e1c4 100644 --- a/crates/starknet_sequencer_node/src/config/test_utils.rs +++ b/crates/starknet_sequencer_node/src/config/test_utils.rs @@ -1,9 +1,8 @@ use std::collections::HashSet; -use std::vec::Vec; // Used by #[gen_field_names_fn]. use papyrus_protobuf::consensus::DEFAULT_VALIDATOR_ID; use serde::Serialize; -use serde_json::{to_value, Value}; +use serde_json::{to_value, Map, Value}; use starknet_api::core::{ChainId, ContractAddress}; use url::Url; @@ -64,3 +63,40 @@ pub fn create_test_config_load_args(required_params: RequiredParams) -> Vec Value { + // Ensure the config_map is a JSON object. + if let Value::Object(map) = config_map { + let mut result = Map::new(); + + for (key, value) in map { + if let Value::Object(inner_map) = value { + // Extract the value. + if let Some(inner_value) = inner_map.get("value") { + // Add it to the result map + result.insert(key.clone(), inner_value.clone()); + } + } + } + + // Return the transformed result as a JSON object. + Value::Object(result) + } else { + panic!("Config map is not a JSON object: {:?}", config_map); + } +}