From 922ec72d10e15d68ec5a9b5a5e521899bf161556 Mon Sep 17 00:00:00 2001 From: esraa Date: Wed, 18 Dec 2024 16:59:02 +0200 Subject: [PATCH] Test Pool role behavior if bad `coinbase_output`.. is provided --- roles/pool/src/lib/mod.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/roles/pool/src/lib/mod.rs b/roles/pool/src/lib/mod.rs index 2603695f88..443f70f5e1 100644 --- a/roles/pool/src/lib/mod.rs +++ b/roles/pool/src/lib/mod.rs @@ -101,3 +101,38 @@ impl PoolSv2 { } } } + +#[cfg(test)] +mod tests { + use super::*; + use ext_config::{Config, File, FileFormat}; + + #[tokio::test] + async fn pool_bad_coinbase_output() { + let invalid_coinbase_output = vec![mining_pool::CoinbaseOutput::new( + "P2PK".to_string(), + "04466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276728176c3c6431f8eeda4538dc37c865e2784f3a9e77d044f33e407797e1278".to_string(), + )]; + let config_path = "config-examples/pool-config-hosted-tp-example.toml"; + let mut config: Configuration = match Config::builder() + .add_source(File::new(config_path, FileFormat::Toml)) + .build() + { + Ok(settings) => match settings.try_deserialize::() { + Ok(c) => c, + Err(e) => { + error!("Failed to deserialize config: {}", e); + return; + } + }, + Err(e) => { + error!("Failed to build config: {}", e); + return; + } + }; + config.coinbase_outputs = invalid_coinbase_output; + let pool = PoolSv2::new(config); + let result = pool.start().await; + assert!(result.is_err()); + } +}