From 9e39cf663e040a91ab4ac285e29b249d96d1da4d Mon Sep 17 00:00:00 2001 From: Razvan Barbascu Date: Tue, 4 Apr 2023 12:30:19 +0100 Subject: [PATCH] Adding tests --- chain/network/src/config.rs | 87 +++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/chain/network/src/config.rs b/chain/network/src/config.rs index 1e06fead6c6..86f6229db74 100644 --- a/chain/network/src/config.rs +++ b/chain/network/src/config.rs @@ -480,6 +480,7 @@ impl std::ops::Deref for VerifiedConfig { mod test { use super::UPDATE_INTERVAL_LAST_TIME_RECEIVED_MESSAGE; use crate::config; + use crate::config_json::NetworkConfigOverrides; use crate::network_protocol; use crate::network_protocol::testonly as data; use crate::network_protocol::{AccountData, VersionedAccountData}; @@ -509,6 +510,92 @@ mod test { assert!(nc.verify().is_err()); } + #[test] + fn test_network_config_override() { + fn check_override_field( + before: &T, + after: &T, + override_val: &Option, + ) -> bool { + if let Some(val) = override_val { + return after == val; + } else { + return after == before; + } + } + let check_fields = |before: &config::NetworkConfig, + after: &config::NetworkConfig, + overrides: &NetworkConfigOverrides| { + assert!(check_override_field( + &before.connect_to_reliable_peers_on_startup, + &after.connect_to_reliable_peers_on_startup, + &overrides.connect_to_reliable_peers_on_startup + )); + assert!(check_override_field( + &before.max_send_peers, + &after.max_send_peers, + &overrides.max_send_peers + )); + assert!(check_override_field( + &before.routed_message_ttl, + &after.routed_message_ttl, + &overrides.routed_message_ttl + )); + assert!(check_override_field( + &before.max_routes_to_store, + &after.max_routes_to_store, + &overrides.max_routes_to_store + )); + assert!(check_override_field( + &before.highest_peer_horizon, + &after.highest_peer_horizon, + &overrides.highest_peer_horizon + )); + assert!(check_override_field( + &before.push_info_period, + &after.push_info_period, + &overrides + .push_info_period_millis + .map(|millis| time::Duration::milliseconds(millis)) + )); + assert!(check_override_field( + &before.outbound_disabled, + &after.outbound_disabled, + &overrides.outbound_disabled + )); + assert!(check_override_field( + &before.accounts_data_broadcast_rate_limit.burst, + &after.accounts_data_broadcast_rate_limit.burst, + &overrides.accounts_data_broadcast_rate_limit_burst + )); + assert!(check_override_field( + &before.accounts_data_broadcast_rate_limit.qps, + &after.accounts_data_broadcast_rate_limit.qps, + &overrides.accounts_data_broadcast_rate_limit_qps + )); + }; + let no_overrides = NetworkConfigOverrides::default(); + let mut overrides = NetworkConfigOverrides::default(); + overrides.connect_to_reliable_peers_on_startup = Some(false); + overrides.max_send_peers = Some(42); + overrides.routed_message_ttl = Some(43); + overrides.accounts_data_broadcast_rate_limit_burst = Some(44); + overrides.accounts_data_broadcast_rate_limit_qps = Some(45.0); + + let nc_before = + config::NetworkConfig::from_seed("123", tcp::ListenerAddr::reserve_for_test()); + + let mut nc_after = nc_before.clone(); + nc_after.override_config(no_overrides.clone()); + check_fields(&nc_before, &nc_after, &no_overrides); + assert!(nc_after.verify().is_ok()); + + nc_after = nc_before.clone(); + nc_after.override_config(overrides.clone()); + check_fields(&nc_before, &nc_after, &overrides); + assert!(nc_after.verify().is_ok()); + } + // Check that MAX_PEER_ADDRS limit is consistent with the // network_protocol::MAX_ACCOUNT_DATA_SIZE_BYTES limit #[test]