diff --git a/zebra-chain/src/parameters/network.rs b/zebra-chain/src/parameters/network.rs index bbf78e83b..6c6091c57 100644 --- a/zebra-chain/src/parameters/network.rs +++ b/zebra-chain/src/parameters/network.rs @@ -1,3 +1,5 @@ +use std::fmt; + #[cfg(any(test, feature = "proptest-impl"))] use proptest_derive::Arbitrary; @@ -11,6 +13,15 @@ pub enum Network { Testnet, } +impl fmt::Display for Network { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Network::Mainnet => f.write_str("Mainnet"), + Network::Testnet => f.write_str("Testnet"), + } + } +} + impl Network { /// Get the default port associated to this network. pub fn default_port(&self) -> u16 { diff --git a/zebra-test/src/command.rs b/zebra-test/src/command.rs index 763b4d401..f70b2fcb8 100644 --- a/zebra-test/src/command.rs +++ b/zebra-test/src/command.rs @@ -86,6 +86,7 @@ impl CommandExt for Command { dir, deadline: None, stdout: None, + bypass_test_stdout: false, }) } } @@ -152,6 +153,7 @@ pub struct TestChild { pub child: Child, pub stdout: Option>>, pub deadline: Option, + bypass_test_stdout: bool, } impl TestChild { @@ -190,6 +192,13 @@ impl TestChild { self } + /// Configures testrunner to forward stdout to the true stdout rather than + /// fakestdout used by cargo tests. + pub fn bypass_test_stdout(mut self, cond: bool) -> Self { + self.bypass_test_stdout = cond; + self + } + /// Checks each line of the child's stdout against `regex`, and returns matching lines. /// /// Kills the child after the configured timeout has elapsed. @@ -221,7 +230,13 @@ impl TestChild { // since we're about to discard this line write it to stdout so our // test runner can capture it and display if the test fails, may // cause weird reordering for stdout / stderr - println!("{}", line); + if !self.bypass_test_stdout { + println!("{}", line); + } else { + use std::io::Write; + #[allow(clippy::explicit_write)] + writeln!(std::io::stdout(), "{}", line).unwrap(); + } if re.is_match(&line) { self.stdout = Some(lines); diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index d20164bc7..96808bf07 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -652,7 +652,6 @@ fn cached_sapling_test_config() -> Result { config.consensus.checkpoint_sync = true; config.state.cache_dir = "/zebrad-cache".into(); config.state.memory_cache_bytes = 52428800; - config.tracing.endpoint_addr = Some("0.0.0.0:3000".parse().unwrap()); Ok(config) } @@ -666,15 +665,17 @@ fn create_cached_database_height(network: Network, height: Height) -> Result<()> // TODO: add convenience methods? config.network.network = network; config.state.debug_stop_at_height = Some(height.0); - let dir = PathBuf::from("/"); + let dir = PathBuf::from("/zebrad-cache"); fs::File::create(dir.join("zebrad.toml"))?.write_all(toml::to_string(&config)?.as_bytes())?; - let mut child = dir.spawn_child(&["start"])?.with_timeout(timeout); + let mut child = dir + .spawn_child(&["start"])? + .with_timeout(timeout) + .bypass_test_stdout(true); - // TODO: is there a way to check for testnet or mainnet here? - // For example: "network=Mainnet" or "network=Testnet" - child.expect_stdout("network: Mainnet,")?; + let network = format!("network: {},", network); + child.expect_stdout(&network)?; child.expect_stdout(STOP_AT_HEIGHT_REGEX)?; child.kill()?;