test(cli): add chain args test (#1488)

This commit is contained in:
Matthias Seitz
2023-02-22 13:05:16 +01:00
committed by GitHub
parent 8f4e6f6974
commit eccafd1bed
4 changed files with 41 additions and 3 deletions

View File

@ -167,10 +167,9 @@ impl RpcServerArgs {
#[cfg(test)]
mod tests {
use std::net::SocketAddrV4;
use super::*;
use clap::Parser;
use std::net::SocketAddrV4;
/// A helper type to parse Args more easily
#[derive(Parser)]

View File

@ -173,3 +173,17 @@ impl ImportCommand {
confy::load_path::<Config>(&self.config).wrap_err("Could not load config")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_common_import_command_chain_args() {
for chain in ["mainnet", "sepolia", "goerli"] {
let args: ImportCommand =
ImportCommand::parse_from(["reth", "--chain", chain, "--path", "."]);
assert_eq!(args.chain.chain, chain.parse().unwrap());
}
}
}

View File

@ -36,7 +36,6 @@ use reth_network::{
use reth_network_api::NetworkInfo;
use reth_primitives::{BlockNumber, ChainSpec, Head, H256};
use reth_provider::{BlockProvider, HeaderProvider, ShareableDatabase};
use reth_staged_sync::{
utils::{
chainspec::genesis_value_parser,
@ -500,3 +499,16 @@ pub async fn handle_events(mut events: impl Stream<Item = NodeEvent> + Unpin) {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_common_node_command_chain_args() {
for chain in ["mainnet", "sepolia", "goerli"] {
let args: Command = Command::parse_from(["reth", "--chain", chain]);
assert_eq!(args.chain.chain, chain.parse().unwrap());
}
}
}

View File

@ -29,3 +29,16 @@ pub fn genesis_value_parser(s: &str) -> Result<ChainSpec, eyre::Error> {
}
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_chain_spec() {
for chain in ["mainnet", "sepolia", "goerli"] {
chain_spec_value_parser(chain).unwrap();
genesis_value_parser(chain).unwrap();
}
}
}