Skip to content

Commit c0a5fce

Browse files
committed
test: Add test for erase orphan tx conflicted by block
1 parent fa45bb2 commit c0a5fce

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/functional/p2p_invalid_tx.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,35 @@ def run_test(self):
193193
with node.assert_debug_log(["Erased 1 orphan tx included or conflicted by block"]):
194194
node.p2ps[0].send_blocks_and_test([block_A], node, success=True)
195195

196+
self.log.info('Test that a transaction in the orphan pool conflicts with a new tip block causes erase this transaction from the orphan pool')
197+
tx_withhold_until_block_B = CTransaction()
198+
tx_withhold_until_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_A.sha256, 1)))
199+
tx_withhold_until_block_B.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
200+
tx_withhold_until_block_B.calc_sha256()
201+
202+
tx_orphan_include_by_block_B = CTransaction()
203+
tx_orphan_include_by_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_B.sha256, 0)))
204+
tx_orphan_include_by_block_B.vout.append(CTxOut(nValue=10 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
205+
tx_orphan_include_by_block_B.calc_sha256()
206+
207+
tx_orphan_conflict_by_block_B = CTransaction()
208+
tx_orphan_conflict_by_block_B.vin.append(CTxIn(outpoint=COutPoint(tx_withhold_until_block_B.sha256, 0)))
209+
tx_orphan_conflict_by_block_B.vout.append(CTxOut(nValue=9 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
210+
tx_orphan_conflict_by_block_B.calc_sha256()
211+
self.log.info('Send the orphan ... ')
212+
node.p2ps[0].send_txs_and_test([tx_orphan_conflict_by_block_B], node, success=False)
213+
214+
tip = int(node.getbestblockhash(), 16)
215+
height = node.getblockcount() + 1
216+
block_B = create_block(tip, create_coinbase(height))
217+
block_B.vtx.extend([tx_withhold_until_block_B, tx_orphan_include_by_block_B])
218+
block_B.hashMerkleRoot = block_B.calc_merkle_root()
219+
block_B.solve()
220+
221+
self.log.info('Send the block that includes a transaction which conflicts with the previous orphan ... ')
222+
with node.assert_debug_log(["Erased 1 orphan tx included or conflicted by block"]):
223+
node.p2ps[0].send_blocks_and_test([block_B], node, success=True)
224+
196225

197226
if __name__ == '__main__':
198227
InvalidTxRequestTest().main()

0 commit comments

Comments
 (0)