mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Merge #16864: test: Add python bech32 impl round-trip test
ae0add8dfe
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
This commit is contained in:
commit
99beda47f5
1 changed files with 13 additions and 1 deletions
|
@ -64,7 +64,10 @@ from test_framework.util import (
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
connect_nodes_bi,
|
connect_nodes_bi,
|
||||||
)
|
)
|
||||||
|
from test_framework.segwit_addr import (
|
||||||
|
encode,
|
||||||
|
decode,
|
||||||
|
)
|
||||||
|
|
||||||
class AddressTypeTest(BitcoinTestFramework):
|
class AddressTypeTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -97,6 +100,13 @@ class AddressTypeTest(BitcoinTestFramework):
|
||||||
else:
|
else:
|
||||||
return [self.nodes[i].getunconfirmedbalance() for i in range(4)]
|
return [self.nodes[i].getunconfirmedbalance() for i in range(4)]
|
||||||
|
|
||||||
|
# Quick test of python bech32 implementation
|
||||||
|
def test_python_bech32(self, addr):
|
||||||
|
hrp = addr[:4]
|
||||||
|
assert_equal(hrp, "bcrt")
|
||||||
|
(witver, witprog) = decode(hrp, addr)
|
||||||
|
assert_equal(encode(hrp, witver, witprog), addr)
|
||||||
|
|
||||||
def test_address(self, node, address, multisig, typ):
|
def test_address(self, node, address, multisig, typ):
|
||||||
"""Run sanity checks on an address."""
|
"""Run sanity checks on an address."""
|
||||||
info = self.nodes[node].getaddressinfo(address)
|
info = self.nodes[node].getaddressinfo(address)
|
||||||
|
@ -121,6 +131,7 @@ class AddressTypeTest(BitcoinTestFramework):
|
||||||
assert_equal(info['witness_version'], 0)
|
assert_equal(info['witness_version'], 0)
|
||||||
assert_equal(len(info['witness_program']), 40)
|
assert_equal(len(info['witness_program']), 40)
|
||||||
assert 'pubkey' in info
|
assert 'pubkey' in info
|
||||||
|
self.test_python_bech32(info["address"])
|
||||||
elif typ == 'legacy':
|
elif typ == 'legacy':
|
||||||
# P2SH-multisig
|
# P2SH-multisig
|
||||||
assert info['isscript']
|
assert info['isscript']
|
||||||
|
@ -146,6 +157,7 @@ class AddressTypeTest(BitcoinTestFramework):
|
||||||
assert_equal(info['witness_version'], 0)
|
assert_equal(info['witness_version'], 0)
|
||||||
assert_equal(len(info['witness_program']), 64)
|
assert_equal(len(info['witness_program']), 64)
|
||||||
assert 'pubkeys' in info
|
assert 'pubkeys' in info
|
||||||
|
self.test_python_bech32(info["address"])
|
||||||
else:
|
else:
|
||||||
# Unknown type
|
# Unknown type
|
||||||
assert False
|
assert False
|
||||||
|
|
Loading…
Add table
Reference in a new issue