#![allow(missing_docs)]
#![cfg(feature = "cli-compiler")]
use assert_cmd::Command;
#[test]
fn compile_pk_segwitv0() {
Command::cargo_bin("md")
.unwrap()
.args(["compile", "pk(@0)", "--context", "segwitv0"])
.assert()
.success()
.stdout(predicates::str::starts_with("wsh("));
}
#[cfg(feature = "json")]
#[test]
fn compile_json() {
Command::cargo_bin("md")
.unwrap()
.args(["compile", "pk(@0)", "--context", "segwitv0", "--json"])
.assert()
.success()
.stdout(predicates::str::contains("\"schema\": \"md-cli/1\""))
.stdout(predicates::str::contains("\"template\":"));
}
#[test]
fn compile_pk_tap_emits_keypath_only() {
Command::cargo_bin("md")
.unwrap()
.args(["compile", "pk(@0)", "--context", "tap"])
.assert()
.success()
.stdout(predicates::str::starts_with("tr(@0)"));
}
#[test]
fn compile_thresh_2_of_3_tap_auto_nums() {
Command::cargo_bin("md").unwrap()
.args(["compile", "thresh(2,pk(@0),pk(@1),pk(@2))", "--context", "tap"])
.assert().success()
.stdout(predicates::str::contains(
"tr(50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0,multi_a(2,@0,@1,@2))",
));
}
#[test]
fn compile_or_pk_and_pk_older_tap() {
Command::cargo_bin("md")
.unwrap()
.args([
"compile",
"or(pk(@0),and(pk(@1),older(144)))",
"--context",
"tap",
])
.assert()
.success()
.stdout(predicates::str::starts_with(
"tr(@0,and_v(v:pk(@1),older(144)))",
));
}
#[test]
fn compile_segwitv0_rejects_unspendable_key() {
Command::cargo_bin("md")
.unwrap()
.args([
"compile",
"pk(@0)",
"--context",
"segwitv0",
"--unspendable-key",
"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0",
])
.assert()
.failure()
.stderr(predicates::str::contains(
"--unspendable-key is only valid for --context tap",
));
}
#[test]
fn compile_empty_unspendable_key_rejected() {
Command::cargo_bin("md")
.unwrap()
.args([
"compile",
"pk(@0)",
"--context",
"tap",
"--unspendable-key",
"",
])
.assert()
.failure()
.stderr(predicates::str::contains(
"--unspendable-key must not be empty",
));
}
#[test]
fn compile_pk_tap_with_explicit_nums_unspendable_key() {
Command::cargo_bin("md")
.unwrap()
.args([
"compile",
"pk(@0)",
"--context",
"tap",
"--unspendable-key",
"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0",
])
.assert()
.success()
.stdout(predicates::str::starts_with("tr(@0)"));
}
#[test]
fn compile_unspendable_key_rejects_xpub_form() {
Command::cargo_bin("md")
.unwrap()
.args([
"compile",
"thresh(2,pk(@0),pk(@1),pk(@2))",
"--context",
"tap",
"--unspendable-key",
"xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz",
])
.assert()
.failure()
.stderr(predicates::str::contains(
"--unspendable-key currently only accepts the BIP-341 NUMS H-point literal hex",
))
.stderr(predicates::str::contains("deferred to a future version"));
}
#[test]
fn compile_unspendable_key_rejects_non_nums_x_only_hex() {
Command::cargo_bin("md")
.unwrap()
.args([
"compile",
"thresh(2,pk(@0),pk(@1),pk(@2))",
"--context",
"tap",
"--unspendable-key",
"0000000000000000000000000000000000000000000000000000000000000001",
])
.assert()
.failure()
.stderr(predicates::str::contains(
"--unspendable-key currently only accepts the BIP-341 NUMS H-point literal hex",
));
}
#[test]
fn encode_from_policy_unspendable_key_rejects_xpub_form() {
Command::cargo_bin("md")
.unwrap()
.args([
"encode",
"--from-policy",
"thresh(2,pk(@0),pk(@1),pk(@2))",
"--context",
"tap",
"--unspendable-key",
"xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz",
])
.assert()
.failure()
.stderr(predicates::str::contains(
"--unspendable-key currently only accepts the BIP-341 NUMS H-point literal hex",
));
}