You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zapwallettxes.py 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python2
  2. # Copyright (c) 2014-2015 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. from test_framework.test_framework import BitcoinTestFramework
  6. from test_framework.util import *
  7. class ZapWalletTXesTest (BitcoinTestFramework):
  8. def setup_chain(self):
  9. print("Initializing test directory "+self.options.tmpdir)
  10. initialize_chain_clean(self.options.tmpdir, 3)
  11. def setup_network(self, split=False):
  12. self.nodes = start_nodes(3, self.options.tmpdir)
  13. connect_nodes_bi(self.nodes,0,1)
  14. connect_nodes_bi(self.nodes,1,2)
  15. connect_nodes_bi(self.nodes,0,2)
  16. self.is_network_split=False
  17. self.sync_all()
  18. def run_test (self):
  19. print "Mining blocks..."
  20. self.nodes[0].generate(1)
  21. self.sync_all()
  22. self.nodes[1].generate(101)
  23. self.sync_all()
  24. assert_equal(self.nodes[0].getbalance(), 50)
  25. txid0 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
  26. txid1 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
  27. self.sync_all()
  28. self.nodes[0].generate(1)
  29. self.sync_all()
  30. txid2 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
  31. txid3 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
  32. tx0 = self.nodes[0].gettransaction(txid0)
  33. assert_equal(tx0['txid'], txid0) #tx0 must be available (confirmed)
  34. tx1 = self.nodes[0].gettransaction(txid1)
  35. assert_equal(tx1['txid'], txid1) #tx1 must be available (confirmed)
  36. tx2 = self.nodes[0].gettransaction(txid2)
  37. assert_equal(tx2['txid'], txid2) #tx2 must be available (unconfirmed)
  38. tx3 = self.nodes[0].gettransaction(txid3)
  39. assert_equal(tx3['txid'], txid3) #tx3 must be available (unconfirmed)
  40. #restart bitcoind
  41. self.nodes[0].stop()
  42. bitcoind_processes[0].wait()
  43. self.nodes[0] = start_node(0,self.options.tmpdir)
  44. tx3 = self.nodes[0].gettransaction(txid3)
  45. assert_equal(tx3['txid'], txid3) #tx must be available (unconfirmed)
  46. self.nodes[0].stop()
  47. bitcoind_processes[0].wait()
  48. #restart bitcoind with zapwallettxes
  49. self.nodes[0] = start_node(0,self.options.tmpdir, ["-zapwallettxes=1"])
  50. aException = False
  51. try:
  52. tx3 = self.nodes[0].gettransaction(txid3)
  53. except JSONRPCException,e:
  54. print e
  55. aException = True
  56. assert_equal(aException, True) #there must be a expection because the unconfirmed wallettx0 must be gone by now
  57. tx0 = self.nodes[0].gettransaction(txid0)
  58. assert_equal(tx0['txid'], txid0) #tx0 (confirmed) must still be available because it was confirmed
  59. if __name__ == '__main__':
  60. ZapWalletTXesTest ().main ()