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
17 from test_framework
.test_framework
import BitcoinTestFramework
18 from test_framework
.util
import (
20 assert_raises_rpc_error
,
24 class ZapWalletTXesTest (BitcoinTestFramework
):
25 def set_test_params(self
):
26 self
.setup_clean_chain
= True
30 self
.log
.info("Mining blocks...")
31 self
.nodes
[0].generate(1)
33 self
.nodes
[1].generate(100)
36 # This transaction will be confirmed
37 txid1
= self
.nodes
[0].sendtoaddress(self
.nodes
[1].getnewaddress(), 10)
39 self
.nodes
[0].generate(1)
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.
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.
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.
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()