From 6f06195d1e92821ecbd0a082124a522a8e0e1f30 Mon Sep 17 00:00:00 2001 From: panditdhamdhere Date: Tue, 24 Mar 2026 21:43:46 +0530 Subject: [PATCH 1/2] Validate test config network names at load time. Fail early when `test.esplora.network` is invalid so mistyped values are caught with a clear error instead of surfacing later in runtime setup. Made-with: Cursor --- crates/test/src/config.rs | 22 ++++++++++++++++++++-- crates/test/src/error.rs | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/test/src/config.rs b/crates/test/src/config.rs index 929e1af..459afb4 100644 --- a/crates/test/src/config.rs +++ b/crates/test/src/config.rs @@ -43,8 +43,10 @@ impl TestConfig { file.read_to_string(&mut content)?; - // TODO: check that network name is correct - Ok(toml::from_str(&content)?) + let config: Self = toml::from_str(&content)?; + Self::validate(&config)?; + + Ok(config) } pub fn to_regtest_config(&self) -> RegtestConfig { @@ -66,6 +68,22 @@ impl TestConfig { Ok(()) } + + fn validate(config: &Self) -> Result<(), TestError> { + if let Some(esplora_config) = &config.esplora { + Self::validate_network(&esplora_config.network)?; + } + + Ok(()) + } + + fn validate_network(network: &str) -> Result<(), TestError> { + if network != "Liquid" && network != "LiquidTestnet" && network != "ElementsRegtest" { + return Err(TestError::BadNetworkName(network.to_string())); + } + + Ok(()) + } } impl Default for TestConfig { diff --git a/crates/test/src/error.rs b/crates/test/src/error.rs index 01f26c0..20cdff6 100644 --- a/crates/test/src/error.rs +++ b/crates/test/src/error.rs @@ -19,6 +19,9 @@ pub enum TestError { #[error("Failed to deserialize config: '{0}'")] ConfigDeserialize(#[from] toml::de::Error), + #[error("Network name should either be `Liquid`, `LiquidTestnet` or `ElementsRegtest`, got: {0}")] + BadNetworkName(String), + #[error("io error occurred: '{0}'")] Io(#[from] io::Error), } From 01fdc1fa3fc32883f2e1f63a81ec0f7e5bf4d9cd Mon Sep 17 00:00:00 2001 From: panditdhamdhere Date: Tue, 24 Mar 2026 21:50:08 +0530 Subject: [PATCH 2/2] Document test network validation fix in changelog. Add a changelog entry for fail-fast validation of `test.esplora.network` values during test config loading. Made-with: Cursor --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b08c67f..bfe5722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fixed regtest not accepting transactions with multiple OP_RETURNs. - Added `send` method to the signer to be able to quickly send a policy asset. - Extended `get_wpkh_utxos` method to be able to filter signer's UTXOs on the fly. +- Validated `test.esplora.network` values when loading test config to fail early on invalid network names. ## [0.0.1]