[tests] don't override __init__() in individual tests
[bitcoinplatinum.git] / test / functional / mempool_resurrect_test.py
blob1263c9306b6377d542db0302600a4a0ddc57e507
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):
12 def set_test_params(self):
13 self.num_nodes = 1
14 self.extra_args = [["-checkmempool"]]
16 def run_test(self):
17 node0_address = self.nodes[0].getnewaddress()
18 # Spend block 1/2/3's coinbase transactions
19 # Mine a block.
20 # Create three more transactions, spending the spends
21 # Mine another block.
22 # ... make sure all the transactions are confirmed
23 # Invalidate both blocks
24 # ... make sure all the transactions are put back in the mempool
25 # Mine a new block
26 # ... make sure all the transactions are confirmed again.
28 b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
29 coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
30 spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
31 spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
33 blocks = []
34 blocks.extend(self.nodes[0].generate(1))
36 spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
37 spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]
39 blocks.extend(self.nodes[0].generate(1))
41 # mempool should be empty, all txns confirmed
42 assert_equal(set(self.nodes[0].getrawmempool()), set())
43 for txid in spends1_id+spends2_id:
44 tx = self.nodes[0].gettransaction(txid)
45 assert(tx["confirmations"] > 0)
47 # Use invalidateblock to re-org back; all transactions should
48 # end up unconfirmed and back in the mempool
49 for node in self.nodes:
50 node.invalidateblock(blocks[0])
52 # mempool should be empty, all txns confirmed
53 assert_equal(set(self.nodes[0].getrawmempool()), set(spends1_id+spends2_id))
54 for txid in spends1_id+spends2_id:
55 tx = self.nodes[0].gettransaction(txid)
56 assert(tx["confirmations"] == 0)
58 # Generate another block, they should all get mined
59 self.nodes[0].generate(1)
60 # mempool should be empty, all txns confirmed
61 assert_equal(set(self.nodes[0].getrawmempool()), set())
62 for txid in spends1_id+spends2_id:
63 tx = self.nodes[0].gettransaction(txid)
64 assert(tx["confirmations"] > 0)
67 if __name__ == '__main__':
68 MempoolCoinbaseTest().main()