From 605fecfb66ba51467b35a3f269116ec786aedd05 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 15 Mar 2022 23:11:01 +0100 Subject: scripted-diff: rename `chars` to `b58chars` in test_framework.address -BEGIN VERIFY SCRIPT- sed -i 's/chars/b58chars/g' ./test/functional/test_framework/address.py -END VERIFY SCRIPT- --- test/functional/test_framework/address.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/functional/test_framework') diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py index c7fbf679b6..9ac3f847b7 100644 --- a/test/functional/test_framework/address.py +++ b/test/functional/test_framework/address.py @@ -35,7 +35,7 @@ class AddressType(enum.Enum): legacy = 'legacy' # P2PKH -chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' +b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' def create_deterministic_address_bcrt1_p2tr_op_true(): @@ -59,10 +59,10 @@ def byte_to_base58(b, version): b += hash256(b)[:4] # append checksum value = int.from_bytes(b, 'big') while value > 0: - result = chars[value % 58] + result + result = b58chars[value % 58] + result value //= 58 while b[0] == 0: - result = chars[0] + result + result = b58chars[0] + result b = b[1:] return result @@ -76,8 +76,8 @@ def base58_to_byte(s): n = 0 for c in s: n *= 58 - assert c in chars - digit = chars.index(c) + assert c in b58chars + digit = b58chars.index(c) n += digit h = '%x' % n if len(h) % 2: @@ -85,7 +85,7 @@ def base58_to_byte(s): res = n.to_bytes((n.bit_length() + 7) // 8, 'big') pad = 0 for c in s: - if c == chars[0]: + if c == b58chars[0]: pad += 1 else: break -- cgit v1.2.3 From 65c49ac750ba39801b349d0a59c27471dfa9868e Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 5 Apr 2022 20:04:20 +0200 Subject: test: throw `ValueError` for invalid base58 checksum --- test/functional/test_framework/address.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/test_framework') diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py index 9ac3f847b7..fcea24655b 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]) -- cgit v1.2.3