-
Notifications
You must be signed in to change notification settings - Fork 88
feat(compile): compile taproot descriptor with randomized unspendable internal key #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a541122
6c3e071
09a381b
d763986
189c710
df6ee82
791a775
7b9a84e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,3 +60,6 @@ verify = [] | |
| # Extra utility tools | ||
| # Compile policies | ||
| compiler = [] | ||
|
|
||
| [dev-dependencies] | ||
| shlex = "1.3.0" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,9 @@ pub enum BDKCliError { | |
| #[error("Miniscript error: {0}")] | ||
| MiniscriptError(#[from] bdk_wallet::miniscript::Error), | ||
|
|
||
| #[error("Miniscript compiler error: {0}")] | ||
| MiniscriptCompilerError(#[from] bdk_wallet::miniscript::policy::compiler::CompilerError), | ||
|
|
||
|
Comment on lines
+48
to
+50
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above miniscript error wraps all the errors from miniscript including this one.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this error only for creating policies in a more concise way: Which way do you prefer more?
|
||
| #[error("ParseError: {0}")] | ||
| ParseError(#[from] bdk_wallet::bitcoin::address::ParseError), | ||
|
|
||
|
|
@@ -78,6 +81,10 @@ pub enum BDKCliError { | |
| #[error("Signer error: {0}")] | ||
| SignerError(#[from] bdk_wallet::signer::SignerError), | ||
|
|
||
| #[cfg(feature = "compiler")] | ||
| #[error("Secp256k1 error: {0}")] | ||
| Secp256k1Error(#[from] bdk_wallet::bitcoin::secp256k1::Error), | ||
|
|
||
| #[cfg(feature = "electrum")] | ||
| #[error("Electrum error: {0}")] | ||
| Electrum(#[from] bdk_electrum::electrum_client::Error), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Copyright (c) 2020-2025 Bitcoin Dev Kit Developers | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| //! Compile Command Tests | ||
| //! | ||
| //! Tests for compile command and subcommands | ||
|
|
||
| use std::process::Command; | ||
|
|
||
| fn run_cmd(cmd: &str) -> Result<String, String> { | ||
| let full_cmd = format!("run --features compiler -- {}", cmd); | ||
| let args = shlex::split(&full_cmd).unwrap(); | ||
|
|
||
| let output = Command::new("cargo").args(args).output().unwrap(); | ||
| let stdout = String::from_utf8_lossy(&output.stdout).to_string(); | ||
| let stderr = String::from_utf8_lossy(&output.stderr).to_string(); | ||
|
|
||
| if output.status.success() { | ||
| Ok(stdout) | ||
| } else { | ||
| Err(stderr) | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_compile_taproot() { | ||
| let stdout = run_cmd(r#"compile "pk(ABC)" -t tr"#).unwrap(); | ||
| let json: serde_json::Value = serde_json::from_str(&stdout).unwrap(); | ||
|
|
||
| assert!(json.get("descriptor").is_some()); | ||
| assert!(json.get("r").is_some()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_compile_sh() { | ||
| let stdout = run_cmd(r#"compile "pk(ABC)" -t sh"#).unwrap(); | ||
| let json: serde_json::Value = serde_json::from_str(&stdout).unwrap(); | ||
|
|
||
| assert!(json.get("descriptor").is_some()); | ||
| assert!(json.get("r").is_none()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_invalid_cases() { | ||
| // Test invalid policy syntax | ||
| let stderr = run_cmd(r#"compile "invalid_policy""#).unwrap_err(); | ||
| assert!(stderr.contains("Miniscript error")); | ||
|
|
||
| // Test invalid script type | ||
| let stderr = run_cmd(r#"compile "pk(A)" -t invalid_type"#).unwrap_err(); | ||
| assert!(stderr.contains("error: invalid value 'invalid_type' for '--type <SCRIPT_TYPE>'")); | ||
|
|
||
| // Test empty policy | ||
| let stderr = run_cmd("compile").unwrap_err(); | ||
| assert!(stderr.contains("error: the following required arguments were not provided")); | ||
| assert!(stderr.contains("<POLICY>")); | ||
|
|
||
| // Test malformed policy with unmatched parentheses | ||
| let stderr = run_cmd(r#"compile "pk(A""#).unwrap_err(); | ||
| assert!(stderr.contains("Miniscript error: expected )")); | ||
|
|
||
| // Test policy with unknown function | ||
| let stderr = run_cmd(r#"compile "unknown_func(A)""#).unwrap_err(); | ||
| assert!(stderr.contains("Miniscript error: unexpected «unknown_func»")); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shlexis an optional dependency, so instead of re-installing it under dev dependencies, it's better to make it a non-optional dependency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shlexneeds to remain both optional and in dev-dependencies:replfeature, so other builds don't need itcargo test --no-default-featureswhich excludesrepl, but tests still needshlexto compileMaking it non-optional would unnecessarily add the dependency to all builds.
Alternatively, we could accept the dependency overhead but simplify the code and CI in return?