-
Notifications
You must be signed in to change notification settings - Fork 36.6k
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
Tests: enforce critical class instance attributes in functional tests, fix segwit test specificity #14305
Tests: enforce critical class instance attributes in functional tests, fix segwit test specificity #14305
Conversation
bb803fe
to
965c8ff
Compare
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. |
What an excellent first-time contribution! Thanks! This is my favourite type of contribution: it not only fixes current code but also fixes future code by introducing a mechanism that helps us avoid introducing new instances of the same class of issue. Exactly the type of contribution that I was referring to in #14217 (comment):
In addition to the above: utACK 965c8ff9c7539719eb36bd46297358e33b571766 |
Concept ACK. There's some suggestion in this thread: https://stackoverflow.com/questions/472000/usage-of-slots that using |
test/functional/p2p_segwit.py
Outdated
@@ -771,8 +771,8 @@ def test_p2sh_witness(self): | |||
# segwit-aware would also reject this for failing CLEANSTACK. | |||
test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False) |
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.
Would be nice to demonstrate that this fails due to the correct reason: "non-mandatory-script-verify-flag (Witness program was passed an empty witness)"
You can achieve this with the assert_debug_log
helper.
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.
I agree. Thanks for the tip on assert_debug_log. I'm more familiar with Python than I am of the test suite. Addressed in a new commit.
test/functional/p2p_segwit.py
Outdated
# Try to put the witness script in the script_sig, should also fail. | ||
spend_tx.vin[0].script_sig = CScript([p2wsh_pubkey, b'a']) | ||
# Try to put the witness script in the scriptSig, should also fail. | ||
spend_tx.vin[0].scriptSig = CScript([p2wsh_pubkey, b'a']) | ||
spend_tx.rehash() | ||
test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False) |
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: The reject reason is just the same as above, whereas it now should be "mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)"
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.
Addressed in a new commit.
Concept ACK. I guess this could also be implemented with a "frozen" decorator, which freezes the attributes after It worries me that the tests just pass with or without this fix, which doesn't add much value to the fix. Would you mind changing the tests itself, such that they would fail without, but pass with the change. (See inline comments) |
You are my hero of the day. I am python ignorant, and so I'm only concept ACKing because (1) I've run into this problem before and been frustrated, (2) I see people who know the tests better haven't opposed it, and (3) I asked for someone to fix this. :P |
I'm not opposed to moving to that at some point. Using Added some checks for specific transaction acceptance failures in the debug log per @MarcoFalke's suggestion. Now at least the scriptSig typo would have caused a failure. Thanks for the feedback, @MarcoFalke @gmaxwell and @practicalswift. |
@MarcoFalke I've created an alternate implementation that uses a freezing decorator as you've suggested: If the new implementation is preferred across the board, I can replace this PR's commits with the alternate ones. For what it's worth, I prefer |
Concept ACK. Will try to learn how |
Concept ACK, +1 |
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.
I slightly prefer the decorator for its brevity when used and thus easy reusability. We don't care about performance improvements if they are not significant or can not be measured.
Though, if slots are the commonly the preferred thing, I am fine with that.
test/functional/p2p_segwit.py
Outdated
spend_tx.rehash() | ||
test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False) | ||
with self.nodes[0].assert_debug_log(expected_msgs=('Not relaying invalid transaction {}'.format(spend_tx.hash), 'mandatory-script-verify-flag-failed')): |
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: Could use the full error message here?
'was not accepted: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)'
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.
Reasonable, will adjust commit.
test/functional/p2p_segwit.py
Outdated
@@ -769,12 +769,14 @@ def test_p2sh_witness(self): | |||
# will require a witness to spend a witness program regardless of | |||
# segwit activation. Note that older bitcoind's that are not | |||
# segwit-aware would also reject this for failing CLEANSTACK. | |||
test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False) | |||
with self.nodes[0].assert_debug_log(expected_msgs=(spend_tx.hash, 'was not accepted: non-mandatory-script-verify-flag')): |
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: Could use the full error message here?
'was not accepted: non-mandatory-script-verify-flag (Witness program was passed an empty witness)'
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.
Reasonable, will adjust commit.
Concept ACK either approach. I slightly prefer the |
Ok, let's keep the slots then. |
Agree with @jnewbery – the explicitness of From the Zen of Python:
:-) |
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.
ACK
Nice use of the slots feature! I would like to see something instructing new devs in the Python testing documentation (functional/README.md) so people don't trip over it.
Additionally, removed redundant parentheses and added PEP-8 compliant spacing around those classes.
Per @jimmysong's suggestion in bitcoin#14305. Also corrects module for network objects and wrappers.
35c9a46
to
e460232
Compare
Revised commits to incorporate code comment suggestions from @MarcoFalke and @jimmysong. |
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 the changes!
ACK
utACK e460232 |
utACK e460232 |
…nctional tests, fix segwit test specificity e460232 Document fixed attribute behavior in critical test framework classes. (Justin Turner Arthur) 17b42f4 Check for specific tx acceptance failures based on script signature (Justin Turner Arthur) 3a4449e Strictly enforce instance attrs in critical functional test classes. (Justin Turner Arthur) 1d0ce94 Fix for incorrect version attr set on functional test segwit block. (Justin Turner Arthur) ba923e3 test: Fix broken segwit test (practicalswift) Pull request description: No extra attributes will be able to be added to instances of the C++ class ports or of other critical classes without causing an exception. Helps prevent adding or depending on attributes that aren't in the intended object structure. It may prevent issues such as the one fixed in #14300. This request fixes the erroneous version attribute used in the p2p_segwit.py functional tests. This pull includes the commit from #14300. Tree-SHA512: 1b8c58e7aa0f71075ed5ff3e5be0a5182599108d8cd9bce682feac3b1842508124288e9335432b16a43f40f159c9710899e6d84af1b5868f48c947bc6f3e07ec
Per @jimmysong's suggestion in bitcoin/bitcoin#14305. Also corrects module for network objects and wrappers.
Per @jimmysong's suggestion in bitcoin#14305. Also corrects module for network objects and wrappers.
Per @jimmysong's suggestion in bitcoin#14305. Also corrects module for network objects and wrappers.
…es in functional tests, fix segwit test specificity e460232 Document fixed attribute behavior in critical test framework classes. (Justin Turner Arthur) 17b42f4 Check for specific tx acceptance failures based on script signature (Justin Turner Arthur) 3a4449e Strictly enforce instance attrs in critical functional test classes. (Justin Turner Arthur) 1d0ce94 Fix for incorrect version attr set on functional test segwit block. (Justin Turner Arthur) ba923e3 test: Fix broken segwit test (practicalswift) Pull request description: No extra attributes will be able to be added to instances of the C++ class ports or of other critical classes without causing an exception. Helps prevent adding or depending on attributes that aren't in the intended object structure. It may prevent issues such as the one fixed in bitcoin#14300. This request fixes the erroneous version attribute used in the p2p_segwit.py functional tests. This pull includes the commit from bitcoin#14300. Tree-SHA512: 1b8c58e7aa0f71075ed5ff3e5be0a5182599108d8cd9bce682feac3b1842508124288e9335432b16a43f40f159c9710899e6d84af1b5868f48c947bc6f3e07ec
…es in functional tests, fix segwit test specificity e460232 Document fixed attribute behavior in critical test framework classes. (Justin Turner Arthur) 17b42f4 Check for specific tx acceptance failures based on script signature (Justin Turner Arthur) 3a4449e Strictly enforce instance attrs in critical functional test classes. (Justin Turner Arthur) 1d0ce94 Fix for incorrect version attr set on functional test segwit block. (Justin Turner Arthur) ba923e3 test: Fix broken segwit test (practicalswift) Pull request description: No extra attributes will be able to be added to instances of the C++ class ports or of other critical classes without causing an exception. Helps prevent adding or depending on attributes that aren't in the intended object structure. It may prevent issues such as the one fixed in bitcoin#14300. This request fixes the erroneous version attribute used in the p2p_segwit.py functional tests. This pull includes the commit from bitcoin#14300. Tree-SHA512: 1b8c58e7aa0f71075ed5ff3e5be0a5182599108d8cd9bce682feac3b1842508124288e9335432b16a43f40f159c9710899e6d84af1b5868f48c947bc6f3e07ec
…s in functional tests, fix segwit test specificity e460232 Document fixed attribute behavior in critical test framework classes. (Justin Turner Arthur) 17b42f4 Check for specific tx acceptance failures based on script signature (Justin Turner Arthur) 3a4449e Strictly enforce instance attrs in critical functional test classes. (Justin Turner Arthur) 1d0ce94 Fix for incorrect version attr set on functional test segwit block. (Justin Turner Arthur) ba923e3 test: Fix broken segwit test (practicalswift) Pull request description: No extra attributes will be able to be added to instances of the C++ class ports or of other critical classes without causing an exception. Helps prevent adding or depending on attributes that aren't in the intended object structure. It may prevent issues such as the one fixed in bitcoin#14300. This request fixes the erroneous version attribute used in the p2p_segwit.py functional tests. This pull includes the commit from bitcoin#14300. Tree-SHA512: 1b8c58e7aa0f71075ed5ff3e5be0a5182599108d8cd9bce682feac3b1842508124288e9335432b16a43f40f159c9710899e6d84af1b5868f48c947bc6f3e07ec
…s in functional tests, fix segwit test specificity e460232 Document fixed attribute behavior in critical test framework classes. (Justin Turner Arthur) 17b42f4 Check for specific tx acceptance failures based on script signature (Justin Turner Arthur) 3a4449e Strictly enforce instance attrs in critical functional test classes. (Justin Turner Arthur) 1d0ce94 Fix for incorrect version attr set on functional test segwit block. (Justin Turner Arthur) ba923e3 test: Fix broken segwit test (practicalswift) Pull request description: No extra attributes will be able to be added to instances of the C++ class ports or of other critical classes without causing an exception. Helps prevent adding or depending on attributes that aren't in the intended object structure. It may prevent issues such as the one fixed in bitcoin#14300. This request fixes the erroneous version attribute used in the p2p_segwit.py functional tests. This pull includes the commit from bitcoin#14300. Tree-SHA512: 1b8c58e7aa0f71075ed5ff3e5be0a5182599108d8cd9bce682feac3b1842508124288e9335432b16a43f40f159c9710899e6d84af1b5868f48c947bc6f3e07ec
…s in functional tests, fix segwit test specificity e460232 Document fixed attribute behavior in critical test framework classes. (Justin Turner Arthur) 17b42f4 Check for specific tx acceptance failures based on script signature (Justin Turner Arthur) 3a4449e Strictly enforce instance attrs in critical functional test classes. (Justin Turner Arthur) 1d0ce94 Fix for incorrect version attr set on functional test segwit block. (Justin Turner Arthur) ba923e3 test: Fix broken segwit test (practicalswift) Pull request description: No extra attributes will be able to be added to instances of the C++ class ports or of other critical classes without causing an exception. Helps prevent adding or depending on attributes that aren't in the intended object structure. It may prevent issues such as the one fixed in bitcoin#14300. This request fixes the erroneous version attribute used in the p2p_segwit.py functional tests. This pull includes the commit from bitcoin#14300. Tree-SHA512: 1b8c58e7aa0f71075ed5ff3e5be0a5182599108d8cd9bce682feac3b1842508124288e9335432b16a43f40f159c9710899e6d84af1b5868f48c947bc6f3e07ec
No extra attributes will be able to be added to instances of the C++ class ports or of other critical classes without causing an exception. Helps prevent adding or depending on attributes that aren't in the intended object structure. It may prevent issues such as the one fixed in #14300.
This request fixes the erroneous version attribute used in the p2p_segwit.py functional tests. This pull includes the commit from #14300.