Skip to content

Commit b3527fd

Browse files
committed
Merge #20168: contrib: Fix gen_key_io_test_vectors.py imports
fa68755 contrib: Fix gen_key_io_test_vectors.py imports (MarcoFalke) Pull request description: The script currently fails with ``` Traceback (most recent call last): File "./gen_key_io_test_vectors.py", line 18, in <module> from segwit_addr import bech32_encode, decode, convertbits, CHARSET ImportError: cannot import name 'decode' from 'segwit_addr' ``` Fix that. Also, unrelated cleanup to use the `bytearray.hex()` method instead of importing a library. https://docs.python.org/3.5/library/stdtypes.html#bytes.hex ACKs for top commit: theStack: tested ACK fa68755 Tree-SHA512: 45ff7d710de3d0ef5ac6d91543cff0edff6189d2cd00b0f8889f4361e66ef1825f12aea9e71d62038c14a7a531bfc95ffe9a1df83b85aa7f3dd666df07a6be81
2 parents 9e8d2bd + fa68755 commit b3527fd

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

contrib/testgen/gen_key_io_test_vectors.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
from itertools import islice
1616
from base58 import b58encode_chk, b58decode_chk, b58chars
1717
import random
18-
from binascii import b2a_hex
19-
from segwit_addr import bech32_encode, decode, convertbits, CHARSET
18+
from segwit_addr import bech32_encode, decode_segwit_address, convertbits, CHARSET
2019

2120
# key types
2221
PUBKEY_ADDRESS = 0
@@ -109,7 +108,7 @@ def is_valid(v):
109108
def is_valid_bech32(v):
110109
'''Check vector v for bech32 validity'''
111110
for hrp in ['bc', 'tb', 'bcrt']:
112-
if decode(hrp, v) != (None, None):
111+
if decode_segwit_address(hrp, v) != (None, None):
113112
return True
114113
return False
115114

@@ -141,9 +140,7 @@ def gen_valid_vectors():
141140
rv, payload = valid_vector_generator(template)
142141
assert is_valid(rv)
143142
metadata = {x: y for x, y in zip(metadata_keys,template[3]) if y is not None}
144-
hexrepr = b2a_hex(payload)
145-
if isinstance(hexrepr, bytes):
146-
hexrepr = hexrepr.decode('utf8')
143+
hexrepr = payload.hex()
147144
yield (rv, hexrepr, metadata)
148145

149146
def gen_invalid_base58_vector(template):

0 commit comments

Comments
 (0)