From 1a689a2c88715c583da6d88cac3f77bdbaeaf551 Mon Sep 17 00:00:00 2001 From: Greg Sanders Date: Thu, 22 May 2025 10:30:13 -0400 Subject: [PATCH 1/2] test: fix block tests of invalid_txs --- test/functional/data/invalid_txs.py | 3 +-- test/functional/feature_block.py | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/functional/data/invalid_txs.py b/test/functional/data/invalid_txs.py index d2d7202d860..4157866dd19 100644 --- a/test/functional/data/invalid_txs.py +++ b/test/functional/data/invalid_txs.py @@ -225,7 +225,6 @@ class CreateSumTooLarge(BadTxTemplate): class InvalidOPIFConstruction(BadTxTemplate): reject_reason = "mandatory-script-verify-flag-failed (Invalid OP_IF construction)" expect_disconnect = True - valid_in_block = True def get_tx(self): return create_tx_with_script( @@ -260,7 +259,7 @@ def getDisabledOpcodeTemplate(opcode): 'reject_reason': "disabled opcode", 'expect_disconnect': True, 'get_tx': get_tx, - 'valid_in_block' : True + 'valid_in_block' : False }) class NonStandardAndInvalid(BadTxTemplate): diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index f4f15d293ec..8f4cca22100 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -153,6 +153,11 @@ class FullBlockTest(BitcoinTestFramework): for TxTemplate in invalid_txs.iter_all_templates(): 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: continue From 8fcd6845052354fad80ae7e5feda3f6a2e441e12 Mon Sep 17 00:00:00 2001 From: Greg Sanders Date: Thu, 22 May 2025 10:43:44 -0400 Subject: [PATCH 2/2] test: ensure reason is checked for invalid blocks rejection --- test/functional/data/invalid_txs.py | 4 ++++ test/functional/feature_block.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/test/functional/data/invalid_txs.py b/test/functional/data/invalid_txs.py index 4157866dd19..e2c9354b739 100644 --- a/test/functional/data/invalid_txs.py +++ b/test/functional/data/invalid_txs.py @@ -134,6 +134,8 @@ class BadInputOutpointIndex(BadTxTemplate): # 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. reject_reason = None + # But fails in block + block_reject_reason = "bad-txns-inputs-missingorspent" expect_disconnect = False def get_tx(self): @@ -176,6 +178,8 @@ class PrevoutNullInput(BadTxTemplate): class NonexistentInput(BadTxTemplate): reject_reason = None # Added as an orphan tx. expect_disconnect = False + # But fails in block + block_reject_reason = "bad-txns-inputs-missingorspent" def get_tx(self): tx = CTransaction() diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index 8f4cca22100..b5767217f44 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -161,6 +161,8 @@ class FullBlockTest(BitcoinTestFramework): if template.valid_in_block: continue + assert template.block_reject_reason or template.reject_reason + self.log.info(f"Reject block with invalid tx: {TxTemplate.__name__}") blockname = f"for_invalid.{TxTemplate.__name__}" self.next_block(blockname)