Merge #10859: RPC: gettxout: Slightly improve doc and tests
[bitcoinplatinum.git] / test / functional / mempool_resurrect_test.py
bloba2f6228df91c26238f57f79b7b9ac5e6afd44b54
1 #!/usr/bin/env python3
2 # Copyright (c) 2014-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test resurrection of mined transactions when the blockchain is re-organized."""
7 from test_framework.test_framework import BitcoinTestFramework
8 from test_framework.util import *
10 # Create one-input, one-output, no-fee transaction:
11 class MempoolCoinbaseTest(BitcoinTestFramework):
13 def __init__(self):
14 super().__init__()
15 self.num_nodes = 1
16 self.setup_clean_chain = False
17 # Just need one node for this test
18 self.extra_args = [["-checkmempool"]]
20 def run_test(self):
21 node0_address = self.nodes[0].getnewaddress()
22 # Spend block 1/2/3's coinbase transactions
23 # Mine a block.
24 # Create three more transactions, spending the spends
25 # Mine another block.
26 # ... make sure all the transactions are confirmed
27 # Invalidate both blocks
28 # ... make sure all the transactions are put back in the mempool
29 # Mine a new block
30 # ... make sure all the transactions are confirmed again.
32 b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
33 coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
34 spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
35 spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
37 blocks = []
38 blocks.extend(self.nodes[0].generate(1))
40 spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
41 spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]
43 blocks.extend(self.nodes[0].generate(1))
45 # mempool should be empty, all txns confirmed
46 assert_equal(set(self.nodes[0].getrawmempool()), set())
47 for txid in spends1_id+spends2_id:
48 tx = self.nodes[0].gettransaction(txid)
49 assert(tx["confirmations"] > 0)
51 # Use invalidateblock to re-org back; all transactions should
52 # end up unconfirmed and back in the mempool
53 for node in self.nodes:
54 node.invalidateblock(blocks[0])
56 # mempool should be empty, all txns confirmed
57 assert_equal(set(self.nodes[0].getrawmempool()), set(spends1_id+spends2_id))
58 for txid in spends1_id+spends2_id:
59 tx = self.nodes[0].gettransaction(txid)
60 assert(tx["confirmations"] == 0)
62 # Generate another block, they should all get mined
63 self.nodes[0].generate(1)
64 # mempool should be empty, all txns confirmed
65 assert_equal(set(self.nodes[0].getrawmempool()), set())
66 for txid in spends1_id+spends2_id:
67 tx = self.nodes[0].gettransaction(txid)
68 assert(tx["confirmations"] > 0)
71 if __name__ == '__main__':
72 MempoolCoinbaseTest().main()