Skip to content

Commit 3c8aace

Browse files
committed
Merge #712: fix len check in blech32 decode() in test framework
522a147 Add blech32 roundtrip test for python implementation (Gregory Sanders) 32564b0 fix len check in blech32 decode() in test framework (Dmitry Petukhov) Pull request description: I used the code from test/functional/test_framework/liquid_addr.py with the same length check adjustments in python-elementstx to decode Liquid's blech32 addresses, and it seems to be working fine. Tree-SHA512: 4ac4589e0cdbeb7397a4f3c9000b8fdb91516ca257b757cddbfb6df2d75df4587ddcee37b8f9f1d0364d5e78515ea2e1f4270eecca42ea9a59b8f28578d7ab1c
2 parents cfc4cca + 522a147 commit 3c8aace

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

test/functional/feature_confidential_transactions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
import os
2929
import re
3030

31+
from test_framework.liquid_addr import (
32+
encode,
33+
decode,
34+
)
35+
3136
class CTTest (BitcoinTestFramework):
3237

3338
def set_test_params(self):
@@ -104,6 +109,15 @@ def run_test(self):
104109
print("Testing wallet secret recovery")
105110
self.test_wallet_recovery()
106111

112+
print("Test blech32 python roundtrip")
113+
# blech/bech are aliased, both are blech32
114+
for addrtype in ["bech32", "blech32"]:
115+
addr_to_rt = self.nodes[0].getnewaddress("", addrtype)
116+
hrp = addr_to_rt[:2]
117+
assert_equal(hrp, "el")
118+
(witver, witprog) = decode(hrp, addr_to_rt)
119+
assert_equal(encode(hrp, witver, witprog), addr_to_rt)
120+
107121
# Test that "blech32" gives a blinded segwit address.
108122
blech32_addr = self.nodes[0].getnewaddress("", "blech32")
109123
blech32_addr_info = self.nodes[0].getaddressinfo(blech32_addr)

test/functional/test_framework/liquid_addr.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,19 @@ def convertbits(data, frombits, tobits, pad=True):
8484

8585

8686
def decode(hrp, addr):
87-
"""Decode a segwit address."""
87+
"""Decode a segwit confidential address.
88+
Its payload is longer than the payload for unconfidential address
89+
by 33 bytes (the length of blinding pubkey)"""
90+
8891
hrpgot, data = blech32_decode(addr)
8992
if hrpgot != hrp:
9093
return (None, None)
9194
decoded = convertbits(data[1:], 5, 8, False)
92-
if decoded is None or len(decoded) < 2 or len(decoded) > 40:
95+
if decoded is None or len(decoded) < 2 or len(decoded) > 40+33:
9396
return (None, None)
9497
if data[0] > 16:
9598
return (None, None)
96-
if data[0] == 0 and len(decoded) != 20 and len(decoded) != 32:
99+
if data[0] == 0 and len(decoded) != 20+33 and len(decoded) != 32+33:
97100
return (None, None)
98101
return (data[0], decoded)
99102

0 commit comments

Comments
 (0)