Skip to content

Commit c952638

Browse files
committed
Add roundtrip tests
1 parent 88d79c1 commit c952638

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/descriptor/mod.rs

+39
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
625625
#[cfg(test)]
626626
mod tests {
627627
use super::checksum::desc_checksum;
628+
use super::tr::Tr;
628629
use super::DescriptorTrait;
629630
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
630631
use bitcoin::blockdata::script::Instruction;
@@ -1092,6 +1093,44 @@ mod tests {
10921093
assert_eq!(check, &Ok(Instruction::Op(OP_CSV)))
10931094
}
10941095

1096+
#[test]
1097+
fn tr_roundtrip_key() {
1098+
let script = Tr::<DummyKey>::from_str("tr()").unwrap().to_string();
1099+
assert_eq!(script, format!("tr()#x4ml3kxd"))
1100+
}
1101+
1102+
#[test]
1103+
fn tr_roundtrip_script() {
1104+
let descriptor = Tr::<DummyKey>::from_str("tr(,{pk(),pk()})")
1105+
.unwrap()
1106+
.to_string();
1107+
1108+
assert_eq!(descriptor, "tr(,{pk(),pk()})#7dqr6v8r")
1109+
}
1110+
1111+
#[test]
1112+
fn tr_roundtrip_tree() {
1113+
let p1 = "020000000000000000000000000000000000000000000000000000000000000001";
1114+
let p2 = "020000000000000000000000000000000000000000000000000000000000000002";
1115+
let p3 = "020000000000000000000000000000000000000000000000000000000000000003";
1116+
let p4 = "020000000000000000000000000000000000000000000000000000000000000004";
1117+
let p5 = "f54a5851e9372b87810a8e60cdd2e7cfd80b6e31";
1118+
let descriptor = Tr::<PublicKey>::from_str(&format!(
1119+
"tr({},{{pk({}),{{pk({}),or_d(pk({}),pkh({}))}}}})",
1120+
p1, p2, p3, p4, p5
1121+
))
1122+
.unwrap()
1123+
.to_string();
1124+
1125+
assert_eq!(
1126+
descriptor,
1127+
format!(
1128+
"tr({},{{pk({}),{{pk({}),or_d(pk({}),pkh({}))}}}})#fdhmu4fj",
1129+
p1, p2, p3, p4, p5
1130+
)
1131+
)
1132+
}
1133+
10951134
#[test]
10961135
fn roundtrip_tests() {
10971136
let descriptor = Descriptor::<bitcoin::PublicKey>::from_str("multi");

0 commit comments

Comments
 (0)