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.

importprunedfunds.py 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 importprunedfunds and removeprunedfunds RPCs."""
  6. from test_framework.test_framework import BitcoinTestFramework
  7. from test_framework.util import *
  8. class ImportPrunedFundsTest(BitcoinTestFramework):
  9. def set_test_params(self):
  10. self.setup_clean_chain = True
  11. self.num_nodes = 2
  12. def run_test(self):
  13. self.log.info("Mining blocks...")
  14. self.nodes[0].generate(101)
  15. self.sync_all()
  16. # address
  17. address1 = self.nodes[0].getnewaddress()
  18. # pubkey
  19. address2 = self.nodes[0].getnewaddress()
  20. address2_pubkey = self.nodes[0].validateaddress(address2)['pubkey'] # Using pubkey
  21. # privkey
  22. address3 = self.nodes[0].getnewaddress()
  23. address3_privkey = self.nodes[0].dumpprivkey(address3) # Using privkey
  24. #Check only one address
  25. address_info = self.nodes[0].validateaddress(address1)
  26. assert_equal(address_info['ismine'], True)
  27. self.sync_all()
  28. #Node 1 sync test
  29. assert_equal(self.nodes[1].getblockcount(),101)
  30. #Address Test - before import
  31. address_info = self.nodes[1].validateaddress(address1)
  32. assert_equal(address_info['iswatchonly'], False)
  33. assert_equal(address_info['ismine'], False)
  34. address_info = self.nodes[1].validateaddress(address2)
  35. assert_equal(address_info['iswatchonly'], False)
  36. assert_equal(address_info['ismine'], False)
  37. address_info = self.nodes[1].validateaddress(address3)
  38. assert_equal(address_info['iswatchonly'], False)
  39. assert_equal(address_info['ismine'], False)
  40. #Send funds to self
  41. txnid1 = self.nodes[0].sendtoaddress(address1, 0.1)
  42. self.nodes[0].generate(1)
  43. rawtxn1 = self.nodes[0].gettransaction(txnid1)['hex']
  44. proof1 = self.nodes[0].gettxoutproof([txnid1])
  45. txnid2 = self.nodes[0].sendtoaddress(address2, 0.05)
  46. self.nodes[0].generate(1)
  47. rawtxn2 = self.nodes[0].gettransaction(txnid2)['hex']
  48. proof2 = self.nodes[0].gettxoutproof([txnid2])
  49. txnid3 = self.nodes[0].sendtoaddress(address3, 0.025)
  50. self.nodes[0].generate(1)
  51. rawtxn3 = self.nodes[0].gettransaction(txnid3)['hex']
  52. proof3 = self.nodes[0].gettxoutproof([txnid3])
  53. self.sync_all()
  54. #Import with no affiliated address
  55. assert_raises_rpc_error(-5, "No addresses", self.nodes[1].importprunedfunds, rawtxn1, proof1)
  56. balance1 = self.nodes[1].getbalance("", 0, True)
  57. assert_equal(balance1, Decimal(0))
  58. #Import with affiliated address with no rescan
  59. self.nodes[1].importaddress(address2, "add2", False)
  60. result2 = self.nodes[1].importprunedfunds(rawtxn2, proof2)
  61. balance2 = self.nodes[1].getbalance("add2", 0, True)
  62. assert_equal(balance2, Decimal('0.05'))
  63. #Import with private key with no rescan
  64. self.nodes[1].importprivkey(privkey=address3_privkey, label="add3", rescan=False)
  65. self.nodes[1].importprunedfunds(rawtxn3, proof3)
  66. balance3 = self.nodes[1].getbalance("add3", 0, False)
  67. assert_equal(balance3, Decimal('0.025'))
  68. balance3 = self.nodes[1].getbalance("*", 0, True)
  69. assert_equal(balance3, Decimal('0.075'))
  70. #Addresses Test - after import
  71. address_info = self.nodes[1].validateaddress(address1)
  72. assert_equal(address_info['iswatchonly'], False)
  73. assert_equal(address_info['ismine'], False)
  74. address_info = self.nodes[1].validateaddress(address2)
  75. assert_equal(address_info['iswatchonly'], True)
  76. assert_equal(address_info['ismine'], False)
  77. address_info = self.nodes[1].validateaddress(address3)
  78. assert_equal(address_info['iswatchonly'], False)
  79. assert_equal(address_info['ismine'], True)
  80. #Remove transactions
  81. assert_raises_rpc_error(-8, "Transaction does not exist in wallet.", self.nodes[1].removeprunedfunds, txnid1)
  82. balance1 = self.nodes[1].getbalance("*", 0, True)
  83. assert_equal(balance1, Decimal('0.075'))
  84. self.nodes[1].removeprunedfunds(txnid2)
  85. balance2 = self.nodes[1].getbalance("*", 0, True)
  86. assert_equal(balance2, Decimal('0.025'))
  87. self.nodes[1].removeprunedfunds(txnid3)
  88. balance3 = self.nodes[1].getbalance("*", 0, True)
  89. assert_equal(balance3, Decimal('0.0'))
  90. if __name__ == '__main__':
  91. ImportPrunedFundsTest().main()