@@ -52,32 +52,46 @@ def run_test(self):
52
52
# 3. Indirect (coinbase and child both in chain) : spend_103 and spend_103_1
53
53
# Use invalidatblock to make all of the above coinbase spends invalid (immature coinbase),
54
54
# 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 ) ]
56
56
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 )
60
68
61
69
# Broadcast and mine spend_102 and 103:
62
70
spend_102_id = self .nodes [0 ].sendrawtransaction (spend_102_raw )
63
71
spend_103_id = self .nodes [0 ].sendrawtransaction (spend_103_raw )
64
72
self .nodes [0 ].generate (1 )
73
+ assert_raises (JSONRPCException , self .nodes [0 ].sendrawtransaction , timelock_tx )
65
74
66
75
# Create 102_1 and 103_1:
67
76
spend_102_1_raw = self .create_tx (spend_102_id , node1_address , 50 )
68
77
spend_103_1_raw = self .create_tx (spend_103_id , node1_address , 50 )
69
78
70
79
# Broadcast and mine 103_1:
71
80
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 )
73
83
74
84
# ... now put spend_101 and spend_102_1 in memory pools:
75
85
spend_101_id = self .nodes [0 ].sendrawtransaction (spend_101_raw )
76
86
spend_102_1_id = self .nodes [0 ].sendrawtransaction (spend_102_1_raw )
77
87
78
88
self .sync_all ()
79
89
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 ]))
81
95
82
96
# Use invalidateblock to re-org back and make all those coinbase spends
83
97
# immature/invalid:
0 commit comments