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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.
  6. - start three bitcoind nodes
  7. - create four transactions on node 0 - two are confirmed and two are
  8. unconfirmed.
  9. - restart node 1 and verify that both the confirmed and the unconfirmed
  10. transactions are still available.
  11. - restart node 0 and verify that the confirmed transactions are still
  12. available, but that the unconfirmed transaction has been zapped.
  13. """
  14. from test_framework.test_framework import BitcoinTestFramework
  15. from test_framework.util import *
  16. class ZapWalletTXesTest (BitcoinTestFramework):
  17. def __init__(self):
  18. super().__init__()
  19. self.setup_clean_chain = True
  20. self.num_nodes = 3
  21. def setup_network(self, split=False):
  22. self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
  23. connect_nodes_bi(self.nodes,0,1)
  24. connect_nodes_bi(self.nodes,1,2)
  25. connect_nodes_bi(self.nodes,0,2)
  26. self.is_network_split=False
  27. self.sync_all()
  28. def run_test (self):
  29. self.log.info("Mining blocks...")
  30. self.nodes[0].generate(1)
  31. self.sync_all()
  32. self.nodes[1].generate(101)
  33. self.sync_all()
  34. assert_equal(self.nodes[0].getbalance(), 50)
  35. txid0 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
  36. txid1 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
  37. self.sync_all()
  38. self.nodes[0].generate(1)
  39. self.sync_all()
  40. txid2 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
  41. txid3 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
  42. tx0 = self.nodes[0].gettransaction(txid0)
  43. assert_equal(tx0['txid'], txid0) #tx0 must be available (confirmed)
  44. tx1 = self.nodes[0].gettransaction(txid1)
  45. assert_equal(tx1['txid'], txid1) #tx1 must be available (confirmed)
  46. tx2 = self.nodes[0].gettransaction(txid2)
  47. assert_equal(tx2['txid'], txid2) #tx2 must be available (unconfirmed)
  48. tx3 = self.nodes[0].gettransaction(txid3)
  49. assert_equal(tx3['txid'], txid3) #tx3 must be available (unconfirmed)
  50. #restart bitcoind
  51. self.nodes[0].stop()
  52. bitcoind_processes[0].wait()
  53. self.nodes[0] = start_node(0,self.options.tmpdir)
  54. tx3 = self.nodes[0].gettransaction(txid3)
  55. assert_equal(tx3['txid'], txid3) #tx must be available (unconfirmed)
  56. self.nodes[0].stop()
  57. bitcoind_processes[0].wait()
  58. #restart bitcoind with zapwallettxes
  59. self.nodes[0] = start_node(0,self.options.tmpdir, ["-zapwallettxes=1"])
  60. assert_raises(JSONRPCException, self.nodes[0].gettransaction, [txid3])
  61. #there must be a expection because the unconfirmed wallettx0 must be gone by now
  62. tx0 = self.nodes[0].gettransaction(txid0)
  63. assert_equal(tx0['txid'], txid0) #tx0 (confirmed) must still be available because it was confirmed
  64. if __name__ == '__main__':
  65. ZapWalletTXesTest ().main ()