Skip to content

Commit 219d2c7

Browse files
committed
contrib: testgen: use base58 methods from test framework
1 parent 605fecf commit 219d2c7

File tree

2 files changed

+10
-121
lines changed

2 files changed

+10
-121
lines changed

contrib/testgen/base58.py

Lines changed: 0 additions & 115 deletions
This file was deleted.

contrib/testgen/gen_key_io_test_vectors.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
./gen_key_io_test_vectors.py invalid 70 > ../../src/test/data/key_io_invalid.json
1111
'''
1212

13-
import os
1413
from itertools import islice
15-
from base58 import b58encode_chk, b58decode_chk, b58chars
14+
import os
1615
import random
1716
import sys
1817

1918
sys.path.append(os.path.join(os.path.dirname(__file__), '../../test/functional'))
2019

20+
from test_framework.address import base58_to_byte, byte_to_base58, b58chars # noqa: E402
2121
from test_framework.script import OP_0, OP_1, OP_2, OP_3, OP_16, OP_DUP, OP_EQUAL, OP_EQUALVERIFY, OP_HASH160, OP_CHECKSIG # noqa: E402
2222
from test_framework.segwit_addr import bech32_encode, decode_segwit_address, convertbits, CHARSET, Encoding # noqa: E402
2323

@@ -108,8 +108,10 @@ def is_valid(v):
108108
'''Check vector v for validity'''
109109
if len(set(v) - set(b58chars)) > 0:
110110
return is_valid_bech32(v)
111-
result = b58decode_chk(v)
112-
if result is None:
111+
try:
112+
payload, version = base58_to_byte(v)
113+
result = bytes([version]) + payload
114+
except AssertionError: # thrown if checksum doesn't match
113115
return is_valid_bech32(v)
114116
for template in templates:
115117
prefix = bytearray(template[0])
@@ -133,7 +135,8 @@ def gen_valid_base58_vector(template):
133135
suffix = bytearray(template[2])
134136
dst_prefix = bytearray(template[4])
135137
dst_suffix = bytearray(template[5])
136-
rv = b58encode_chk(prefix + payload + suffix)
138+
assert len(prefix) == 1
139+
rv = byte_to_base58(payload + suffix, prefix[0])
137140
return rv, dst_prefix + payload + dst_suffix
138141

139142
def gen_valid_bech32_vector(template):
@@ -184,7 +187,8 @@ def gen_invalid_base58_vector(template):
184187
else:
185188
suffix = bytearray(template[2])
186189

187-
val = b58encode_chk(prefix + payload + suffix)
190+
assert len(prefix) == 1
191+
val = byte_to_base58(payload + suffix, prefix[0])
188192
if random.randint(0,10)<1: # line corruption
189193
if randbool(): # add random character to end
190194
val += random.choice(b58chars)

0 commit comments

Comments
 (0)