Skip to content

Commit 1384586

Browse files
committed
feat(policy): change semantic::Policy Display to mathematical notation
1 parent 04f1c58 commit 1384586

5 files changed

Lines changed: 320 additions & 14 deletions

File tree

examples/htlc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737
// Lift the descriptor into an abstract policy.
3838
assert_eq!(
3939
format!("{}", htlc_descriptor.lift().unwrap()),
40-
"or(and(pk(022222222222222222222222222222222222222222222222222222222222222222),sha256(1111111111111111111111111111111111111111111111111111111111111111)),and(pk(020202020202020202020202020202020202020202020202020202020202020202),older(4444)))"
40+
"((pk(022222222222222222222222222222222222222222222222222222222222222222)sha256(1111111111111111111111111111111111111111111111111111111111111111))(pk(020202020202020202020202020202020202020202020202020202020202020202)older(4444)))"
4141
);
4242

4343
// Get the scriptPubkey for this Wsh descriptor.

fuzz/fuzz_targets/regression_descriptor_parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn do_test(data: &[u8]) {
3535
(Ok(new), Ok(old)) => {
3636
assert_eq!(
3737
old.to_string(),
38-
new.to_string(),
38+
new.to_policy_syntax_string(),
3939
"lifted input {} (left is old, right is new)",
4040
data_str
4141
)

src/descriptor/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,15 +2175,15 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
21752175
// Taproot structure is erased but key order preserved..
21762176
let desc = Descriptor::<String>::from_str("tr(ROOT,{pk(A1),{pk(B1),pk(B2)}})").unwrap();
21772177
let lift = desc.lift().unwrap();
2178-
assert_eq!(lift.to_string(), "or(pk(ROOT),or(pk(A1),pk(B1),pk(B2)))",);
2178+
assert_eq!(lift.to_string(), "(pk(ROOT)(pk(A1)pk(B1)pk(B2)))");
21792179
let desc = Descriptor::<String>::from_str("tr(ROOT,{{pk(A1),pk(B1)},pk(B2)})").unwrap();
21802180
let lift = desc.lift().unwrap();
2181-
assert_eq!(lift.to_string(), "or(pk(ROOT),or(pk(A1),pk(B1),pk(B2)))",);
2181+
assert_eq!(lift.to_string(), "(pk(ROOT)(pk(A1)pk(B1)pk(B2)))");
21822182

21832183
// And normalization happens
21842184
let desc = Descriptor::<String>::from_str("tr(ROOT,{0,{0,0}})").unwrap();
21852185
let lift = desc.lift().unwrap();
2186-
assert_eq!(lift.to_string(), "or(pk(ROOT),UNSATISFIABLE)",);
2186+
assert_eq!(lift.to_string(), "(pk(ROOT)UNSATISFIABLE)");
21872187
}
21882188

21892189
#[test]

src/policy/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ mod tests {
280280
concrete_policy_rtt("and(pk(X),or(99@pk(Y),1@older(12960)))");
281281

282282
semantic_policy_rtt("pk()");
283-
semantic_policy_rtt("or(pk(X),pk(Y))");
284-
semantic_policy_rtt("and(pk(X),pk(Y))");
283+
semantic_policy_rtt("(pk(X)pk(Y))");
284+
semantic_policy_rtt("(pk(X)pk(Y))");
285285

286286
//fuzzer crashes
287287
assert!(ConcretePol::from_str("thresh()").is_err());

0 commit comments

Comments
 (0)