diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-08-05 12:14:38 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-08-05 12:15:01 +0200 |
commit | f4328ebef52f51a5ee45cc42815c91ccd28b0669 (patch) | |
tree | c419289605be3219360b66a6ef43081fc1ce25ec /test/functional/test_framework/blocktools.py | |
parent | c4b42aa4ffa1596742135acaa805343675acd7ab (diff) | |
parent | 5a1bef60a03b57de708a1a751bd90b8245fd8b83 (diff) | |
download | bitcoin-f4328ebef52f51a5ee45cc42815c91ccd28b0669.tar.xz |
Merge bitcoin/bitcoin#22619: test: refactor: use consistent bytes <-> hex-string conversion in functional test framework
5a1bef60a03b57de708a1a751bd90b8245fd8b83 test: refactor: remove binascii from test_framework (Zero-1729)
Pull request description:
This PR continues the work started in PR #22593, regarding using the `bytes` built-in module. In this PR specifically, instances of `binascii`'s methods `hexlify`, `unhexlify`, and `a2b_hex` have been replaced with the build-in `bytes` module's `hex` and `fromhex` methods where appropriate to make bytes <-> hex-string conversions consistent across the functional test files and test_framework.
Additionally, certain changes made are based on the following assumption:
```
bytes.hex(data) == binascii.hexlify(data).decode()
bytes.hex(data).encode() == binascii.hexlify(data)
```
Ran the functional tests to ensure behaviour is still consistent and changes didn't break existing tests.
closes #22605
ACKs for top commit:
theStack:
Code-review ACK 5a1bef60a03b57de708a1a751bd90b8245fd8b83 🔢
Tree-SHA512: 8f28076cf0580a0d02a156f3e1e94c9badd3d41c3fbdfb2b87cd8a761dde2c94faa5f4c448d6747b1ccc9111c3ef1a1d7b42a11c806b241fa0410b7529e2445f
Diffstat (limited to 'test/functional/test_framework/blocktools.py')
-rw-r--r-- | test/functional/test_framework/blocktools.py | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index a88a119e6f..52ca579b1b 100644 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -4,7 +4,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Utilities for manipulating blocks and transactions.""" -from binascii import a2b_hex import struct import time import unittest @@ -74,7 +73,7 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl block.nTime = ntime or tmpl.get('curtime') or int(time.time() + 600) block.hashPrevBlock = hashprev or int(tmpl['previousblockhash'], 0x10) if tmpl and not tmpl.get('bits') is None: - block.nBits = struct.unpack('>I', a2b_hex(tmpl['bits']))[0] + block.nBits = struct.unpack('>I', bytes.fromhex(tmpl['bits']))[0] else: block.nBits = 0x207fffff # difficulty retargeting is disabled in REGTEST chainparams if coinbase is None: |