From 65c49ac750ba39801b349d0a59c27471dfa9868e Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 5 Apr 2022 20:04:20 +0200 Subject: [PATCH] test: throw `ValueError` for invalid base58 checksum --- contrib/testgen/gen_key_io_test_vectors.py | 2 +- test/functional/test_framework/address.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/testgen/gen_key_io_test_vectors.py b/contrib/testgen/gen_key_io_test_vectors.py index 8017fad461a..4aa7dc200be 100755 --- a/contrib/testgen/gen_key_io_test_vectors.py +++ b/contrib/testgen/gen_key_io_test_vectors.py @@ -111,7 +111,7 @@ def is_valid(v): try: payload, version = base58_to_byte(v) 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) for template in templates: prefix = bytearray(template[0]) diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py index 9ac3f847b79..fcea24655bd 100644 --- a/test/functional/test_framework/address.py +++ b/test/functional/test_framework/address.py @@ -91,8 +91,8 @@ def base58_to_byte(s): break res = b'\x00' * pad + res - # Assert if the checksum is invalid - assert_equal(hash256(res[:-4])[:4], res[-4:]) + if hash256(res[:-4])[:4] != res[-4:]: + raise ValueError('Invalid Base58Check checksum') return res[1:-4], int(res[0])