Skip to content

Conversation

@Zero-1729
Copy link
Contributor

@Zero-1729 Zero-1729 commented Aug 3, 2021

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

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, but I am wondering if the member method can be used

@Zero-1729
Copy link
Contributor Author

@MarcoFalke Yeah, it works. It also applies to the change made in test_framework/bdb.py.

I could just switch them to use bytes_obj.hex().encode() as suggested. It shouldn't really affect the consistency of the bytes<->hex conversion as we are just accessing the built-in bytes and then str methods. Plus, it looks cleaner.

@Zero-1729 Zero-1729 force-pushed the test-remove-binascii-in-test-framework branch from ef40833 to 306dad7 Compare August 4, 2021 07:55
@practicalswift
Copy link
Contributor

Concept ACK

@Saviour1001
Copy link

Tested the changes on my end and works correctly.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK
There is one more instance where the hex() member method can be used, see below.

binascii is still used in Python files outside of the test framework, e.g. in contrib and test/util (I didn't think about those in the issue, my bad...). If you want, you can also tackle those in this PR, if not, a follow-up is also okay I guess.

@Zero-1729
Copy link
Contributor Author

binascii is still used in Python files outside of the test framework, e.g. in contrib and test/util (I didn't think about those in the issue, my bad...). If you want, you can also tackle those in this PR, if not, a follow-up is also okay I guess.

Yeah, initially after running git grep binascii I noticed those instances outside of the test/functional and test_framework. I think it would probably be best to handle those in a follow-up. This PR's scope is already explicitly set as changes to the test framework, so a follow-up cleaning the instances outside it might be better.

@Zero-1729 Zero-1729 force-pushed the test-remove-binascii-in-test-framework branch from 306dad7 to 5a1bef6 Compare August 4, 2021 19:05
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-review ACK 5a1bef6 🔢

Checked that all binascii instances are removed and properly replaced within the test framework, also ran the changed tests locally 👌

maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Aug 5, 2021
… hex-string conversion in functional test framework

5a1bef6 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 5a1bef6 🔢

Tree-SHA512: 8f28076cf0580a0d02a156f3e1e94c9badd3d41c3fbdfb2b87cd8a761dde2c94faa5f4c448d6747b1ccc9111c3ef1a1d7b42a11c806b241fa0410b7529e2445f
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 5, 2021

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@maflcko
Copy link
Member

maflcko commented Aug 5, 2021

No idea what is going on with GitHub, this was merged 35 minutes ago: f4328eb

@maflcko maflcko closed this Aug 5, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 5, 2021
maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Aug 21, 2021
…hod calls

021daed refactor: replace remaining binascii method calls (Zero-1729)

Pull request description:

  This PR removes the remaining `binascii` method calls outside `test/functional` and `test_framework`, as pointed out here  bitcoin/bitcoin#22619 (review).

  Follow-up to #22593 and #22619
  Closes #22605

ACKs for top commit:
  josibake:
    re-ACK bitcoin/bitcoin@021daed
  theStack:
    re-ACK 021daed

Tree-SHA512: 2ae9fee8917112c91a5406f219ca70f24cd8902b903db5a61fc2de85ad640d669a772f5c05970be0fcee6ef1cdd32fae2ca5d1ec6dc9798b43352c8160ddde6f
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 7, 2022
Summary:
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.

Also update some code in a  comment in serialize_tests.cpp that was using binascii. This code also needed additional changes to work with python3 (because in python 3 you cannot join `bytes` using a `str` separator).

This is a backport of [[bitcoin/bitcoin#22619 | core#22619]]

Test Plan: `ninja check-functional-extended`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11137
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use consistent bytes <-> hex-string conversions in functional test framework

6 participants