Skip to content

Commit 1259375

Browse files
committed
miniscript: make display prefer 'u' over 'l' in the fragment l:0
When fuzzing my new non-recursive tree parsing logic, I noticed that we were deviating from the released 12.0 in the way that we display l:0. This is an ambiguous fragment which can be displayed either as l:0 or u:0. In our released code we use u:0 so stick with that. This was unintentially changed as part of #722. Change it back. While we are at it add a regression test for #735
1 parent 67fdc50 commit 1259375

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/descriptor/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,21 @@ mod tests {
10361036
);
10371037
}
10381038

1039+
#[test]
1040+
fn display_prefers_u() {
1041+
// The fragments u:0 and l:0 are identical in terms of Script and
1042+
// in terms of the in-memory representation -- OrI(False, False).
1043+
// Test that the way we display the ambiguous fragment doesn't
1044+
// change, in case somebody somehow is depending on it.
1045+
let desc = StdDescriptor::from_str("sh(u:0)").unwrap();
1046+
assert_eq!("sh(u:0)#ncq3yf9h", desc.to_string());
1047+
1048+
// This is a regression test for https://github.com/rust-bitcoin/rust-miniscript/pull/735
1049+
// which was found at the same time. It's just a bug plain and simple.
1050+
let desc = StdDescriptor::from_str("sh(and_n(u:0,1))").unwrap();
1051+
assert_eq!("sh(and_n(u:0,1))#5j5tw8nm", desc.to_string());
1052+
}
1053+
10391054
#[test]
10401055
fn desc_rtt_tests() {
10411056
roundtrip_descriptor("c:pk_k()");

src/miniscript/display.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
260260
Terminal::ZeroNotEqual(..) => "n",
261261
Terminal::AndV(_, ref r) if matches!(r.as_inner(), Terminal::True) => "t",
262262
Terminal::AndV(..) => "and_v",
263-
Terminal::AndB(..) => "and_b",
264263
Terminal::AndOr(_, _, ref c) if matches!(c.as_inner(), Terminal::False) => "and_n",
264+
Terminal::AndB(..) => "and_b",
265265
Terminal::AndOr(..) => "andor",
266266
Terminal::OrB(..) => "or_b",
267267
Terminal::OrD(..) => "or_d",
268268
Terminal::OrC(..) => "or_c",
269-
Terminal::OrI(ref l, _) if matches!(l.as_inner(), Terminal::False) => "l",
270269
Terminal::OrI(_, ref r) if matches!(r.as_inner(), Terminal::False) => "u",
270+
Terminal::OrI(ref l, _) if matches!(l.as_inner(), Terminal::False) => "l",
271271
Terminal::OrI(..) => "or_i",
272272
Terminal::Thresh(..) => "thresh",
273273
Terminal::Multi(..) => "multi",

0 commit comments

Comments
 (0)