Skip to content

Commit 0c9959a

Browse files
TheBlueMattsdaftuar
authored andcommitted
Add failing test checking timelocked-txn removal during reorg
1 parent 34e02e0 commit 0c9959a

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
'rawtransactions.py',
7878
'rest.py',
7979
'mempool_spendcoinbase.py',
80-
'mempool_coinbase_spends.py',
80+
'mempool_reorg.py',
8181
'httpbasics.py',
8282
'zapwallettxes.py',
8383
'proxy_test.py',

qa/rpc-tests/mempool_coinbase_spends.py renamed to qa/rpc-tests/mempool_reorg.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,46 @@ def run_test(self):
5252
# 3. Indirect (coinbase and child both in chain) : spend_103 and spend_103_1
5353
# Use invalidatblock to make all of the above coinbase spends invalid (immature coinbase),
5454
# and make sure the mempool code behaves correctly.
55-
b = [ self.nodes[0].getblockhash(n) for n in range(102, 105) ]
55+
b = [ self.nodes[0].getblockhash(n) for n in range(101, 105) ]
5656
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
57-
spend_101_raw = self.create_tx(coinbase_txids[0], node1_address, 50)
58-
spend_102_raw = self.create_tx(coinbase_txids[1], node0_address, 50)
59-
spend_103_raw = self.create_tx(coinbase_txids[2], node0_address, 50)
57+
spend_101_raw = self.create_tx(coinbase_txids[1], node1_address, 50)
58+
spend_102_raw = self.create_tx(coinbase_txids[2], node0_address, 50)
59+
spend_103_raw = self.create_tx(coinbase_txids[3], node0_address, 50)
60+
61+
# Create a block-height-locked transaction which will be invalid after reorg
62+
timelock_tx = self.nodes[0].createrawtransaction([{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 50})
63+
# Set the time lock
64+
timelock_tx = timelock_tx.replace("ffffffff", "11111111", 1)
65+
timelock_tx = timelock_tx[:-8] + hex(self.nodes[0].getblockcount() + 2)[2:] + "000000"
66+
timelock_tx = self.nodes[0].signrawtransaction(timelock_tx)["hex"]
67+
assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, timelock_tx)
6068

6169
# Broadcast and mine spend_102 and 103:
6270
spend_102_id = self.nodes[0].sendrawtransaction(spend_102_raw)
6371
spend_103_id = self.nodes[0].sendrawtransaction(spend_103_raw)
6472
self.nodes[0].generate(1)
73+
assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, timelock_tx)
6574

6675
# Create 102_1 and 103_1:
6776
spend_102_1_raw = self.create_tx(spend_102_id, node1_address, 50)
6877
spend_103_1_raw = self.create_tx(spend_103_id, node1_address, 50)
6978

7079
# Broadcast and mine 103_1:
7180
spend_103_1_id = self.nodes[0].sendrawtransaction(spend_103_1_raw)
72-
self.nodes[0].generate(1)
81+
last_block = self.nodes[0].generate(1)
82+
timelock_tx_id = self.nodes[0].sendrawtransaction(timelock_tx)
7383

7484
# ... now put spend_101 and spend_102_1 in memory pools:
7585
spend_101_id = self.nodes[0].sendrawtransaction(spend_101_raw)
7686
spend_102_1_id = self.nodes[0].sendrawtransaction(spend_102_1_raw)
7787

7888
self.sync_all()
7989

80-
assert_equal(set(self.nodes[0].getrawmempool()), set([ spend_101_id, spend_102_1_id ]))
90+
assert_equal(set(self.nodes[0].getrawmempool()), set([ spend_101_id, spend_102_1_id, timelock_tx_id ]))
91+
92+
for node in self.nodes:
93+
node.invalidateblock(last_block[0])
94+
assert_equal(set(self.nodes[0].getrawmempool()), set([ spend_101_id, spend_102_1_id, spend_103_1_id ]))
8195

8296
# Use invalidateblock to re-org back and make all those coinbase spends
8397
# immature/invalid:

0 commit comments

Comments
 (0)