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 three bitcoind nodes
8 - create four transactions on node 0 - two are confirmed and two are
10 - restart node 1 and verify that both the confirmed and the unconfirmed
11 transactions are still available.
12 - restart node 0 and verify that the confirmed transactions are still
13 available, but that the unconfirmed transaction has been zapped.
15 from test_framework
.test_framework
import BitcoinTestFramework
16 from test_framework
.util
import *
19 class ZapWalletTXesTest (BitcoinTestFramework
):
23 self
.setup_clean_chain
= True
26 def setup_network(self
, split
=False):
27 self
.nodes
= start_nodes(self
.num_nodes
, self
.options
.tmpdir
)
28 connect_nodes_bi(self
.nodes
,0,1)
29 connect_nodes_bi(self
.nodes
,1,2)
30 connect_nodes_bi(self
.nodes
,0,2)
31 self
.is_network_split
=False
35 print("Mining blocks...")
36 self
.nodes
[0].generate(1)
38 self
.nodes
[1].generate(101)
41 assert_equal(self
.nodes
[0].getbalance(), 50)
43 txid0
= self
.nodes
[0].sendtoaddress(self
.nodes
[2].getnewaddress(), 11)
44 txid1
= self
.nodes
[0].sendtoaddress(self
.nodes
[2].getnewaddress(), 10)
46 self
.nodes
[0].generate(1)
49 txid2
= self
.nodes
[0].sendtoaddress(self
.nodes
[2].getnewaddress(), 11)
50 txid3
= self
.nodes
[0].sendtoaddress(self
.nodes
[2].getnewaddress(), 10)
52 tx0
= self
.nodes
[0].gettransaction(txid0
)
53 assert_equal(tx0
['txid'], txid0
) #tx0 must be available (confirmed)
55 tx1
= self
.nodes
[0].gettransaction(txid1
)
56 assert_equal(tx1
['txid'], txid1
) #tx1 must be available (confirmed)
58 tx2
= self
.nodes
[0].gettransaction(txid2
)
59 assert_equal(tx2
['txid'], txid2
) #tx2 must be available (unconfirmed)
61 tx3
= self
.nodes
[0].gettransaction(txid3
)
62 assert_equal(tx3
['txid'], txid3
) #tx3 must be available (unconfirmed)
66 bitcoind_processes
[0].wait()
67 self
.nodes
[0] = start_node(0,self
.options
.tmpdir
)
69 tx3
= self
.nodes
[0].gettransaction(txid3
)
70 assert_equal(tx3
['txid'], txid3
) #tx must be available (unconfirmed)
73 bitcoind_processes
[0].wait()
75 #restart bitcoind with zapwallettxes
76 self
.nodes
[0] = start_node(0,self
.options
.tmpdir
, ["-zapwallettxes=1"])
78 assert_raises(JSONRPCException
, self
.nodes
[0].gettransaction
, [txid3
])
79 #there must be a expection because the unconfirmed wallettx0 must be gone by now
81 tx0
= self
.nodes
[0].gettransaction(txid0
)
82 assert_equal(tx0
['txid'], txid0
) #tx0 (confirmed) must still be available because it was confirmed
85 if __name__
== '__main__':
86 ZapWalletTXesTest ().main ()