Skip to content

Commit 81d1658

Browse files
Add roundtrip tests
Co-authored-by: SarcasticNastik <[email protected]>
1 parent 6a717bf commit 81d1658

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/descriptor/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
651651
#[cfg(test)]
652652
mod tests {
653653
use super::checksum::desc_checksum;
654+
use super::tr::Tr;
654655
use super::*;
655656
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
656657
use bitcoin::blockdata::script::Instruction;
@@ -1117,6 +1118,44 @@ mod tests {
11171118
assert_eq!(check, &Ok(Instruction::Op(OP_CSV)))
11181119
}
11191120

1121+
#[test]
1122+
fn tr_roundtrip_key() {
1123+
let script = Tr::<DummyKey>::from_str("tr()").unwrap().to_string();
1124+
assert_eq!(script, format!("tr()#x4ml3kxd"))
1125+
}
1126+
1127+
#[test]
1128+
fn tr_roundtrip_script() {
1129+
let descriptor = Tr::<DummyKey>::from_str("tr(,{pk(),pk()})")
1130+
.unwrap()
1131+
.to_string();
1132+
1133+
assert_eq!(descriptor, "tr(,{pk(),pk()})#7dqr6v8r")
1134+
}
1135+
1136+
#[test]
1137+
fn tr_roundtrip_tree() {
1138+
let p1 = "020000000000000000000000000000000000000000000000000000000000000001";
1139+
let p2 = "020000000000000000000000000000000000000000000000000000000000000002";
1140+
let p3 = "020000000000000000000000000000000000000000000000000000000000000003";
1141+
let p4 = "020000000000000000000000000000000000000000000000000000000000000004";
1142+
let p5 = "f54a5851e9372b87810a8e60cdd2e7cfd80b6e31";
1143+
let descriptor = Tr::<PublicKey>::from_str(&format!(
1144+
"tr({},{{pk({}),{{pk({}),or_d(pk({}),pkh({}))}}}})",
1145+
p1, p2, p3, p4, p5
1146+
))
1147+
.unwrap()
1148+
.to_string();
1149+
1150+
assert_eq!(
1151+
descriptor,
1152+
format!(
1153+
"tr({},{{pk({}),{{pk({}),or_d(pk({}),pkh({}))}}}})#fdhmu4fj",
1154+
p1, p2, p3, p4, p5
1155+
)
1156+
)
1157+
}
1158+
11201159
#[test]
11211160
fn roundtrip_tests() {
11221161
let descriptor = Descriptor::<bitcoin::PublicKey>::from_str("multi");

0 commit comments

Comments
 (0)