Merge #10859: RPC: gettxout: Slightly improve doc and tests
[bitcoinplatinum.git] / test / functional / mempool_persist.py
blob807edeb7a83227a78b1ccaf4e7aec0da63e3bb21
1 #!/usr/bin/env python3
2 # Copyright (c) 2014-2017 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 mempool persistence.
7 By default, bitcoind will dump mempool on shutdown and
8 then reload it on startup. This can be overridden with
9 the -persistmempool=0 command line option.
11 Test is as follows:
13 - start node0, node1 and node2. node1 has -persistmempool=0
14 - create 5 transactions on node2 to its own address. Note that these
15 are not sent to node0 or node1 addresses because we don't want
16 them to be saved in the wallet.
17 - check that node0 and node1 have 5 transactions in their mempools
18 - shutdown all nodes.
19 - startup node0. Verify that it still has 5 transactions
20 in its mempool. Shutdown node0. This tests that by default the
21 mempool is persistent.
22 - startup node1. Verify that its mempool is empty. Shutdown node1.
23 This tests that with -persistmempool=0, the mempool is not
24 dumped to disk when the node is shut down.
25 - Restart node0 with -persistmempool=0. Verify that its mempool is
26 empty. Shutdown node0. This tests that with -persistmempool=0,
27 the mempool is not loaded from disk on start up.
28 - Restart node0 with -persistmempool. Verify that it has 5
29 transactions in its mempool. This tests that -persistmempool=0
30 does not overwrite a previously valid mempool stored on disk.
32 """
33 import time
35 from test_framework.test_framework import BitcoinTestFramework
36 from test_framework.util import *
38 class MempoolPersistTest(BitcoinTestFramework):
40 def __init__(self):
41 super().__init__()
42 # We need 3 nodes for this test. Node1 does not have a persistent mempool.
43 self.num_nodes = 3
44 self.setup_clean_chain = False
45 self.extra_args = [[], ["-persistmempool=0"], []]
47 def run_test(self):
48 chain_height = self.nodes[0].getblockcount()
49 assert_equal(chain_height, 200)
51 self.log.debug("Mine a single block to get out of IBD")
52 self.nodes[0].generate(1)
53 self.sync_all()
55 self.log.debug("Send 5 transactions from node2 (to its own address)")
56 for i in range(5):
57 self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10"))
58 self.sync_all()
60 self.log.debug("Verify that node0 and node1 have 5 transactions in their mempools")
61 assert_equal(len(self.nodes[0].getrawmempool()), 5)
62 assert_equal(len(self.nodes[1].getrawmempool()), 5)
64 self.log.debug("Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.")
65 self.stop_nodes()
66 self.nodes = []
67 self.nodes.append(self.start_node(0, self.options.tmpdir))
68 self.nodes.append(self.start_node(1, self.options.tmpdir))
69 # Give bitcoind a second to reload the mempool
70 time.sleep(1)
71 wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
72 assert_equal(len(self.nodes[1].getrawmempool()), 0)
74 self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
75 self.stop_nodes()
76 self.nodes = []
77 self.nodes.append(self.start_node(0, self.options.tmpdir, ["-persistmempool=0"]))
78 # Give bitcoind a second to reload the mempool
79 time.sleep(1)
80 assert_equal(len(self.nodes[0].getrawmempool()), 0)
82 self.log.debug("Stop-start node0. Verify that it has the transactions in its mempool.")
83 self.stop_nodes()
84 self.nodes = []
85 self.nodes.append(self.start_node(0, self.options.tmpdir))
86 wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
88 if __name__ == '__main__':
89 MempoolPersistTest().main()