Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove redundent mempool node config tests #165

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 32 additions & 66 deletions crates/mempool_node/src/config/config_test.rs
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 crates/mempool_node/src/test_files/mempool_node_config.json

This file was deleted.

Loading