mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-23 02:56:14 +02:00
Merge bitcoin/bitcoin#32591: test: fix and augment block tests of invalid_txs
8fcd684505
test: ensure reason is checked for invalid blocks rejection (Greg Sanders)1a689a2c88
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 https://github.com/bitcoin/bitcoin/pull/32533 ACKs for top commit: maflcko: review ACK8fcd684505
🔶 theStack: ACK8fcd684505
BrandonOdiwuor: Code Review ACK8fcd684505
TheCharlatan: ACK8fcd684505
Tree-SHA512: 7e79ea35b64f56b29811b29df5752945cb10ec62465b385be5e4e2d295c3237b15d5dacf9e99661346967e84899da6fc82e3d2bd0ef6e5c51da85247da31e26a
This commit is contained in:
@@ -138,6 +138,8 @@ class BadInputOutpointIndex(BadTxTemplate):
|
|||||||
# Won't be rejected - nonexistent outpoint index is treated as an orphan since the coins
|
# Won't be rejected - nonexistent outpoint index is treated as an orphan since the coins
|
||||||
# database can't distinguish between spent outpoints and outpoints which never existed.
|
# database can't distinguish between spent outpoints and outpoints which never existed.
|
||||||
reject_reason = None
|
reject_reason = None
|
||||||
|
# But fails in block
|
||||||
|
block_reject_reason = "bad-txns-inputs-missingorspent"
|
||||||
expect_disconnect = False
|
expect_disconnect = False
|
||||||
|
|
||||||
def get_tx(self):
|
def get_tx(self):
|
||||||
@@ -180,6 +182,8 @@ class PrevoutNullInput(BadTxTemplate):
|
|||||||
class NonexistentInput(BadTxTemplate):
|
class NonexistentInput(BadTxTemplate):
|
||||||
reject_reason = None # Added as an orphan tx.
|
reject_reason = None # Added as an orphan tx.
|
||||||
expect_disconnect = False
|
expect_disconnect = False
|
||||||
|
# But fails in block
|
||||||
|
block_reject_reason = "bad-txns-inputs-missingorspent"
|
||||||
|
|
||||||
def get_tx(self):
|
def get_tx(self):
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
@@ -229,7 +233,6 @@ class CreateSumTooLarge(BadTxTemplate):
|
|||||||
class InvalidOPIFConstruction(BadTxTemplate):
|
class InvalidOPIFConstruction(BadTxTemplate):
|
||||||
reject_reason = "mandatory-script-verify-flag-failed (Invalid OP_IF construction)"
|
reject_reason = "mandatory-script-verify-flag-failed (Invalid OP_IF construction)"
|
||||||
expect_disconnect = True
|
expect_disconnect = True
|
||||||
valid_in_block = True
|
|
||||||
|
|
||||||
def get_tx(self):
|
def get_tx(self):
|
||||||
return create_tx_with_script(
|
return create_tx_with_script(
|
||||||
@@ -278,7 +281,7 @@ def getDisabledOpcodeTemplate(opcode):
|
|||||||
'reject_reason': "disabled opcode",
|
'reject_reason': "disabled opcode",
|
||||||
'expect_disconnect': True,
|
'expect_disconnect': True,
|
||||||
'get_tx': get_tx,
|
'get_tx': get_tx,
|
||||||
'valid_in_block' : True
|
'valid_in_block' : False
|
||||||
})
|
})
|
||||||
|
|
||||||
class NonStandardAndInvalid(BadTxTemplate):
|
class NonStandardAndInvalid(BadTxTemplate):
|
||||||
|
@@ -153,9 +153,16 @@ class FullBlockTest(BitcoinTestFramework):
|
|||||||
for TxTemplate in invalid_txs.iter_all_templates():
|
for TxTemplate in invalid_txs.iter_all_templates():
|
||||||
template = TxTemplate(spend_tx=attempt_spend_tx)
|
template = TxTemplate(spend_tx=attempt_spend_tx)
|
||||||
|
|
||||||
|
# belt-and-suspenders checking we won't pass up validating something
|
||||||
|
# we expect a disconnect from
|
||||||
|
if template.expect_disconnect:
|
||||||
|
assert not template.valid_in_block
|
||||||
|
|
||||||
if template.valid_in_block:
|
if template.valid_in_block:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
assert template.block_reject_reason or template.reject_reason
|
||||||
|
|
||||||
self.log.info(f"Reject block with invalid tx: {TxTemplate.__name__}")
|
self.log.info(f"Reject block with invalid tx: {TxTemplate.__name__}")
|
||||||
blockname = f"for_invalid.{TxTemplate.__name__}"
|
blockname = f"for_invalid.{TxTemplate.__name__}"
|
||||||
self.next_block(blockname)
|
self.next_block(blockname)
|
||||||
|
Reference in New Issue
Block a user