-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: remove redundent mempool node config tests (#165)
- Loading branch information
1 parent
70cc2a9
commit fcdf7ae
Showing
2 changed files
with
32 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,43 @@ | ||
#[cfg(any(feature = "testing", test))] | ||
use std::fs::File; | ||
use std::path::Path; | ||
|
||
use assert_matches::assert_matches; | ||
use papyrus_config::loading::load_and_process_config; | ||
use papyrus_config::validators::ParsedValidationErrors; | ||
use starknet_gateway::config::{ | ||
GatewayNetworkConfig, RpcStateReaderConfig, StatefulTransactionValidatorConfig, | ||
StatelessTransactionValidatorConfig, | ||
}; | ||
use papyrus_config::validators::{ParsedValidationError, ParsedValidationErrors}; | ||
use validator::Validate; | ||
|
||
use crate::config::{ | ||
node_command, ComponentConfig, ComponentExecutionConfig, GatewayConfig, MempoolNodeConfig, | ||
}; | ||
|
||
const TEST_FILES_FOLDER: &str = "./src/test_files"; | ||
const CONFIG_FILE: &str = "mempool_node_config.json"; | ||
|
||
fn get_config_file(file_name: &str) -> Result<MempoolNodeConfig, papyrus_config::ConfigError> { | ||
let config_file = File::open(Path::new(TEST_FILES_FOLDER).join(file_name)).unwrap(); | ||
load_and_process_config::<MempoolNodeConfig>(config_file, node_command(), vec![]) | ||
} | ||
use crate::config::{ComponentConfig, ComponentExecutionConfig}; | ||
|
||
/// Test the validation of the struct ComponentConfig. | ||
/// The validation validates at least one of the components is set with execute: true. | ||
#[test] | ||
fn test_valid_config() { | ||
// Read the valid config file and validate its content. | ||
let expected_config = MempoolNodeConfig { | ||
components: ComponentConfig { | ||
gateway_component: ComponentExecutionConfig { execute: true }, | ||
mempool_component: ComponentExecutionConfig { execute: false }, | ||
}, | ||
gateway_config: GatewayConfig { | ||
network_config: GatewayNetworkConfig { ip: "0.0.0.0".parse().unwrap(), port: 8080 }, | ||
stateless_transaction_validator_config: StatelessTransactionValidatorConfig { | ||
validate_non_zero_l1_gas_fee: true, | ||
validate_non_zero_l2_gas_fee: false, | ||
max_calldata_length: 10, | ||
max_signature_length: 2, | ||
}, | ||
stateful_transaction_validator_config: | ||
StatefulTransactionValidatorConfig::create_for_testing(), | ||
}, | ||
rpc_state_reader_config: RpcStateReaderConfig::default(), | ||
fn test_components_config_validation() { | ||
// Initialize an invalid config and check that the validator finds an error. | ||
let mut component_config = ComponentConfig { | ||
gateway_component: ComponentExecutionConfig { execute: false }, | ||
mempool_component: ComponentExecutionConfig { execute: false }, | ||
}; | ||
let loaded_config = get_config_file(CONFIG_FILE).unwrap(); | ||
|
||
assert!(loaded_config.validate().is_ok()); | ||
assert_eq!(loaded_config, expected_config); | ||
} | ||
|
||
#[test] | ||
fn test_components_config() { | ||
// Read the valid config file and check that the validator finds no errors. | ||
let mut config = get_config_file(CONFIG_FILE).unwrap(); | ||
assert!(config.validate().is_ok()); | ||
|
||
// Invalidate the gateway component and check that the validator finds an error. | ||
config.components.gateway_component.execute = false; | ||
|
||
assert_matches!(config.validate(), Err(e) => { | ||
let parse_err = ParsedValidationErrors::from(e); | ||
let mut error_msg = String::new(); | ||
for error in parse_err.0 { | ||
if error.param_path == "components.__all__" { | ||
error_msg.push_str(&error.code); | ||
break; | ||
} | ||
} | ||
assert_eq!(error_msg, "Invalid components configuration."); | ||
assert_matches!(component_config.validate().unwrap_err(), validation_errors => { | ||
let parsed_errors = ParsedValidationErrors::from(validation_errors); | ||
assert_eq!(parsed_errors.0.len(), 1); | ||
let parsed_validation_error = &parsed_errors.0[0]; | ||
assert_matches!( | ||
parsed_validation_error, | ||
ParsedValidationError { param_path, code, message, params} | ||
if ( | ||
param_path == "__all__" && | ||
code == "Invalid components configuration." && | ||
params.is_empty() && | ||
*message == Some("At least one component should be allowed to execute.".to_string()) | ||
) | ||
) | ||
}); | ||
|
||
// Validate the mempool component and check that the validator finds no errors. | ||
config.components.mempool_component.execute = true; | ||
assert!(config.validate().is_ok()); | ||
// Update the config to be valid and check that the validator finds no errors. | ||
for (gateway_component_execute, mempool_component_execute) in | ||
[(true, false), (false, true), (true, true)] | ||
{ | ||
component_config.gateway_component.execute = gateway_component_execute; | ||
component_config.mempool_component.execute = mempool_component_execute; | ||
|
||
assert!(component_config.validate().is_ok()); | ||
} | ||
} |
82 changes: 0 additions & 82 deletions
82
crates/mempool_node/src/test_files/mempool_node_config.json
This file was deleted.
Oops, something went wrong.