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

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