Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_reorg.py
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
timelock_tx = self.nodes[0].createrawtransaction( | timelock_tx = self.nodes[0].createrawtransaction( | ||||
[{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 49.99}) | [{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 49.99}) | ||||
# Set the time lock | # Set the time lock | ||||
timelock_tx = timelock_tx.replace("ffffffff", "11111191", 1) | timelock_tx = timelock_tx.replace("ffffffff", "11111191", 1) | ||||
timelock_tx = timelock_tx[:-8] + \ | timelock_tx = timelock_tx[:-8] + \ | ||||
hex(self.nodes[0].getblockcount() + 2)[2:] + "000000" | hex(self.nodes[0].getblockcount() + 2)[2:] + "000000" | ||||
timelock_tx = self.nodes[0].signrawtransactionwithwallet(timelock_tx)[ | timelock_tx = self.nodes[0].signrawtransactionwithwallet(timelock_tx)[ | ||||
"hex"] | "hex"] | ||||
# This will raise an exception because the timelock transaction is too immature to spend | # This will raise an exception because the timelock transaction is too | ||||
# immature to spend | |||||
assert_raises_rpc_error(-26, "bad-txns-nonfinal", | assert_raises_rpc_error(-26, "bad-txns-nonfinal", | ||||
self.nodes[0].sendrawtransaction, timelock_tx) | self.nodes[0].sendrawtransaction, timelock_tx) | ||||
# Broadcast and mine spend_102 and 103: | # Broadcast and mine spend_102 and 103: | ||||
spend_102_id = self.nodes[0].sendrawtransaction(spend_102_raw) | spend_102_id = self.nodes[0].sendrawtransaction(spend_102_raw) | ||||
spend_103_id = self.nodes[0].sendrawtransaction(spend_103_raw) | spend_103_id = self.nodes[0].sendrawtransaction(spend_103_raw) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
# Time-locked transaction is still too immature to spend | # Time-locked transaction is still too immature to spend | ||||
Show All 19 Lines | def run_test(self): | ||||
self.sync_all() | self.sync_all() | ||||
assert_equal(set(self.nodes[0].getrawmempool()), { | assert_equal(set(self.nodes[0].getrawmempool()), { | ||||
spend_101_id, spend_102_1_id, timelock_tx_id}) | spend_101_id, spend_102_1_id, timelock_tx_id}) | ||||
for node in self.nodes: | for node in self.nodes: | ||||
node.invalidateblock(last_block[0]) | node.invalidateblock(last_block[0]) | ||||
# Time-locked transaction is now too immature and has been removed from the mempool | # Time-locked transaction is now too immature and has been removed from the mempool | ||||
# spend_103_1 has been re-orged out of the chain and is back in the mempool | # spend_103_1 has been re-orged out of the chain and is back in the | ||||
# mempool | |||||
assert_equal(set(self.nodes[0].getrawmempool()), { | assert_equal(set(self.nodes[0].getrawmempool()), { | ||||
spend_101_id, spend_102_1_id, spend_103_1_id}) | spend_101_id, spend_102_1_id, spend_103_1_id}) | ||||
# Use invalidateblock to re-org back and make all those coinbase spends | # Use invalidateblock to re-org back and make all those coinbase spends | ||||
# immature/invalid: | # immature/invalid: | ||||
for node in self.nodes: | for node in self.nodes: | ||||
node.invalidateblock(new_blocks[0]) | node.invalidateblock(new_blocks[0]) | ||||
self.sync_all() | self.sync_all() | ||||
# mempool should be empty. | # mempool should be empty. | ||||
assert_equal(set(self.nodes[0].getrawmempool()), set()) | assert_equal(set(self.nodes[0].getrawmempool()), set()) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
MempoolCoinbaseTest().main() | MempoolCoinbaseTest().main() |