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] 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), }