diff --git a/crates/mempool_node/src/config/config_test.rs b/crates/mempool_node/src/config/config_test.rs index f4089e9e6c..93a467a3b8 100644 --- a/crates/mempool_node/src/config/config_test.rs +++ b/crates/mempool_node/src/config/config_test.rs @@ -94,7 +94,8 @@ fn test_default_config_file_is_up_to_date() { /// Tests parsing a node config without additional args. #[test] fn test_config_parsing() { - let args = create_test_config_load_args(&REQUIRED_PARAM_CONFIG_POINTERS); + let required_params = RequiredParams::create_for_testing(); + let args = create_test_config_load_args(required_params); let config = SequencerNodeConfig::load_and_process(args); let config = config.expect("Parsing function failed."); diff --git a/crates/mempool_node/src/config/test_utils.rs b/crates/mempool_node/src/config/test_utils.rs index aa96bfffab..b6ecd7d697 100644 --- a/crates/mempool_node/src/config/test_utils.rs +++ b/crates/mempool_node/src/config/test_utils.rs @@ -1,9 +1,10 @@ use std::vec::Vec; // Used by #[gen_field_names_fn]. -use papyrus_config::{ParamPath, SerializationType, SerializedContent, SerializedParam}; use papyrus_proc_macros::gen_field_names_fn; use starknet_api::core::ChainId; +use crate::config::node_command; + /// Required parameters utility struct. #[gen_field_names_fn] pub struct RequiredParams { @@ -14,42 +15,19 @@ impl RequiredParams { pub fn create_for_testing() -> Self { Self { chain_id: ChainId::create_for_testing() } } + + pub fn cli_args(&self) -> Vec { + let args = vec!["--chain_id".to_string(), self.chain_id.to_string()]; + // Verify all arguments and their values are present. + assert!(args.len() == Self::field_names().len() * 2, "Missing required parameters."); + args + } } -// TODO(Tsabary): Bundle required config values in a struct, detailing whether they are pointer -// targets or not. Then, derive their values in the config (struct and pointers). -// Also, add functionality to derive them for testing. // Creates a vector of strings with the command name and required parameters that can be used as // arguments to load a config. -#[cfg(any(feature = "testing", test))] -pub fn create_test_config_load_args(pointers: &Vec<(ParamPath, SerializedParam)>) -> Vec { - use crate::config::node_command; - - let mut dummy_values = Vec::new(); - - // Command name. - dummy_values.push(node_command().to_string()); - - // Iterate over required config parameters and add them as args with suitable arbitrary values. - for (target_param, serialized_pointer) in pointers { - // Param name. - let required_param_name_as_arg = format!("--{}", target_param); - dummy_values.push(required_param_name_as_arg); - - // Param value. - let serialization_type = match &serialized_pointer.content { - SerializedContent::ParamType(serialization_type) => serialization_type, - _ => panic!("Required parameters have to be of type ParamType."), - }; - let arbitrary_value = match serialization_type { - SerializationType::Boolean => "false", - SerializationType::Float => "15.2", - SerializationType::NegativeInteger => "-30", - SerializationType::PositiveInteger => "17", - SerializationType::String => "ArbitraryString", - } - .to_string(); - dummy_values.push(arbitrary_value); - } - dummy_values +pub fn create_test_config_load_args(required_params: RequiredParams) -> Vec { + let mut cli_args = vec![node_command().to_string()]; + cli_args.extend(required_params.cli_args()); + cli_args }