Skip to content

Commit df2b5da

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22408: test: add tests for bad-txns-prevout-null reject reason
1f44958 test: add `bad-txns-prevout-null` test to mempool_accept.py (Sebastian Falbesoner) aa0a5bb test: add `bad-txns-prevout-null` test case to invalid_txs.py (Sebastian Falbesoner) Pull request description: This simple PR adds missing tests for the reject reason `bad-txns-prevout-null`, which is thrown in the function `CheckTransaction()`: https://github.com/bitcoin/bitcoin/blob/a62fc35a150da584d39d7cd01ade14bbb5002fb9/src/consensus/tx_check.cpp#L52-L54 Basically this condition is met for non-coinbase transactions (the code snippet above only hits if `!tx.IsCoinBase()`) with coinbase-like outpoints, i.e. hash=0, n=0xffffffff. Can be tested by running the functional tests `feature_block.py`, `p2p_invalid_tx.py` and `mempool_accept.py`. Not sure if the redundancy in the tests is desired (I guess it would make sense if the mempool acceptance test also makes use of the invalid_txs templates?). ACKs for top commit: rajarshimaitra: tACK bitcoin/bitcoin@1f44958 brunoerg: tACK 1f44958 kristapsk: ACK 1f44958, code looks correct and all tests pass. Tree-SHA512: 2d4f940a6ac8e0d80d2670c9e1111cbf43ae6ac62809a2ccf17cffee9a41d387ea4d889ee300eb4a407c055b13bfa5d37102a32ed59964a9b6950bd907ba7204
2 parents d968616 + 1f44958 commit df2b5da

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/functional/data/invalid_txs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ def get_tx(self):
151151
return tx
152152

153153

154+
class PrevoutNullInput(BadTxTemplate):
155+
reject_reason = 'bad-txns-prevout-null'
156+
expect_disconnect = True
157+
158+
def get_tx(self):
159+
tx = CTransaction()
160+
tx.vin.append(self.valid_txin)
161+
tx.vin.append(CTxIn(COutPoint(hash=0, n=0xffffffff)))
162+
tx.vout.append(CTxOut(1, basic_p2sh))
163+
tx.calc_sha256()
164+
return tx
165+
166+
154167
class NonexistentInput(BadTxTemplate):
155168
reject_reason = None # Added as an orphan tx.
156169
expect_disconnect = False

test/functional/mempool_accept.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
BIP125_SEQUENCE_NUMBER,
1414
COIN,
1515
COutPoint,
16+
CTxIn,
1617
CTxOut,
1718
MAX_BLOCK_BASE_SIZE,
1819
MAX_MONEY,
@@ -247,6 +248,14 @@ def run_test(self):
247248
rawtxs=[tx.serialize().hex()],
248249
)
249250

251+
self.log.info('A non-coinbase transaction with coinbase-like outpoint')
252+
tx = tx_from_hex(raw_tx_reference)
253+
tx.vin.append(CTxIn(COutPoint(hash=0, n=0xffffffff)))
254+
self.check_mempool_result(
255+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-prevout-null'}],
256+
rawtxs=[tx.serialize().hex()],
257+
)
258+
250259
self.log.info('A coinbase transaction')
251260
# Pick the input of the first tx we signed, so it has to be a coinbase tx
252261
raw_tx_coinbase_spent = node.getrawtransaction(txid=node.decoderawtransaction(hexstring=raw_tx_in_block)['vin'][0]['txid'])

0 commit comments

Comments
 (0)