Skip to content

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Apr 25, 2020

Many functional tests still use magic numbers for inventory types, either passed to the CInv constructor or for comparing the type member of CInv. This PR replaces all of those by constants in the module test_framework.messages that have been introduced in commit c32cf9f: MSG_TX (1) or MSG_BLOCK (2).

It also introduces a new constant MSG_CMPCT_BLOCK (naming as in src/protocol.h) and uses it to replace the remaining magic numbers.

The occurences of the magic numbers were identified through greping for CInv( and type ==. The idea was first to create a scripted-diff, but since also adding missing imports is needed, this would be non-trivial. Besides, also some unneeded comments like # 2 == "Block" could be removed.

@fanquake fanquake added the Tests label Apr 25, 2020
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 25, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@practicalswift
Copy link
Contributor

Concept ACK

@theStack theStack force-pushed the 20200425-test-replace_inv_types_by_constants branch from 16dc435 to e5d107a Compare April 30, 2020 13:33
@theStack
Copy link
Contributor Author

Rebased.

@brakmic
Copy link
Contributor

brakmic commented May 1, 2020

Code review ACK.

@maflcko
Copy link
Member

maflcko commented May 1, 2020

test/functional/wallet_resendwallettransactions.py:9:1: F401 'test_framework.messages.MSG_TX' imported but unused

@theStack theStack force-pushed the 20200425-test-replace_inv_types_by_constants branch from e5d107a to adb0cc4 Compare May 1, 2020 16:52
@theStack
Copy link
Contributor Author

theStack commented May 1, 2020

test/functional/wallet_resendwallettransactions.py:9:1: F401 'test_framework.messages.MSG_TX' imported but unused

Oops, that apparently happened in the course of rebasing, resolving a merge conflict. Fixed.

Copy link
Member

@glozow glozow 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, and a small question

@theStack theStack force-pushed the 20200425-test-replace_inv_types_by_constants branch from adb0cc4 to 4a614ff Compare May 7, 2020 12:36
@theStack
Copy link
Contributor Author

theStack commented May 7, 2020

Rebased on master and added changes suggested by gzhao408 (explicitely importing from test_framework.messages in p2p_invalid_messages.py).

@glozow
Copy link
Member

glozow commented May 9, 2020

ACK 4a614ff

@maflcko maflcko merged commit 3eda7ea into bitcoin:master May 20, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 20, 2020
…y constants

4a614ff test: explicit imports from test_framework.messages in p2p_invalid_messages.py (Sebastian Falbesoner)
b35e1d2 test: add inventory type constant MSG_CMPCT_BLOCK (Sebastian Falbesoner)
eeaaa58 test: replace inv type magic numbers by constants (Sebastian Falbesoner)

Pull request description:

  Many functional tests still use magic numbers for inventory types, either passed to the `CInv` constructor or for comparing the `type` member of `CInv`. This PR replaces all of those by constants in the module `test_framework.messages` that have been introduced in commit c32cf9f: `MSG_TX` (1) or `MSG_BLOCK` (2).

  It also introduces a new constant `MSG_CMPCT_BLOCK` (naming as in `src/protocol.h`) and uses it to replace the remaining magic numbers.

  The occurences of the magic numbers were identified through `grep`ing for `CInv(` and `type ==`. The idea was first to create a scripted-diff, but since also adding missing `import`s is needed, this would be non-trivial. Besides, also some unneeded comments like `# 2 == "Block"` could be removed.

ACKs for top commit:
  gzhao408:
    ACK [`4a614ff`](bitcoin@4a614ff)

Tree-SHA512: 4ba4fdef9f3eef7fd5ac72cb03ca3524863d1ae292161c550424a4c1047283fa2d2e7e03017d1fbae3652b3cb14f08b8d4b368403f3f209993aef3f2e2b22784
@theStack theStack deleted the 20200425-test-replace_inv_types_by_constants branch December 1, 2020 09:55
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 3, 2021
Summary:
This is a backport of Core [[bitcoin/bitcoin#18764 | PR18764]] [1/3]
bitcoin/bitcoin@eeaaa58

Test Plan: ninja check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9141
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 3, 2021
Summary:
Bitcoin ABC already had such a constant, so this just renames it to use
the same as Core and uses it in p2p_compactblocks.py

This is a backport of Core [[bitcoin/bitcoin#18764 | PR18764]] [2/3]
bitcoin/bitcoin@b35e1d2

Depends on D9141

Test Plan: ninja check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9142
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 3, 2021
…ssages.py

Summary:
This is a backport of Core [[bitcoin/bitcoin#18764 | PR18764]] [3/3]
bitcoin/bitcoin@4a614ff

Depends on D9142

Test Plan: test/functional/test_runner.py p2p_invalid_messages

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9143
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants