-
Notifications
You must be signed in to change notification settings - Fork 38.7k
test: add invalid tx templates for use in functional tests #14457
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
53cd753 to
1483640
Compare
|
Excellent! Thanks for doing this Concept ACK |
|
Concept ACK! And looking the code LGTM. IMO there is no need to be comprehensive. |
jimmysong
left a comment
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.
A couple of nits, but overall, very solid PR. Thanks!
test/functional/feature_block.py
Outdated
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: put these one per line so diffs are easier to see later.
test/functional/data/invalid_txs.py
Outdated
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.
Since this is a new file you might want to run it file through black to get PEP-8 formatting. Including fixing this case of too many blank lines :-)
test/functional/data/invalid_txs.py
Outdated
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.
Should be "construction" :-)
c0ea4ad to
74306a5
Compare
|
Addressed @practicalswift @jimmysong feedback. Thanks for the looks. |
|
Concept ACK |
|
Neat! utACK 74306a55a5fd15ed194d8addb50cb55a849f293c |
maflcko
left a comment
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.
Concept ACK
74306a5 to
428c144
Compare
|
Addressed @MarcoFalke's feedback. |
conscott
left a comment
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 428c144fc3acc02d36cb0e01dd631d39f0e9a00c
Nice! I guess the follow up is to also use these in the mempool_accept.py test, possibly adding bad-txns-vout-toolarge, bad-txns-txouttotal-toolarge
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 428c144fc3acc02d36cb0e01dd631d39f0e9a00c, with caveat that I didn't really take time to understand changes to feature_block.py, though they seem reasonable. The new module and changes to p2p_invalid_tx.py look good.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
maflcko
left a comment
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.
Concept ACK 428c144fc3acc02d36cb0e01dd631d39f0e9a00c
57c6e5b to
e45f4a8
Compare
|
travis fails :( |
|
@MarcoFalke Thanks for the ping! @jamesob |
Add templates for easily constructing different kinds of invalid transactions and use them in feature_block and p2p_invalid_tx.
e45f4a8 to
59e3877
Compare
|
@practicalswift thanks for the advice. I've excluded the whole |
| # Something about the serialization code for missing inputs creates | ||
| # a different hash in the test client than on bitcoind, resulting | ||
| # in a mismatching merkle root during block validation. | ||
| # Skip until we figure out what's going on. |
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.
missing inputs means the vin is empty and is thus interpreted as the witness dummy vin?
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.
See:
tx as sent: CTransaction(nVersion=1 vin=[] vout=[CTxOut(nValue=0.00000000 scriptPubKey=51515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151515151)] wit=CTxWitness() nLockTime=0)
tx as received: CTransaction(nVersion=1 vin=[] vout=[] wit=CTxWitness() nLockTime=0)
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.
One solution would be:
diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py
index 697a0b19ac..edbdcf2d55 100755
--- a/test/functional/feature_block.py
+++ b/test/functional/feature_block.py
@@ -137,12 +137,6 @@ class FullBlockTest(BitcoinTestFramework):
for TxTemplate in invalid_txs.iter_all_templates():
template = TxTemplate(spend_tx=attempt_spend_tx)
- # Something about the serialization code for missing inputs creates
- # a different hash in the test client than on bitcoind, resulting
- # in a mismatching merkle root during block validation.
- # Skip until we figure out what's going on.
- if TxTemplate == invalid_txs.InputMissing:
- continue
if template.valid_in_block:
continue
@@ -150,7 +144,10 @@ class FullBlockTest(BitcoinTestFramework):
blockname = "for_invalid.%s" % TxTemplate.__name__
badblock = self.next_block(blockname)
badtx = template.get_tx()
- self.sign_tx(badtx, attempt_spend_tx)
+ if TxTemplate != invalid_txs.InputMissing:
+ self.sign_tx(badtx, attempt_spend_tx)
+ else:
+ badtx.vout = [] # Also set outputs empty, so we can calculate the correct hash
badtx.rehash()
badblock = self.update_block(blockname, [badtx])
self.sync_blocks(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 59e3877. Changes since last review: rebase, minor tweaks, variable, renames, dead code linter update.
|
utACK 59e3877 |
59e3877 test: add invalid tx templates for use in functional tests (James O'Beirne) Pull request description: This change adds a list of `CTransaction`-generating templates which each correspond to a specific type of invalid transaction. We then use this list to test for a wider variety of invalid tx types in `p2p_invalid_tx.py` and `feature_block.py`. Consolidating all invalid tx types will allow us to more easily cover all tx reject cases from a variety of tests without repeating ourselves. Validation logic doesn't differ much between mempool and block acceptance, but there *is* a difference and we should be sure we're testing both comprehensively. Right now, I've only added templates covering the tx reject types listed below but if this approach seems worthwhile I will expand the list to be fully comprehensive. ``` bad-txns-in-belowout bad-txns-inputs-duplicate bad-txns-too-many-sigops bad-txns-vin-empty bad-txns-vout-empty bad-txns-vout-negative ``` Tree-SHA512: 05407f4a953fbd7c44c08bb49bb989cefd39a2b05ea00f5b3c92197a3f05e1b302f789e33832445734220e1c333d133aba385740b77b84139b170c583471ce20
This change adds a list of
CTransaction-generating templates which each correspond to a specific type of invalid transaction. We then use this list to test for a wider variety of invalid tx types inp2p_invalid_tx.pyandfeature_block.py.Consolidating all invalid tx types will allow us to more easily cover all tx reject cases from a variety of tests without repeating ourselves. Validation logic doesn't differ much between mempool and block acceptance, but there is a difference and we should be sure we're testing both comprehensively.
Right now, I've only added templates covering the tx reject types listed below but if this approach seems worthwhile I will expand the list to be fully comprehensive.