Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

listtransactions.py 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env python2
  2. # Copyright (c) 2014 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. # Exercise the listtransactions API
  6. from test_framework import BitcoinTestFramework
  7. from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
  8. from util import *
  9. def check_array_result(object_array, to_match, expected):
  10. """
  11. Pass in array of JSON objects, a dictionary with key/value pairs
  12. to match against, and another dictionary with expected key/value
  13. pairs.
  14. """
  15. num_matched = 0
  16. for item in object_array:
  17. all_match = True
  18. for key,value in to_match.items():
  19. if item[key] != value:
  20. all_match = False
  21. if not all_match:
  22. continue
  23. for key,value in expected.items():
  24. if item[key] != value:
  25. raise AssertionError("%s : expected %s=%s"%(str(item), str(key), str(value)))
  26. num_matched = num_matched+1
  27. if num_matched == 0:
  28. raise AssertionError("No objects matched %s"%(str(to_match)))
  29. class ListTransactionsTest(BitcoinTestFramework):
  30. def run_test(self):
  31. # Simple send, 0 to 1:
  32. txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
  33. self.sync_all()
  34. check_array_result(self.nodes[0].listtransactions(),
  35. {"txid":txid},
  36. {"category":"send","account":"","amount":Decimal("-0.1"),"confirmations":0})
  37. check_array_result(self.nodes[1].listtransactions(),
  38. {"txid":txid},
  39. {"category":"receive","account":"","amount":Decimal("0.1"),"confirmations":0})
  40. # mine a block, confirmations should change:
  41. self.nodes[0].setgenerate(True, 1)
  42. self.sync_all()
  43. check_array_result(self.nodes[0].listtransactions(),
  44. {"txid":txid},
  45. {"category":"send","account":"","amount":Decimal("-0.1"),"confirmations":1})
  46. check_array_result(self.nodes[1].listtransactions(),
  47. {"txid":txid},
  48. {"category":"receive","account":"","amount":Decimal("0.1"),"confirmations":1})
  49. # send-to-self:
  50. txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
  51. check_array_result(self.nodes[0].listtransactions(),
  52. {"txid":txid, "category":"send"},
  53. {"amount":Decimal("-0.2")})
  54. check_array_result(self.nodes[0].listtransactions(),
  55. {"txid":txid, "category":"receive"},
  56. {"amount":Decimal("0.2")})
  57. # sendmany from node1: twice to self, twice to node2:
  58. send_to = { self.nodes[0].getnewaddress() : 0.11,
  59. self.nodes[1].getnewaddress() : 0.22,
  60. self.nodes[0].getaccountaddress("from1") : 0.33,
  61. self.nodes[1].getaccountaddress("toself") : 0.44 }
  62. txid = self.nodes[1].sendmany("", send_to)
  63. self.sync_all()
  64. check_array_result(self.nodes[1].listtransactions(),
  65. {"category":"send","amount":Decimal("-0.11")},
  66. {"txid":txid} )
  67. check_array_result(self.nodes[0].listtransactions(),
  68. {"category":"receive","amount":Decimal("0.11")},
  69. {"txid":txid} )
  70. check_array_result(self.nodes[1].listtransactions(),
  71. {"category":"send","amount":Decimal("-0.22")},
  72. {"txid":txid} )
  73. check_array_result(self.nodes[1].listtransactions(),
  74. {"category":"receive","amount":Decimal("0.22")},
  75. {"txid":txid} )
  76. check_array_result(self.nodes[1].listtransactions(),
  77. {"category":"send","amount":Decimal("-0.33")},
  78. {"txid":txid} )
  79. check_array_result(self.nodes[0].listtransactions(),
  80. {"category":"receive","amount":Decimal("0.33")},
  81. {"txid":txid, "account" : "from1"} )
  82. check_array_result(self.nodes[1].listtransactions(),
  83. {"category":"send","amount":Decimal("-0.44")},
  84. {"txid":txid, "account" : ""} )
  85. check_array_result(self.nodes[1].listtransactions(),
  86. {"category":"receive","amount":Decimal("0.44")},
  87. {"txid":txid, "account" : "toself"} )
  88. if __name__ == '__main__':
  89. ListTransactionsTest().main()