[tests] Add -blocknotify functional test
[bitcoinplatinum.git] / test / functional / zapwallettxes.py
blob8cd622dc8ec3b7996140f2115f904a89e3a6639e
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 the zapwallettxes functionality.
7 - start two bitcoind nodes
8 - create two transactions on node 0 - one is confirmed and one is unconfirmed.
9 - restart node 0 and verify that both the confirmed and the unconfirmed
10 transactions are still available.
11 - restart node 0 with zapwallettxes and persistmempool, and verify that both
12 the confirmed and the unconfirmed transactions are still available.
13 - restart node 0 with just zapwallettxed and verify that the confirmed
14 transactions are still available, but that the unconfirmed transaction has
15 been zapped.
16 """
17 from test_framework.test_framework import BitcoinTestFramework
18 from test_framework.util import (
19 assert_equal,
20 assert_raises_rpc_error,
21 wait_until,
24 class ZapWalletTXesTest (BitcoinTestFramework):
25 def set_test_params(self):
26 self.setup_clean_chain = True
27 self.num_nodes = 2
29 def run_test(self):
30 self.log.info("Mining blocks...")
31 self.nodes[0].generate(1)
32 self.sync_all()
33 self.nodes[1].generate(100)
34 self.sync_all()
36 # This transaction will be confirmed
37 txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10)
39 self.nodes[0].generate(1)
40 self.sync_all()
42 # This transaction will not be confirmed
43 txid2 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 20)
45 # Confirmed and unconfirmed transactions are now in the wallet.
46 assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
47 assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
49 # Stop-start node0. Both confirmed and unconfirmed transactions remain in the wallet.
50 self.stop_node(0)
51 self.start_node(0)
53 assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
54 assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
56 # Stop node0 and restart with zapwallettxes and persistmempool. The unconfirmed
57 # transaction is zapped from the wallet, but is re-added when the mempool is reloaded.
58 self.stop_node(0)
59 self.start_node(0, ["-persistmempool=1", "-zapwallettxes=2"])
61 wait_until(lambda: self.nodes[0].getmempoolinfo()['size'] == 1, timeout=3)
63 assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
64 assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
66 # Stop node0 and restart with zapwallettxes, but not persistmempool.
67 # The unconfirmed transaction is zapped and is no longer in the wallet.
68 self.stop_node(0)
69 self.start_node(0, ["-zapwallettxes=2"])
71 # tx1 is still be available because it was confirmed
72 assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
74 # This will raise an exception because the unconfirmed transaction has been zapped
75 assert_raises_rpc_error(-5, 'Invalid or non-wallet transaction id', self.nodes[0].gettransaction, txid2)
77 if __name__ == '__main__':
78 ZapWalletTXesTest().main()