mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
test: Modify can_serde_config_test (#1048)
Co-authored-by: lambdaclass-user <github@lambdaclass.com> Co-authored-by: xqft <estefano.bargas@fing.edu.uy>
This commit is contained in:
committed by
GitHub
parent
55fc6924b9
commit
be70f810e9
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4576,6 +4576,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shellexpand",
|
||||
"tempfile",
|
||||
"tracing",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
@ -4,7 +4,7 @@ use std::{collections::HashMap, net::IpAddr, time::Instant};
|
||||
|
||||
/// Stores peers that should be taken out of circulation either indefinitely or until a certain
|
||||
/// timestamp
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct BanList {
|
||||
/// A set of IPs whose packets get dropped instantly.
|
||||
banned_ips: HashMap<IpAddr, Option<Instant>>,
|
||||
|
||||
@ -658,7 +658,7 @@ impl Default for PeersManager {
|
||||
}
|
||||
|
||||
/// Tracks stats about connected nodes
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct ConnectionInfo {
|
||||
/// Counter for currently occupied slots for active outbound connections.
|
||||
@ -917,7 +917,7 @@ pub enum PeerAction {
|
||||
}
|
||||
|
||||
/// Config type for initiating a [`PeersManager`] instance
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct PeersConfig {
|
||||
/// How often to recheck free slots for outbound connections.
|
||||
@ -1003,7 +1003,7 @@ impl PeersConfig {
|
||||
/// The durations to use when a backoff should be applied to a peer.
|
||||
///
|
||||
/// See also [`BackoffKind`](BackoffKind).
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct PeerBackoffDurations {
|
||||
/// Applies to connection problems where there is a chance that they will be resolved after the
|
||||
|
||||
@ -37,7 +37,7 @@ pub(crate) fn is_banned_reputation(reputation: i32) -> bool {
|
||||
}
|
||||
|
||||
/// How the [`ReputationChangeKind`] are weighted.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct ReputationChangeWeights {
|
||||
/// Weight for [`ReputationChangeKind::BadMessage`]
|
||||
|
||||
@ -32,3 +32,4 @@ walkdir = "2.3.2"
|
||||
eyre = "0.6.8"
|
||||
shellexpand = "3.0.0"
|
||||
tracing = "0.1.37"
|
||||
tempfile = "3.3.0"
|
||||
|
||||
@ -12,7 +12,7 @@ use reth_provider::ShareableDatabase;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Configuration for the reth node.
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Default, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
/// Configuration for each stage in the pipeline.
|
||||
@ -48,7 +48,7 @@ impl Config {
|
||||
}
|
||||
|
||||
/// Configuration for each stage in the pipeline.
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Default, Deserialize, PartialEq, Serialize)]
|
||||
pub struct StageConfig {
|
||||
/// Header stage configuration.
|
||||
pub headers: HeadersConfig,
|
||||
@ -63,7 +63,7 @@ pub struct StageConfig {
|
||||
}
|
||||
|
||||
/// Header stage configuration.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub struct HeadersConfig {
|
||||
/// The maximum number of headers to download before committing progress to the database.
|
||||
pub commit_threshold: u64,
|
||||
@ -80,7 +80,7 @@ impl Default for HeadersConfig {
|
||||
}
|
||||
|
||||
/// Total difficulty stage configuration
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub struct TotalDifficultyConfig {
|
||||
/// The maximum number of total difficulty entries to sum up before committing progress to the
|
||||
/// database.
|
||||
@ -94,7 +94,7 @@ impl Default for TotalDifficultyConfig {
|
||||
}
|
||||
|
||||
/// Body stage configuration.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub struct BodiesConfig {
|
||||
/// The batch size of non-empty blocks per one request
|
||||
pub downloader_request_limit: u64,
|
||||
@ -121,7 +121,7 @@ impl Default for BodiesConfig {
|
||||
}
|
||||
|
||||
/// Sender recovery stage configuration.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
|
||||
pub struct SenderRecoveryConfig {
|
||||
/// The maximum number of blocks to process before committing progress to the database.
|
||||
pub commit_threshold: u64,
|
||||
@ -136,7 +136,7 @@ impl Default for SenderRecoveryConfig {
|
||||
}
|
||||
|
||||
/// Execution stage configuration.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub struct ExecutionConfig {
|
||||
/// The maximum number of blocks to execution before committing progress to the database.
|
||||
pub commit_threshold: u64,
|
||||
@ -151,8 +151,34 @@ impl Default for ExecutionConfig {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Config;
|
||||
|
||||
const EXTENSION: &str = "toml";
|
||||
|
||||
fn with_tempdir(filename: &str, proc: fn(&std::path::Path)) {
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let config_path = temp_dir.path().join(filename).with_extension(EXTENSION);
|
||||
|
||||
proc(&config_path);
|
||||
|
||||
temp_dir.close().unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_serde_config() {
|
||||
let _: Config = confy::load("test", None).unwrap();
|
||||
fn test_store_config() {
|
||||
with_tempdir("config-store-test", |config_path| {
|
||||
let config = Config::default();
|
||||
confy::store_path(config_path, config).unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_load_config() {
|
||||
with_tempdir("config-load-test", |config_path| {
|
||||
let config = Config::default();
|
||||
confy::store_path(config_path, &config).unwrap();
|
||||
|
||||
let loaded_config: Config = confy::load_path(config_path).unwrap();
|
||||
assert_eq!(config, loaded_config);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user