-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[Tests] Make p2p_segwit easier to debug #13467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
test/functional/p2p_segwit.py
Outdated
NUM_DROPS = 200 # 201 max ops per script! | ||
NUM_OUTPUTS = 50 | ||
num_drops = 200 # 201 max ops per script! | ||
num_outputs = 50 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo we indicate "compile time" constants with upper case, so I'd prefer if they were left that way, since it makes it easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C.f. https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#coding-style
Constant names are all uppercase, and use _ to separate words.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not fair! Those are C++ style guides.
But fine, reverted to all caps.
CTxIn, | ||
CTxInWitness, | ||
CTxOut, | ||
CTxWitness, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are message types and not from mininode. I'd prefer to keep it the way it was over changing it in the wrong way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out. These were previously being imported indirectly through the from mininode import *
import, but you're right that I should fix that to import from messages.py in this commit.
I've now put them in the right place.
Note to 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. |
Concept ACK, but let's try not to overshoot the target by pleasing some obscure style rules that contradict our style guide. |
Sorry - will address your comments. Was travelling last week. |
1b6730c
to
daad0c4
Compare
Comments addressed. Thanks for the review @MarcoFalke ! |
This re-orders the defintions in p2p_segwit so subtests are defined in the order that they're called.
The subtest wrapper logs the name of the subtest.
daad0c4
to
e3aab29
Compare
rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK e3aab29
Nice cleanup.
As a follow up, what do you think about moving these functions back to mininode.py? It seems there are similiar patterns in other p2p tests, like here, which could be refactored.
Thanks @conscott !
Seems reasonable if they can be used by multiple tests, although blocktools.py might be a better place for them. |
utACK e3aab29 |
e3aab29 [tests] p2p_segwit: sync_blocks in subtest wrapper. (John Newbery) 55e8050 [tests] p2p_segwit: remove unnecessary arguments from subtests. (John Newbery) 25711c2 [tests] p2p_segwit: log and assert segwit status in subtest wrapper. (John Newbery) 6839863 [tests] p2p_segwit: Make sure each subtest leaves utxos for the next. (John Newbery) bfe3273 [tests] p2p_segwit: wrap subtests with subtest wrapper. (John Newbery) 2af4e39 [tests] p2p_segwit: re-order function definitions. (John Newbery) 94a0134 [tests] p2p_segwit: standardise comments/docstrings. (John Newbery) f7c7f8e [tests] p2p_segwit: Fix flake8 warnings. (John Newbery) Pull request description: `p2p_segwit.py` is a very long test, composed of multiple subtests. When it fails it's difficult to debug for a couple of reasons: - Control flow jumps between different methods in the test class, so it's a little difficult to follow the code. - state may be carried forward unintentionally from one subtest to the next. Improve that by wrapping the subtests with a `@subtest` decorator which: - logs progress - asserts state after each subtest As usual, I've also included a few commits which generally tidy up the test and improve style. Tree-SHA512: 3650602b3ce9823dc968cc5f2e716757feadc3dbedb3605eb79bb3df91a6db8ae53431f253b440da690e3a8e9d76de84fad4368a2663aeb40e6b9427cf948870
test/functional/p2p_segwit.py
Outdated
# Verify that future segwit upgraded transactions are non-standard, | ||
# but valid in blocks. Can run this before and after segwit activation. | ||
def test_segwit_versions(self): | ||
self.log.info("Testing standardness/consensus for segwit versions (0-16)") | ||
assert(len(self.utxo)) | ||
NUM_TESTS = 17 # will test OP_0, OP1, ..., OP_16 | ||
if (len(self.utxo) < NUM_TESTS): | ||
num_tests = 17 # will test OP_0, OP1, ..., OP_16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in commit f7c7f8e [tests] p2p_segwit: Fix flake8 warnings
You change a constant to lowercase. Imo this makes the code harder to read, as mentioned in my previous review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry - recapitalized the ones that you mentioned in your review. Missed this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK e3aab29
Excellent addition of the @subtest
wrapper! In the past I used to splatter around those assertions manually.
Left some comments to prove I actually reviewed the individual commits.
# Ensure that we've tested a situation where we use SIGHASH_SINGLE with | ||
# an input index > number of outputs. | ||
NUM_TESTS = 500 | ||
num_tests = 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address in follow-up PR
test/functional/p2p_segwit.py
Outdated
def advance_to_segwit_lockin(self): | ||
"""Mine enough blocks to lock in segwit, but don't activate.""" | ||
# TODO: we could verify that lockin only happens at the right threshold of | ||
# signalling blocks, rather than just at the right period boundary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (unrelated):
In commit 94a0134 [tests] p2p_segwit: standardise comments/docstrings.
Could remove this todo, since it should be covered by the BIP9 tests. (No need to re-cover BIP9 logic in every softfork deployment that uses BIP9)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address in follow-up PR
test/functional/p2p_segwit.py
Outdated
def advance_to_segwit_active(self): | ||
"""Mine enough blocks to activate segwit.""" | ||
# TODO: we could verify that activation only happens at the right threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address in follow-up PR
test/functional/p2p_segwit.py
Outdated
@@ -41,7 +41,6 @@ | |||
from test_framework.mininode import ( | |||
P2PInterface, | |||
mininode_lock, | |||
network_thread_start, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in commit 2af4e39 [tests] p2p_segwit: re-order function definitions.
Unrelated change
test/functional/p2p_segwit.py
Outdated
return | ||
|
||
def run_test(self): | ||
# Setup the p2p connections and start up the network thread. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit 2af4e39 [tests] p2p_segwit: re-order function definitions.
Unrelated addition: Tests are not aware of a "network thread"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address in follow-up PR
@@ -220,7 +218,77 @@ def update_witness_block_with_transactions(self, block, tx_list, nonce=0): | |||
block.vtx.extend(tx_list) | |||
add_witness_commitment(block, nonce) | |||
block.solve() | |||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit 2af4e39 [tests] p2p_segwit: re-order function definitions.
Unrelated non-moveonly removal
test/functional/p2p_segwit.py
Outdated
|
||
def test_standardness_v0(self, segwit_activated): | ||
"""Test V0 txout standardness. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit 2af4e39 [tests] p2p_segwit: re-order function definitions.
Unrelated removal of trailing whitespace (should have been in one of the previous commits)
test/functional/p2p_segwit.py
Outdated
|
||
def test_segwit_versions(self): | ||
"""Test validity of future segwit version transactions. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit 2af4e39 [tests] p2p_segwit: re-order function definitions.
Unrelated removal of trailing whitespace (should have been in one of the previous commits)
Thanks for the review @MarcoFalke - I'll try to address your comments in a follow-up PR. |
eeeef80 qa: Fix some TODOs in p2p_segwit (MarcoFalke) Pull request description: * I believe we don't need to redundantly test versionbits logic in every functional tests that tests a softfork deployment that is being done with versionbits. Thus, remove two `TODO`s that ask for that. * Replace another `TODO` with `wait_until`. * Some style fixups after #13467 Tree-SHA512: c7120404d50579d6f3b9092f1e259959190eeafe520231e3479c8c256a50bf7260ccc93f8301ac0e100c54037053f6849433ebb1c55607e01d94b9812e525083
p2p_segwit.py
is a very long test, composed of multiple subtests. When it fails it's difficult to debug for a couple of reasons:Improve that by wrapping the subtests with a
@subtest
decorator which:As usual, I've also included a few commits which generally tidy up the test and improve style.