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

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