From 4e8559b1b8ff07ae4eb8177a3a5e2ba3d8367014 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 24 May 2024 16:16:37 +0000 Subject: [PATCH] descriptor.py: fix parsing tr() desc with single leaf TREE --- hwilib/descriptor.py | 2 ++ test/test_descriptor.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/hwilib/descriptor.py b/hwilib/descriptor.py index 311c78028..4e743fda7 100644 --- a/hwilib/descriptor.py +++ b/hwilib/descriptor.py @@ -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]: diff --git a/test/test_descriptor.py b/test/test_descriptor.py index 4df2c0899..9e281a479 100755 --- a/test/test_descriptor.py +++ b/test/test_descriptor.py @@ -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()