Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Unreleased]

- Handle `ElementsRegtest` in test context instead of panicking; return clear error for invalid network values.

## [0.0.2]

- Implemented `simplex init` and `simplex clean` commands.
Expand Down
34 changes: 33 additions & 1 deletion crates/test/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl TestContext {
let network = match esplora.network.as_str() {
"Liquid" => SimplicityNetwork::Liquid,
"LiquidTestnet" => SimplicityNetwork::LiquidTestnet,
_ => panic!("Impossible branch reached, please report a bug"),
"ElementsRegtest" => SimplicityNetwork::default_regtest(),
other => return Err(TestError::BadNetworkName(other.to_string())),
};
let provider = Box::new(EsploraProvider::new(esplora.url, network));

Expand All @@ -91,3 +92,34 @@ impl TestContext {
Ok((signer, client))
}
}

#[cfg(test)]
mod tests {
use std::fs;

use super::*;

#[test]
fn invalid_network_returns_error() {
let config = r#"
mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean"
bitcoins = 10000

[esplora]
url = "http://localhost:3000"
network = "InvalidNetwork"
"#;

let path = std::env::temp_dir().join("smplx_test_invalid_network.toml");
fs::write(&path, config).unwrap();

let result = TestContext::new(path);
let Err(e) = result else {
panic!("expected BadNetworkName error")
};
assert!(
matches!(e, TestError::BadNetworkName(ref s) if s == "InvalidNetwork"),
"expected BadNetworkName, got: {e}"
);
}
}
3 changes: 3 additions & 0 deletions crates/test/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ pub enum TestError {

#[error("io error occurred: '{0}'")]
Io(#[from] io::Error),

#[error("Network name should either be `Liquid`, `LiquidTestnet` or `ElementsRegtest`, got: {0}")]
BadNetworkName(String),
}