Skip to content

Commit f7cc7f6

Browse files
committed
Merge bitcoin/bitcoin#32591: test: fix and augment block tests of invalid_txs
8fcd684 test: ensure reason is checked for invalid blocks rejection (Greg Sanders) 1a689a2 test: fix block tests of invalid_txs (Greg Sanders) Pull request description: We are not actually testing some cases accidentally, for block inclusion. Issue discovered while reviewing bitcoin/bitcoin#32533 ACKs for top commit: maflcko: review ACK 8fcd684 🔶 theStack: ACK 8fcd684 BrandonOdiwuor: Code Review ACK 8fcd684 TheCharlatan: ACK 8fcd684 Tree-SHA512: 7e79ea35b64f56b29811b29df5752945cb10ec62465b385be5e4e2d295c3237b15d5dacf9e99661346967e84899da6fc82e3d2bd0ef6e5c51da85247da31e26a
2 parents 8786014 + 8fcd684 commit f7cc7f6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

test/functional/data/invalid_txs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class BadInputOutpointIndex(BadTxTemplate):
138138
# Won't be rejected - nonexistent outpoint index is treated as an orphan since the coins
139139
# database can't distinguish between spent outpoints and outpoints which never existed.
140140
reject_reason = None
141+
# But fails in block
142+
block_reject_reason = "bad-txns-inputs-missingorspent"
141143
expect_disconnect = False
142144

143145
def get_tx(self):
@@ -180,6 +182,8 @@ def get_tx(self):
180182
class NonexistentInput(BadTxTemplate):
181183
reject_reason = None # Added as an orphan tx.
182184
expect_disconnect = False
185+
# But fails in block
186+
block_reject_reason = "bad-txns-inputs-missingorspent"
183187

184188
def get_tx(self):
185189
tx = CTransaction()
@@ -229,7 +233,6 @@ def get_tx(self):
229233
class InvalidOPIFConstruction(BadTxTemplate):
230234
reject_reason = "mandatory-script-verify-flag-failed (Invalid OP_IF construction)"
231235
expect_disconnect = True
232-
valid_in_block = True
233236

234237
def get_tx(self):
235238
return create_tx_with_script(
@@ -278,7 +281,7 @@ def get_tx(self):
278281
'reject_reason': "disabled opcode",
279282
'expect_disconnect': True,
280283
'get_tx': get_tx,
281-
'valid_in_block' : True
284+
'valid_in_block' : False
282285
})
283286

284287
class NonStandardAndInvalid(BadTxTemplate):

test/functional/feature_block.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,16 @@ def run_test(self):
153153
for TxTemplate in invalid_txs.iter_all_templates():
154154
template = TxTemplate(spend_tx=attempt_spend_tx)
155155

156+
# belt-and-suspenders checking we won't pass up validating something
157+
# we expect a disconnect from
158+
if template.expect_disconnect:
159+
assert not template.valid_in_block
160+
156161
if template.valid_in_block:
157162
continue
158163

164+
assert template.block_reject_reason or template.reject_reason
165+
159166
self.log.info(f"Reject block with invalid tx: {TxTemplate.__name__}")
160167
blockname = f"for_invalid.{TxTemplate.__name__}"
161168
self.next_block(blockname)

0 commit comments

Comments
 (0)