diff --git a/bin/reth/src/args/rpc_server_args.rs b/bin/reth/src/args/rpc_server_args.rs index 796269b6db..66937d153e 100644 --- a/bin/reth/src/args/rpc_server_args.rs +++ b/bin/reth/src/args/rpc_server_args.rs @@ -502,6 +502,7 @@ impl TypedValueParser for RpcModuleSelectionValueParser { mod tests { use super::*; use clap::Parser; + use reth_rpc_builder::RpcModuleSelection::Selection; use std::net::SocketAddrV4; /// A helper type to parse Args more easily @@ -538,6 +539,14 @@ mod tests { assert_eq!(apis, expected); } + #[test] + fn test_rpc_server_args_parser_none() { + let args = CommandParser::::parse_from(["reth", "--http.api", "none"]).args; + let apis = args.http_api.unwrap(); + let expected = Selection(vec![]); + assert_eq!(apis, expected); + } + #[test] fn test_transport_rpc_module_config() { let args = CommandParser::::parse_from([ diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index c16902e1fe..e691036280 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -135,7 +135,10 @@ #![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use crate::{auth::AuthRpcModule, error::WsHttpSamePortError, metrics::RpcServerMetrics}; +use crate::{ + auth::AuthRpcModule, error::WsHttpSamePortError, metrics::RpcServerMetrics, + RpcModuleSelection::Selection, +}; use constants::*; use error::{RpcError, ServerKind}; use hyper::{header::AUTHORIZATION, HeaderMap}; @@ -679,10 +682,14 @@ impl FromStr for RpcModuleSelection { type Err = ParseError; fn from_str(s: &str) -> Result { + if s.is_empty() { + return Ok(Selection(vec![])) + } let mut modules = s.split(',').map(str::trim).peekable(); let first = modules.peek().copied().ok_or(ParseError::VariantNotFound)?; match first { "all" | "All" => Ok(RpcModuleSelection::All), + "none" | "None" => Ok(Selection(vec![])), _ => RpcModuleSelection::try_from_selection(modules), } } @@ -2035,6 +2042,12 @@ mod tests { assert_eq!(selection, RpcModuleSelection::All); } + #[test] + fn parse_rpc_module_selection_none() { + let selection = "none".parse::().unwrap(); + assert_eq!(selection, Selection(vec![])); + } + #[test] fn parse_rpc_unique_module_selection() { let selection = "eth,admin,eth,net".parse::().unwrap(); @@ -2122,4 +2135,18 @@ mod tests { } ) } + + #[test] + fn test_configure_transport_config_none() { + let config = TransportRpcModuleConfig::default().with_http(Vec::::new()); + assert_eq!( + config, + TransportRpcModuleConfig { + http: Some(RpcModuleSelection::Selection(vec![])), + ws: None, + ipc: None, + config: None, + } + ) + } }