Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
22 changes: 20 additions & 2 deletions crates/test/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions crates/test/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}