Skip to content

Commit

Permalink
descriptor.py: fix parsing tr() desc with single leaf TREE
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed May 24, 2024
1 parent d774d65 commit 4e8559b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hwilib/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ def _get_expr(s: str) -> Tuple[str, str]:
level -= 1
elif level == 0 and c in [")", "}", ","]:
break
else:
return s, ""
return s[0:i], s[i:]

def parse_pubkey(expr: str) -> Tuple['PubkeyProvider', str]:
Expand Down
10 changes: 10 additions & 0 deletions test/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,15 @@ def test_tr_descriptor(self):
self.assertEqual(desc.depths, [1, 3, 3, 2])
self.assertEqual(desc.to_string_no_checksum(), d)

d = "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,pk(669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0))"
desc = parse_descriptor(d)
self.assertTrue(isinstance(desc, TRDescriptor))
self.assertEqual(len(desc.subdescriptors), 1)
self.assertEqual(desc.pubkeys[0].pubkey, "a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd")
self.assertEqual(desc.depths, [0])
self.assertEqual(desc.subdescriptors[0].pubkeys[0].pubkey, "669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0")
self.assertEqual(desc.to_string_no_checksum(), d)


if __name__ == "__main__":
unittest.main()

0 comments on commit 4e8559b

Please sign in to comment.