test: generalise byte_to_base58 utility function to allow more version types
What changed, and why it matters
This is a small test-only code cleanup. It changes a helper function used only in Bitcoin Core's functional test framework so it can accept a version number either as a single integer or as a sequence of bytes. There is no change to the live Bitcoin network code, no security fix, and no vulnerability.
No security action needed. This is a benign test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies test/functional/test_framework/address.py’s byte_to_base58(). Previously the function prepended a single byte version with bytes([version]). Now it checks whether version is an int and converts it to bytes only in that case, otherwise it treats version as already being bytes. This generalizes the helper for callers that may pass multi-byte version prefixes in a follow-up commit. The change is purely in test framework code.
Changed components
test/functional/test_framework/address.pyInspect captured patch +4 / −2
diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py
index d4aa26e5..7fb6ddf9 100644
--- a/test/functional/test_framework/address.py
+++ b/test/functional/test_framework/address.py
@@ -56,10 +56,12 @@ def create_deterministic_address_bcrt1_p2tr_op_true(explicit_internal_key=None):
def byte_to_base58(b, version):
- result = ''
- b = bytes([version]) + b # prepend version
+ if isinstance(version, int):
+ version = bytes([version])
+ b = version + b # prepend version
b += hash256(b)[:4] # append checksum
value = int.from_bytes(b, 'big')
+ result = ''
while value > 0:
result = b58chars[value % 58] + result
value //= 58
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.