diff --git a/Cargo.lock b/Cargo.lock index 535ede7..db63344 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2315,6 +2315,7 @@ dependencies = [ "async-channel", "clap", "colored", + "futures", "integration_tests_sv2", "serde", "stratum-apps", diff --git a/Cargo.toml b/Cargo.toml index 4eb1657..8a6d7a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ clap = { version = "4", features = ["derive"] } colored = "2" serde = { version = "1", features = ["derive"] } toml = "0.8" +futures = "0.3" diff --git a/README.md b/README.md index 9d860a6..76e0a8d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ Built on top of [`integration_tests_sv2`](https://crates.io/crates/integration_t cargo run --bin sv2-compliance -- --config targets.toml ``` -`--config` defaults to `targets.toml` in the current directory. Exits `0` when no scenario fails, `1` otherwise; a scenario the endpoint legitimately did not let the client exercise (e.g. a standard-channel scenario against a server that set `REQUIRES_EXTENDED_CHANNELS`) is reported but does not fail the run. See `targets.example.toml` for the config format and `--help` for all options. +`--config` defaults to `targets.toml` in the current directory. Addresses accept either an IP or a hostname followed by a port (e.g. `stratum.ckpool.org:3336`); hostnames are resolved before the run starts, and an unresolvable one is reported as a failed target without stopping the remaining sites. Exits `0` when no scenario fails and every target resolves, `1` otherwise; a scenario the endpoint legitimately did not let the client exercise (e.g. a standard-channel scenario against a server that set `REQUIRES_EXTENDED_CHANNELS`) is reported but does not fail the run. See `targets.example.toml` for the config format and `--help` for all options. + +Use `--verbose` to also print the underlying resolver message when a hostname fails to resolve. ## Library @@ -29,6 +31,8 @@ async fn sv2_compliance() { } ``` +For TOML batches, `interoperability_tests_sv2::config::Config::from_path` parses the file and `resolve_targets().await` returns `Targets`, whose `resolved` and `unresolved` fields separate reachable targets from failed lookups. `Targets::is_empty()` reports a config with no addresses at all. + ## Running the tests `cargo test` spins up a local SRI Template Provider and Pool (binaries under `template-provider/` are downloaded on first run) and runs the suite against them. diff --git a/src/bin/sv2-compliance.rs b/src/bin/sv2-compliance.rs index 711f9c5..0c4d913 100644 --- a/src/bin/sv2-compliance.rs +++ b/src/bin/sv2-compliance.rs @@ -4,7 +4,8 @@ use clap::Parser; use colored::Colorize; use integration_tests_sv2::start_tracing; use interoperability_tests_sv2::{ - config::Config, + app_type::AppType, + config::{Config, Target, TargetAddress, UnresolvedTarget}, runner::run_suite, scenarios::{ScenarioError, ScenarioReport}, }; @@ -19,20 +20,95 @@ struct Cli { #[arg(short = 'c', long, default_value = "targets.toml")] config: PathBuf, - /// Verbose logging + /// Verbose logging and resolver error details #[arg(short, long)] verbose: bool, } +#[derive(Default)] +struct RunSummary { + passed: u32, + failed: u32, + not_exercised: u32, +} +impl RunSummary { + fn record(&mut self, report: &ScenarioReport) { + match &report.result { + Ok(_) => self.passed += 1, + Err(ScenarioError::NotExercised(_)) => self.not_exercised += 1, + Err(ScenarioError::Failed(_)) => self.failed += 1, + } + } + + fn succeeded(&self, unresolved: usize) -> bool { + self.failed == 0 && unresolved == 0 + } + + fn summary_line(&self, resolved: usize, unresolved: usize) -> String { + if resolved == 0 && unresolved > 0 { + return format!( + "{} no targets resolved ({} unresolved)", + "✗".red().bold(), + unresolved + ); + } + + let total = self.passed + self.failed + self.not_exercised; + let failed_note = if self.failed > 0 { + format!(", {} failed", self.failed) + } else { + String::new() + }; + let not_exercised_note = if self.not_exercised > 0 { + format!(", {} not exercised", self.not_exercised) + } else { + String::new() + }; + let unresolved_note = if unresolved > 0 { + format!("; {unresolved} target(s) unresolved") + } else { + String::new() + }; + + if self.succeeded(unresolved) { + format!( + "{} {}/{} scenarios passed{} across {} resolved target(s)", + "✓".green().bold(), + self.passed, + total, + not_exercised_note, + resolved + ) + } else { + format!( + "{} {}/{} scenarios passed{}{}{} across {} resolved target(s)", + "✗".red().bold(), + self.passed, + total, + failed_note, + not_exercised_note, + unresolved_note, + resolved + ) + } + } + + fn print(&self, resolved: usize, unresolved: usize) { + println!("{}", self.summary_line(resolved, unresolved)); + } +} + #[tokio::main] async fn main() { + let mut summary = RunSummary::default(); + let cli = Cli::parse(); if cli.verbose { start_tracing(); } let targets = match Config::from_path(&cli.config) { - Ok(config) => config.targets(), + Ok(config) => config.resolve_targets().await, Err(e) => { eprintln!("{} {e}", "error:".red().bold()); std::process::exit(1); @@ -44,60 +120,72 @@ async fn main() { std::process::exit(1); } - let mut passed = 0u32; - let mut failed = 0u32; - let mut not_exercised = 0u32; - for target in &targets { - println!( - "── {} ──", - format!( - "{}: {:?} at {}", - target.site_name, target.endpoint.app_type, target.endpoint.addr - ) - .blue() - .bold() + for target in &targets.resolved { + print_target_header( + &target.site_name, + target.endpoint.app_type, + format!("{}{}", target.address, resolved_note(target)), ); let reports = run_suite(&target.endpoint).await; for report in &reports { + summary.record(report); print_report(report); - match &report.result { - Ok(_) => passed += 1, - Err(ScenarioError::NotExercised(_)) => not_exercised += 1, - Err(ScenarioError::Failed(_)) => failed += 1, - } } println!(); } - let total = passed + failed + not_exercised; - let not_exercised_note = if not_exercised > 0 { - format!(", {not_exercised} not exercised") - } else { - String::new() - }; - if failed == 0 { - println!( - "{} {}/{} scenarios passed{} across {} target(s)", - "✓".green().bold(), - passed, - total, - not_exercised_note, - targets.len() - ); - } else { - println!( - "{} {}/{} scenarios passed, {} failed{} across {} target(s)", - "✗".red().bold(), - passed, - total, - failed, - not_exercised_note, - targets.len() - ); + for target in &targets.unresolved { + print_unresolved(target, cli.verbose); + } + + summary.print(targets.resolved.len(), targets.unresolved.len()); + + if !summary.succeeded(targets.unresolved.len()) { std::process::exit(1); } } +fn print_target_header(site_name: &str, app_type: AppType, address: String) { + println!( + "── {} ──", + format!("{site_name}: {app_type:?} at {address}") + .blue() + .bold() + ); +} + +fn print_unresolved(target: &UnresolvedTarget, verbose: bool) { + print_target_header( + &target.site_name, + target.app_type, + target.address.to_string(), + ); + + println!( + " {} target unresolved: {}", + "✗".red(), + target.error.to_string().red() + ); + + if verbose { + if let Some(detail) = target.error.detail() { + println!(" {}", detail.dimmed()); + } + } + + println!(); +} + +/// Shows the resolved IP when the configured address was a hostname. +fn resolved_note(target: &Target) -> String { + match &target.address { + TargetAddress::Socket(_) => String::new(), + TargetAddress::Hostname { .. } => { + format!(" (resolved to {})", target.endpoint.addr) + } + } +} + fn print_report(report: &ScenarioReport) { match &report.result { Ok(detail) => { diff --git a/src/config.rs b/src/config.rs index 3bccda3..e311ade 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,16 @@ //! TOML batch configuration for the `sv2-compliance` CLI. -use std::{fs, net::SocketAddr, path::Path}; - +use futures::future::join_all; use serde::Deserialize; +use std::{fmt, fs, net::SocketAddr, path::Path, str::FromStr, time::Duration}; use crate::{app_type::AppType, endpoint::Endpoint}; +/// How long to wait for the resolver for a single configured address. +const RESOLVE_TIMEOUT: Duration = Duration::from_secs(10); + +const DEFAULT_USER_IDENTITY: &str = "interoperability_tests_sv2"; + /// A set of [`Site`]s to test, loaded from a TOML file on disk. #[derive(Debug, Default, Deserialize)] #[serde(deny_unknown_fields)] @@ -22,38 +27,55 @@ impl Config { toml::from_str(&raw).map_err(|e| format!("failed to parse {}: {e}", path.display())) } - /// One [`Target`] per configured address: `mining_server_address` is tested as a - /// Mining Protocol Server, `job_declaration_server_address` as a Job Declarator Server and + /// Resolves every configured address into a [`Target`]. + /// + /// `mining_server_address` is tested as a Mining Protocol Server, + /// `job_declaration_server_address` as a Job Declarator Server and /// `template_provider_address` as a Template Provider. - pub fn targets(&self) -> Vec { - let mut out = Vec::new(); - for site in &self.site { - let user_identity = site - .user_identity - .clone() - .unwrap_or_else(|| "interoperability_tests_sv2".to_string()); - for (addr, app_type) in [ - (site.mining_server_address, AppType::MiningServer), - ( - site.job_declaration_server_address, - AppType::JobDeclarationServer, - ), - (site.template_provider_address, AppType::TemplateProvider), - ] - .into_iter() - .filter_map(|(addr, app_type)| addr.map(|a| (a, app_type))) - { - out.push(Target { - site_name: site.name.clone(), - endpoint: Endpoint { - addr, - app_type, - user_identity: user_identity.clone(), - }, - }); + /// + /// An address whose hostname fails to resolve is returned in + /// [`Targets::unresolved`] instead of aborting, so the other sites still run. + pub async fn resolve_targets(&self) -> Targets { + let mut resolved = Vec::new(); + let mut unresolved = Vec::new(); + + for site_results in join_all(self.site.iter().map(Site::resolve_addresses)).await { + for result in site_results { + match result { + Ok(target) => resolved.push(target), + Err(target) => unresolved.push(target), + } } } - out + + Targets { + resolved, + unresolved, + } + } +} + +/// Picks one address from a resolver result, preferring IPv4 when available. +fn pick_address(addrs: &[SocketAddr]) -> Option { + addrs + .iter() + .find(|addr| addr.is_ipv4()) + .or_else(|| addrs.first()) + .copied() +} + +/// The result of resolving a [`Config`]'s addresses. +pub struct Targets { + /// Endpoints that resolved to a [`SocketAddr`]. + pub resolved: Vec, + /// Endpoints whose hostname could not be resolved. + pub unresolved: Vec, +} + +impl Targets { + /// Returns `true` when the config contained no addresses at all. + pub fn is_empty(&self) -> bool { + self.resolved.is_empty() && self.unresolved.is_empty() } } @@ -61,26 +83,303 @@ impl Config { #[derive(Debug, Clone)] pub struct Target { pub site_name: String, + /// The address as configured, before hostname resolution. + pub address: TargetAddress, pub endpoint: Endpoint, } +/// Why a configured address could not be resolved. +#[derive(Debug, Clone)] +pub enum ResolveError { + /// The resolver did not answer within the configured timeout. + Timeout(Duration), + /// The OS resolver rejected the lookup; the string is its platform detail. + Lookup(String), + /// The resolver returned no addresses. + NoAddresses, +} + +impl fmt::Display for ResolveError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Timeout(after) => write!(f, "timed out after {after:?}"), + Self::Lookup(_) => write!(f, "DNS lookup failed"), + Self::NoAddresses => write!(f, "resolver returned no addresses"), + } + } +} + +impl ResolveError { + /// The platform-specific resolver detail, when there is one. + pub fn detail(&self) -> Option<&str> { + match self { + Self::Lookup(detail) => Some(detail), + _ => None, + } + } +} + +/// A configured endpoint whose hostname could not be resolved. +#[derive(Debug, Clone)] +pub struct UnresolvedTarget { + pub site_name: String, + pub address: TargetAddress, + pub app_type: AppType, + pub error: ResolveError, +} + /// A named deployment of one or more Sv2 endpoints. #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct Site { pub name: String, - pub mining_server_address: Option, - pub job_declaration_server_address: Option, - pub template_provider_address: Option, + pub mining_server_address: Option, + pub job_declaration_server_address: Option, + pub template_provider_address: Option, pub user_identity: Option, } +impl Site { + /// Resolves this site's configured addresses concurrently. + async fn resolve_addresses(&self) -> Vec> { + let user_identity = self + .user_identity + .clone() + .unwrap_or_else(|| DEFAULT_USER_IDENTITY.to_string()); + + join_all( + [ + (self.mining_server_address.as_ref(), AppType::MiningServer), + ( + self.job_declaration_server_address.as_ref(), + AppType::JobDeclarationServer, + ), + ( + self.template_provider_address.as_ref(), + AppType::TemplateProvider, + ), + ] + .into_iter() + .filter_map(|(address, app_type)| { + address.map(|address| { + let user_identity = user_identity.clone(); + async move { + match address.resolve().await { + Ok(addr) => Ok(Target { + site_name: self.name.clone(), + address: address.clone(), + endpoint: Endpoint { + addr, + app_type, + user_identity, + }, + }), + Err(error) => Err(UnresolvedTarget { + site_name: self.name.clone(), + address: address.clone(), + app_type, + error, + }), + } + } + }) + }), + ) + .await + } +} + +#[derive(Debug, PartialEq, Deserialize, Clone)] +#[serde(try_from = "String")] +pub enum TargetAddress { + Socket(SocketAddr), + Hostname { host: String, port: u16 }, +} + +impl TryFrom for TargetAddress { + type Error = String; + + fn try_from(value: String) -> Result { + value.parse() + } +} + +impl TargetAddress { + async fn resolve(&self) -> Result { + match self { + Self::Socket(addr) => Ok(*addr), + Self::Hostname { host, port } => { + let addrs: Vec = tokio::time::timeout( + RESOLVE_TIMEOUT, + tokio::net::lookup_host((host.as_str(), *port)), + ) + .await + .map_err(|_| ResolveError::Timeout(RESOLVE_TIMEOUT))? + .map_err(|e| ResolveError::Lookup(e.to_string()))? + .collect(); + + pick_address(&addrs).ok_or(ResolveError::NoAddresses) + } + } + } +} + +impl FromStr for TargetAddress { + type Err = String; + + fn from_str(s: &str) -> Result { + if let Ok(addr) = s.parse::() { + return Ok(Self::Socket(addr)); + } + + if s.contains('/') { + return Err(format!( + "invalid address {s:?}: expected host:port, not a URL" + )); + } + + let (host, port) = s.rsplit_once(':').ok_or_else(|| { + format!( + "invalid address {s:?}: expected host:port \ + (for example my.pool.org:3336)" + ) + })?; + + if host.is_empty() { + return Err(format!("invalid address {s:?}: host is empty")); + } + + if host.contains(':') { + return Err(format!( + "invalid address {s:?}: IPv6 addresses must be bracketed, \ + for example [::1]:3333" + )); + } + + if host.chars().any(char::is_whitespace) { + return Err(format!( + "invalid address {s:?}: host must not contain whitespace" + )); + } + + if host.chars().all(|c| c.is_ascii_digit() || c == '.') { + return Err(format!("invalid address {s:?}: invalid IPv4 address")); + } + + Ok(Self::Hostname { + host: host.to_string(), + port: port + .parse() + .map_err(|_| format!("invalid address {s:?}: invalid port"))?, + }) + } +} + +impl fmt::Display for TargetAddress { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Socket(addr) => write!(f, "{addr}"), + Self::Hostname { host, port } => write!(f, "{host}:{port}"), + } + } +} + #[cfg(test)] mod tests { use super::*; #[test] - fn parses_sites_into_endpoints() { + fn parses_hostname_address() { + let addr: TargetAddress = "stratum.ckpool.org:3336".parse().unwrap(); + assert_eq!( + addr, + TargetAddress::Hostname { + host: "stratum.ckpool.org".to_string(), + port: 3336, + } + ); + + assert_eq!(addr.to_string(), "stratum.ckpool.org:3336"); + } + + #[test] + fn parses_ip_literal() { + let ipv4: TargetAddress = "75.119.150.111:3333".parse().unwrap(); + assert_eq!( + ipv4, + TargetAddress::Socket("75.119.150.111:3333".parse().unwrap()) + ); + + let ipv6: TargetAddress = "[::1]:3334".parse().unwrap(); + assert_eq!(ipv6, TargetAddress::Socket("[::1]:3334".parse().unwrap())); + assert_eq!(ipv6.to_string(), "[::1]:3334"); + } + + #[test] + fn target_address_rejects_url_with_clear_error() { + let error = "stratum+tcp://sri.pool.org:3333" + .parse::() + .unwrap_err(); + assert!( + error.contains("not a URL"), + "expected a URL-specific error, got {error}" + ); + } + + #[test] + fn target_address_rejects_invalid_addresses() { + for address in [ + "sri.pool.org", + ":3333", + "::1:3333", + "stratum+tcp://sri.pool.org:3333", + "sri.pool.org:not-a-port-number", + "sri pool.org:42", + "sri\tpool.org:42", + "51.161.49:34255", + "1.2.3:80", + ] { + assert!( + address.parse::().is_err(), + "{address} should be rejected" + ); + } + } + + #[test] + fn target_address_deserializes_from_toml() { + #[derive(serde::Deserialize)] + struct Wrapper { + addr: TargetAddress, + } + + let wrapper: Wrapper = toml::from_str("addr = \"localhost:3333\"").unwrap(); + assert_eq!( + wrapper.addr, + TargetAddress::Hostname { + host: "localhost".to_string(), + port: 3333 + } + ); + } + + #[test] + fn resolve_error_display_is_stable() { + let lookup = ResolveError::Lookup("nodename nor servname provided".to_string()); + assert_eq!(lookup.to_string(), "DNS lookup failed"); + assert_eq!(lookup.detail(), Some("nodename nor servname provided")); + + let timeout = ResolveError::Timeout(Duration::from_secs(10)); + assert_eq!(timeout.to_string(), "timed out after 10s"); + assert_eq!(timeout.detail(), None); + + let no_addresses = ResolveError::NoAddresses; + assert_eq!(no_addresses.to_string(), "resolver returned no addresses"); + assert_eq!(no_addresses.detail(), None); + } + + #[tokio::test] + async fn parses_sites_into_endpoints() { let raw = r#" [[site]] name = "SRI Pool" @@ -92,11 +391,18 @@ template_provider_address = "51.161.49.55:8442" name = "Empty Site" "#; let config: Config = toml::from_str(raw).expect("valid toml"); - let targets = config.targets(); - assert_eq!(targets.len(), 3); - assert_eq!(targets[0].endpoint.app_type, AppType::MiningServer); - assert_eq!(targets[1].endpoint.app_type, AppType::JobDeclarationServer); - assert_eq!(targets[2].endpoint.app_type, AppType::TemplateProvider); + let targets = config.resolve_targets().await; + assert!(targets.unresolved.is_empty()); + assert_eq!(targets.resolved.len(), 3); + assert_eq!(targets.resolved[0].endpoint.app_type, AppType::MiningServer); + assert_eq!( + targets.resolved[1].endpoint.app_type, + AppType::JobDeclarationServer + ); + assert_eq!( + targets.resolved[2].endpoint.app_type, + AppType::TemplateProvider + ); } /// A misspelled field must fail to parse rather than leave a site with @@ -110,4 +416,103 @@ mining_server_adress = "51.161.49.55:34255" "#; assert!(toml::from_str::(raw).is_err()); } + + #[test] + fn parses_host_address_from_config() { + let raw = r#" + [[site]] + name = "Mixed" + mining_server_address = "stratum.ckpool.org:3336" + job_declaration_server_address = "192.168.0.1:34256" + template_provider_address = "[::1]:8442" + "#; + + let config: Config = toml::from_str(raw).expect("expected a valid toml"); + let site = &config.site[0]; + + assert_eq!( + site.mining_server_address, + Some(TargetAddress::Hostname { + host: "stratum.ckpool.org".to_string(), + port: 3336 + }) + ); + + assert_eq!( + site.job_declaration_server_address, + Some(TargetAddress::Socket("192.168.0.1:34256".parse().unwrap())) + ); + + assert_eq!( + site.template_provider_address, + Some(TargetAddress::Socket("[::1]:8442".parse().unwrap())) + ); + } + + #[tokio::test] + async fn unresolved_hostname_does_not_drop_other_targets() { + let raw = r#" + [[site]] + name = "Resolved" + mining_server_address = "localhost:34255" + + [[site]] + name = "Unresolved" + mining_server_address = "not-a-valid-host.invalid:3333" + "#; + + let config: Config = toml::from_str(raw).expect("expected a valid toml"); + let targets = config.resolve_targets().await; + + assert_eq!(targets.resolved.len(), 1); + assert_eq!(targets.resolved[0].site_name, "Resolved"); + assert_eq!(targets.resolved[0].endpoint.addr.port(), 34255); + + assert_eq!(targets.unresolved.len(), 1); + assert_eq!(targets.unresolved[0].site_name, "Unresolved"); + assert_eq!( + targets.unresolved[0].address, + TargetAddress::Hostname { + host: "not-a-valid-host.invalid".to_string(), + port: 3333, + } + ); + } + + #[test] + fn targets_is_empty_only_when_both_lists_are_empty() { + let empty = Targets { + resolved: Vec::new(), + unresolved: Vec::new(), + }; + + assert!(empty.is_empty()); + + let unresolved = Targets { + resolved: Vec::new(), + unresolved: vec![UnresolvedTarget { + site_name: "Unresolved".to_string(), + address: TargetAddress::Hostname { + host: "does-not-exist.invalid".to_string(), + port: 3333, + }, + app_type: AppType::MiningServer, + error: ResolveError::NoAddresses, + }], + }; + assert!(!unresolved.is_empty()); + } + + #[test] + fn prefers_ipv4_over_ipv6() { + let addrs: [SocketAddr; 2] = [ + "[::1]:3333".parse().unwrap(), + "127.0.0.1:3333".parse().unwrap(), + ]; + + assert_eq!( + pick_address(&addrs), + Some("127.0.0.1:3333".parse().unwrap()) + ); + } } diff --git a/targets.example.toml b/targets.example.toml index 103c343..d9401bc 100644 --- a/targets.example.toml +++ b/targets.example.toml @@ -6,6 +6,10 @@ # template_provider_address -> Template Provider (no scenarios yet, see COVERAGE.md) # # `user_identity` (optional) is used when opening mining channels. +# +# Addresses are `host:port`; the host may be a hostname or an IP address, e.g. +# "stratum.ckpool.org:3336" or "51.81.56.15:3336". Hostnames are resolved +# before the run starts, so they do not need to be pinned to an IP. [[site]] name = "SRI Community SoloPool" diff --git a/tests/cli_unresolved.rs b/tests/cli_unresolved.rs new file mode 100644 index 0000000..53998ca --- /dev/null +++ b/tests/cli_unresolved.rs @@ -0,0 +1,76 @@ +use std::process::Command; + +fn run_cli(config_name: &str, contents: &str) -> String { + let config = std::path::Path::new(env!("CARGO_TARGET_TMPDIR")).join(config_name); + std::fs::write(&config, contents).unwrap(); + + let output = Command::new(env!("CARGO_BIN_EXE_sv2-compliance")) + .args(["--config", config.to_str().unwrap()]) + .output() + .unwrap(); + + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!( + !output.status.success(), + "stdout: {stdout}\nstderr: {stderr}" + ); + stdout.into_owned() +} + +#[test] +fn cli_reports_unresolved_target_and_exits_nonzero() { + let stdout = run_cli( + "unresolved.toml", + r#" +[[site]] +name = "Unresolved" +mining_server_address = "unreachable-hostname.invalid:3333" +"#, + ); + + assert!(stdout.contains("Unresolved"), "stdout: {stdout}"); + assert!( + stdout.contains("unreachable-hostname.invalid:3333"), + "stdout: {stdout}" + ); + assert!( + !stdout.contains("failed to lookup address information"), + "default output should not expose resolver detail: {stdout}" + ); +} + +#[test] +fn cli_shows_resolved_ip_for_hostname() { + let stdout = run_cli( + "resolved-hostname.toml", + r#" +[[site]] +name = "Resolved" +mining_server_address = "localhost:9" +"#, + ); + + assert!( + stdout.contains("Resolved: MiningServer at localhost:9 (resolved to 127.0.0.1:9)"), + "stdout: {stdout}" + ); +} + +#[test] +fn cli_reports_no_resolved_targets() { + let stdout = run_cli( + "no-resolved.toml", + r#" +[[site]] +name = "Unresolved" +mining_server_address = "unreachable-hostname.invalid:3333" +"#, + ); + + assert!( + stdout.contains("no targets resolved (1 unresolved)"), + "stdout: {stdout}" + ); + assert!(!stdout.contains("0/0 scenarios passed"), "stdout: {stdout}"); +} diff --git a/tests/config_run.rs b/tests/config_run.rs index a07da51..ce8a604 100644 --- a/tests/config_run.rs +++ b/tests/config_run.rs @@ -6,7 +6,7 @@ use integration_tests_sv2::{ }; use interoperability_tests_sv2::{config::Config, runner::run_suite}; -/// The TOML batch path used by the CLI. +/// The TOML batch path used by the CLI, with IP and hostname targets. #[tokio::test] async fn config_driven_run_against_pool() { start_tracing(); @@ -18,13 +18,20 @@ async fn config_driven_run_against_pool() { [[site]] name = "Local Pool" mining_server_address = "{pool_addr}" -"# + +[[site]] +name = "Local Pool by hostname" +mining_server_address = "localhost:{}" +"#, + pool_addr.port() ); + let config: Config = toml::from_str(&raw).expect("valid toml"); - let targets = config.targets(); - assert_eq!(targets.len(), 1); + let targets = config.resolve_targets().await; + assert!(targets.unresolved.is_empty()); + assert_eq!(targets.resolved.len(), 2); - for target in &targets { + for target in &targets.resolved { let reports = run_suite(&target.endpoint).await; common::assert_suite(&reports); }