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.

wallet-accounts.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env python3
  2. # Copyright (c) 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 account RPCs.
  6. RPCs tested are:
  7. - getaccountaddress
  8. - getaddressesbyaccount
  9. - setaccount
  10. - sendfrom (with account arguments)
  11. - move (with account arguments)
  12. """
  13. from test_framework.test_framework import BitcoinTestFramework
  14. from test_framework.util import (
  15. start_nodes,
  16. assert_equal,
  17. )
  18. class WalletAccountsTest(BitcoinTestFramework):
  19. def __init__(self):
  20. super().__init__()
  21. self.setup_clean_chain = True
  22. self.num_nodes = 1
  23. self.node_args = [[]]
  24. def setup_network(self):
  25. self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.node_args)
  26. self.is_network_split = False
  27. def run_test (self):
  28. node = self.nodes[0]
  29. # Check that there's no UTXO on any of the nodes
  30. assert_equal(len(node.listunspent()), 0)
  31. node.generate(101)
  32. assert_equal(node.getbalance(), 50)
  33. accounts = ["a","b","c","d","e"]
  34. amount_to_send = 1.0
  35. account_addresses = dict()
  36. for account in accounts:
  37. address = node.getaccountaddress(account)
  38. account_addresses[account] = address
  39. node.getnewaddress(account)
  40. assert_equal(node.getaccount(address), account)
  41. assert(address in node.getaddressesbyaccount(account))
  42. node.sendfrom("", address, amount_to_send)
  43. node.generate(1)
  44. for i in range(len(accounts)):
  45. from_account = accounts[i]
  46. to_account = accounts[(i+1)%len(accounts)]
  47. to_address = account_addresses[to_account]
  48. node.sendfrom(from_account, to_address, amount_to_send)
  49. node.generate(1)
  50. for account in accounts:
  51. address = node.getaccountaddress(account)
  52. assert(address != account_addresses[account])
  53. assert_equal(node.getreceivedbyaccount(account), 2)
  54. node.move(account, "", node.getbalance(account))
  55. node.generate(101)
  56. expected_account_balances = {"": 5200}
  57. for account in accounts:
  58. expected_account_balances[account] = 0
  59. assert_equal(node.listaccounts(), expected_account_balances)
  60. assert_equal(node.getbalance(""), 5200)
  61. for account in accounts:
  62. address = node.getaccountaddress("")
  63. node.setaccount(address, account)
  64. assert(address in node.getaddressesbyaccount(account))
  65. assert(address not in node.getaddressesbyaccount(""))
  66. for account in accounts:
  67. addresses = []
  68. for x in range(10):
  69. addresses.append(node.getnewaddress())
  70. multisig_address = node.addmultisigaddress(5, addresses, account)
  71. node.sendfrom("", multisig_address, 50)
  72. node.generate(101)
  73. for account in accounts:
  74. assert_equal(node.getbalance(account), 50)
  75. if __name__ == '__main__':
  76. WalletAccountsTest().main ()