mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add sanity tests for Args Default impls (#5660)
This commit is contained in:
@ -11,3 +11,23 @@ pub struct DatabaseArgs {
|
||||
#[arg(long = "db.log-level", value_enum)]
|
||||
pub log_level: Option<LogLevel>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::Parser;
|
||||
|
||||
/// A helper type to parse Args more easily
|
||||
#[derive(Parser)]
|
||||
struct CommandParser<T: Args> {
|
||||
#[clap(flatten)]
|
||||
args: T,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_database_args() {
|
||||
let default_args = DatabaseArgs::default();
|
||||
let args = CommandParser::<DatabaseArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,3 +58,23 @@ pub struct DebugArgs {
|
||||
)]
|
||||
pub hook_all: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::Parser;
|
||||
|
||||
/// A helper type to parse Args more easily
|
||||
#[derive(Parser)]
|
||||
struct CommandParser<T: Args> {
|
||||
#[clap(flatten)]
|
||||
args: T,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_database_args() {
|
||||
let default_args = DebugArgs::default();
|
||||
let args = CommandParser::<DebugArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,4 +96,11 @@ mod tests {
|
||||
]);
|
||||
assert!(args.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dev_args_default_sanity_check() {
|
||||
let default_args = DevArgs::default();
|
||||
let args = CommandParser::<DevArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use clap::Args;
|
||||
|
||||
/// Parameters to configure Gas Price Oracle
|
||||
#[derive(Debug, Clone, Args, PartialEq, Eq, Default)]
|
||||
#[derive(Debug, Clone, Args, PartialEq, Eq)]
|
||||
#[clap(next_help_heading = "Gas Price Oracle")]
|
||||
pub struct GasPriceOracleArgs {
|
||||
/// Number of recent blocks to check for gas price
|
||||
@ -21,6 +21,17 @@ pub struct GasPriceOracleArgs {
|
||||
pub percentile: Option<u32>,
|
||||
}
|
||||
|
||||
impl Default for GasPriceOracleArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
blocks: Some(20),
|
||||
ignore_price: Some(2),
|
||||
max_price: Some(500000000000),
|
||||
percentile: Some(60),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -46,4 +57,11 @@ mod tests {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gpo_args_default_sanity_test() {
|
||||
let default_args = GasPriceOracleArgs::default();
|
||||
let args = CommandParser::<GasPriceOracleArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ use secp256k1::SecretKey;
|
||||
use std::{net::Ipv4Addr, path::PathBuf, sync::Arc};
|
||||
|
||||
/// Parameters for configuring the network more granularity via CLI
|
||||
#[derive(Debug, Args)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
#[clap(next_help_heading = "Networking")]
|
||||
pub struct NetworkArgs {
|
||||
/// Disable the discovery service.
|
||||
@ -118,7 +118,7 @@ impl NetworkArgs {
|
||||
/// If `no_persist_peers` is true then this returns the path to the persistent peers file path.
|
||||
pub fn persistent_peers_file(&self, peers_file: PathBuf) -> Option<PathBuf> {
|
||||
if self.no_persist_peers {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(peers_file)
|
||||
@ -146,7 +146,7 @@ impl Default for NetworkArgs {
|
||||
}
|
||||
|
||||
/// Arguments to setup discovery
|
||||
#[derive(Debug, Args)]
|
||||
#[derive(Debug, Args, PartialEq, Eq)]
|
||||
pub struct DiscoveryArgs {
|
||||
/// Disable the discovery service.
|
||||
#[arg(short, long, default_value_if("dev", "true", "true"))]
|
||||
@ -256,4 +256,12 @@ mod tests {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn network_args_default_sanity_test() {
|
||||
let default_args = NetworkArgs::default();
|
||||
let args = CommandParser::<NetworkArgs>::parse_from(["reth"]).args;
|
||||
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,11 +6,13 @@ use clap::{
|
||||
builder::{RangedU64ValueParser, TypedValueParser},
|
||||
Arg, Args, Command,
|
||||
};
|
||||
use reth_primitives::constants::MAXIMUM_EXTRA_DATA_SIZE;
|
||||
use reth_primitives::constants::{
|
||||
ETHEREUM_BLOCK_GAS_LIMIT, MAXIMUM_EXTRA_DATA_SIZE, SLOT_DURATION,
|
||||
};
|
||||
use std::{borrow::Cow, ffi::OsStr, time::Duration};
|
||||
|
||||
/// Parameters for configuring the Payload Builder
|
||||
#[derive(Debug, Args, PartialEq, Default)]
|
||||
#[derive(Debug, Args, PartialEq)]
|
||||
#[clap(next_help_heading = "Builder")]
|
||||
pub struct PayloadBuilderArgs {
|
||||
/// Block extra data set by the payload builder.
|
||||
@ -46,6 +48,20 @@ pub struct PayloadBuilderArgs {
|
||||
pub compute_pending_block: bool,
|
||||
}
|
||||
|
||||
impl Default for PayloadBuilderArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
extradata: default_extradata(),
|
||||
max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
|
||||
interval: Duration::from_secs(1),
|
||||
deadline: SLOT_DURATION,
|
||||
max_payload_tasks: 3,
|
||||
#[cfg(feature = "optimism")]
|
||||
compute_pending_block: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PayloadBuilderConfig for PayloadBuilderArgs {
|
||||
fn extradata(&self) -> Cow<'_, str> {
|
||||
self.extradata.as_str().into()
|
||||
@ -94,7 +110,7 @@ impl TypedValueParser for ExtradataValueParser {
|
||||
format!(
|
||||
"Payload builder extradata size exceeds {MAXIMUM_EXTRA_DATA_SIZE}bytes limit"
|
||||
),
|
||||
))
|
||||
));
|
||||
}
|
||||
Ok(val.to_string())
|
||||
}
|
||||
@ -152,4 +168,11 @@ mod tests {
|
||||
]);
|
||||
assert!(args.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn payload_builder_args_default_sanity_check() {
|
||||
let default_args = PayloadBuilderArgs::default();
|
||||
let args = CommandParser::<PayloadBuilderArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,3 +47,23 @@ impl PruningArgs {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::{Args, Parser};
|
||||
|
||||
/// A helper type to parse Args more easily
|
||||
#[derive(Parser)]
|
||||
struct CommandParser<T: Args> {
|
||||
#[clap(flatten)]
|
||||
args: T,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pruning_args_sanity_check() {
|
||||
let default_args = PruningArgs::default();
|
||||
let args = CommandParser::<PruningArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! clap [Args](clap::Args) for op-reth rollup configuration
|
||||
|
||||
/// Parameters for rollup configuration
|
||||
#[derive(Debug, clap::Args)]
|
||||
#[derive(Debug, Default, PartialEq, Eq, clap::Args)]
|
||||
#[clap(next_help_heading = "Rollup")]
|
||||
pub struct RollupArgs {
|
||||
/// HTTP endpoint for the sequencer mempool
|
||||
@ -17,3 +17,23 @@ pub struct RollupArgs {
|
||||
#[arg(long = "rollup.enable-genesis-walkback")]
|
||||
pub enable_genesis_walkback: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::{Args, Parser};
|
||||
|
||||
/// A helper type to parse Args more easily
|
||||
#[derive(Parser)]
|
||||
struct CommandParser<T: Args> {
|
||||
#[clap(flatten)]
|
||||
args: T,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_database_args() {
|
||||
let default_args = RollupArgs::default();
|
||||
let args = CommandParser::<RollupArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ pub(crate) const RPC_DEFAULT_MAX_RESPONSE_SIZE_MB: u32 = 150;
|
||||
pub(crate) const RPC_DEFAULT_MAX_CONNECTIONS: u32 = 500;
|
||||
|
||||
/// Parameters for configuring the rpc more granularity via CLI
|
||||
#[derive(Debug, Clone, Args)]
|
||||
#[derive(Debug, Clone, Args, PartialEq, Eq)]
|
||||
#[clap(next_help_heading = "RPC")]
|
||||
pub struct RpcServerArgs {
|
||||
/// Enable the HTTP-RPC server
|
||||
@ -462,7 +462,7 @@ impl RethRpcConfig for RpcServerArgs {
|
||||
impl Default for RpcServerArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
http: true,
|
||||
http: false,
|
||||
http_addr: Ipv4Addr::LOCALHOST.into(),
|
||||
http_port: constants::DEFAULT_HTTP_RPC_PORT,
|
||||
http_api: None,
|
||||
@ -709,4 +709,12 @@ mod tests {
|
||||
assert_eq!(config.max_blocks_per_filter, Some(100));
|
||||
assert_eq!(config.max_logs_per_response, Some(200));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_server_args_default_sanity_test() {
|
||||
let default_args = RpcServerArgs::default();
|
||||
let args = CommandParser::<RpcServerArgs>::parse_from(["reth"]).args;
|
||||
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ use reth_transaction_pool::{
|
||||
};
|
||||
|
||||
/// Parameters for debugging purposes
|
||||
#[derive(Debug, Args, PartialEq, Default)]
|
||||
#[derive(Debug, Args, PartialEq)]
|
||||
#[clap(next_help_heading = "TxPool")]
|
||||
pub struct TxPoolArgs {
|
||||
/// Max number of transaction in the pending sub-pool.
|
||||
@ -48,6 +48,23 @@ pub struct TxPoolArgs {
|
||||
pub no_locals: bool,
|
||||
}
|
||||
|
||||
impl Default for TxPoolArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pending_max_count: TXPOOL_SUBPOOL_MAX_TXS_DEFAULT,
|
||||
pending_max_size: TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT,
|
||||
basefee_max_count: TXPOOL_SUBPOOL_MAX_TXS_DEFAULT,
|
||||
basefee_max_size: TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT,
|
||||
queued_max_count: TXPOOL_SUBPOOL_MAX_TXS_DEFAULT,
|
||||
queued_max_size: TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT,
|
||||
max_account_slots: TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER,
|
||||
price_bump: DEFAULT_PRICE_BUMP,
|
||||
blob_transaction_price_bump: REPLACE_BLOB_PRICE_BUMP,
|
||||
no_locals: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TxPoolArgs {
|
||||
/// Returns transaction pool configuration.
|
||||
pub fn pool_config(&self) -> PoolConfig {
|
||||
@ -77,3 +94,23 @@ impl TxPoolArgs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::Parser;
|
||||
|
||||
/// A helper type to parse Args more easily
|
||||
#[derive(Parser)]
|
||||
struct CommandParser<T: Args> {
|
||||
#[clap(flatten)]
|
||||
args: T,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn txpool_args_default_sanity_test() {
|
||||
let default_args = TxPoolArgs::default();
|
||||
let args = CommandParser::<TxPoolArgs>::parse_from(["reth"]).args;
|
||||
assert_eq!(args, default_args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ const JWT_SIGNATURE_ALGO: Algorithm = Algorithm::HS256;
|
||||
/// for the JWT, which is included in the JWT along with its payload.
|
||||
///
|
||||
/// See also: [Secret key - Engine API specs](https://github.com/ethereum/execution-apis/blob/main/src/engine/authentication.md#key-distribution)
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct JwtSecret([u8; 32]);
|
||||
|
||||
impl JwtSecret {
|
||||
|
||||
Reference in New Issue
Block a user