mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
test: throw ValueError
for invalid base58 checksum
This commit is contained in:
parent
219d2c7ee1
commit
65c49ac750
2 changed files with 3 additions and 3 deletions
|
@ -111,7 +111,7 @@ def is_valid(v):
|
||||||
try:
|
try:
|
||||||
payload, version = base58_to_byte(v)
|
payload, version = base58_to_byte(v)
|
||||||
result = bytes([version]) + payload
|
result = bytes([version]) + payload
|
||||||
except AssertionError: # thrown if checksum doesn't match
|
except ValueError: # thrown if checksum doesn't match
|
||||||
return is_valid_bech32(v)
|
return is_valid_bech32(v)
|
||||||
for template in templates:
|
for template in templates:
|
||||||
prefix = bytearray(template[0])
|
prefix = bytearray(template[0])
|
||||||
|
|
|
@ -91,8 +91,8 @@ def base58_to_byte(s):
|
||||||
break
|
break
|
||||||
res = b'\x00' * pad + res
|
res = b'\x00' * pad + res
|
||||||
|
|
||||||
# Assert if the checksum is invalid
|
if hash256(res[:-4])[:4] != res[-4:]:
|
||||||
assert_equal(hash256(res[:-4])[:4], res[-4:])
|
raise ValueError('Invalid Base58Check checksum')
|
||||||
|
|
||||||
return res[1:-4], int(res[0])
|
return res[1:-4], int(res[0])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue