Skip to content

Commit 99beda4

Browse files
author
MarcoFalke
committed
Merge #16864: test: Add python bech32 impl round-trip test
ae0add8 Add python bech32 impl round-trip test (Gregory Sanders) Pull request description: Currently there is a single use of `segwit_addr.encode`, and zero uses of `segwit_addr.decode` in the codebase. This adds a simple round-trip test of the implementation to avoid future regressions. Top commit has no ACKs. Tree-SHA512: feb3303f240f5987993e092ec15b878c8db3957d338db6a08fbe947bbfea0c558c7ebc26f8052c38a69d85c354f24e71431e19e0a2991c3c64b604f6d50697ff
2 parents 318890b + ae0add8 commit 99beda4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/functional/wallet_address_types.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
assert_raises_rpc_error,
6565
connect_nodes_bi,
6666
)
67-
67+
from test_framework.segwit_addr import (
68+
encode,
69+
decode,
70+
)
6871

6972
class AddressTypeTest(BitcoinTestFramework):
7073
def set_test_params(self):
@@ -97,6 +100,13 @@ def get_balances(self, confirmed=True):
97100
else:
98101
return [self.nodes[i].getunconfirmedbalance() for i in range(4)]
99102

103+
# Quick test of python bech32 implementation
104+
def test_python_bech32(self, addr):
105+
hrp = addr[:4]
106+
assert_equal(hrp, "bcrt")
107+
(witver, witprog) = decode(hrp, addr)
108+
assert_equal(encode(hrp, witver, witprog), addr)
109+
100110
def test_address(self, node, address, multisig, typ):
101111
"""Run sanity checks on an address."""
102112
info = self.nodes[node].getaddressinfo(address)
@@ -121,6 +131,7 @@ def test_address(self, node, address, multisig, typ):
121131
assert_equal(info['witness_version'], 0)
122132
assert_equal(len(info['witness_program']), 40)
123133
assert 'pubkey' in info
134+
self.test_python_bech32(info["address"])
124135
elif typ == 'legacy':
125136
# P2SH-multisig
126137
assert info['isscript']
@@ -146,6 +157,7 @@ def test_address(self, node, address, multisig, typ):
146157
assert_equal(info['witness_version'], 0)
147158
assert_equal(len(info['witness_program']), 64)
148159
assert 'pubkeys' in info
160+
self.test_python_bech32(info["address"])
149161
else:
150162
# Unknown type
151163
assert False

0 commit comments

Comments
 (0)