Remove unused Python imports
[bitcoinplatinum.git] / test / functional / wallet-accounts.py
blobe6635bea1c671268cbfffa9e39bc1aaa2ecf5cc0
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.
7 RPCs tested are:
8 - getaccountaddress
9 - getaddressesbyaccount
10 - listaddressgroupings
11 - setaccount
12 - sendfrom (with account arguments)
13 - move (with account arguments)
14 """
16 from test_framework.test_framework import BitcoinTestFramework
17 from test_framework.util import (
18 assert_equal,
21 class WalletAccountsTest(BitcoinTestFramework):
23 def __init__(self):
24 super().__init__()
25 self.setup_clean_chain = True
26 self.num_nodes = 1
27 self.extra_args = [[]]
29 def run_test(self):
30 node = self.nodes[0]
31 # Check that there's no UTXO on any of the nodes
32 assert_equal(len(node.listunspent()), 0)
34 # Note each time we call generate, all generated coins go into
35 # the same address, so we call twice to get two addresses w/50 each
36 node.generate(1)
37 node.generate(101)
38 assert_equal(node.getbalance(), 100)
40 # there should be 2 address groups
41 # each with 1 address with a balance of 50 Bitcoins
42 address_groups = node.listaddressgroupings()
43 assert_equal(len(address_groups), 2)
44 # the addresses aren't linked now, but will be after we send to the
45 # common address
46 linked_addresses = set()
47 for address_group in address_groups:
48 assert_equal(len(address_group), 1)
49 assert_equal(len(address_group[0]), 2)
50 assert_equal(address_group[0][1], 50)
51 linked_addresses.add(address_group[0][0])
53 # send 50 from each address to a third address not in this wallet
54 # There's some fee that will come back to us when the miner reward
55 # matures.
56 common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr"
57 txid = node.sendmany(
58 fromaccount="",
59 amounts={common_address: 100},
60 subtractfeefrom=[common_address],
61 minconf=1,
63 tx_details = node.gettransaction(txid)
64 fee = -tx_details['details'][0]['fee']
65 # there should be 1 address group, with the previously
66 # unlinked addresses now linked (they both have 0 balance)
67 address_groups = node.listaddressgroupings()
68 assert_equal(len(address_groups), 1)
69 assert_equal(len(address_groups[0]), 2)
70 assert_equal(set([a[0] for a in address_groups[0]]), linked_addresses)
71 assert_equal([a[1] for a in address_groups[0]], [0, 0])
73 node.generate(1)
75 # we want to reset so that the "" account has what's expected.
76 # otherwise we're off by exactly the fee amount as that's mined
77 # and matures in the next 100 blocks
78 node.sendfrom("", common_address, fee)
79 accounts = ["a", "b", "c", "d", "e"]
80 amount_to_send = 1.0
81 account_addresses = dict()
82 for account in accounts:
83 address = node.getaccountaddress(account)
84 account_addresses[account] = address
86 node.getnewaddress(account)
87 assert_equal(node.getaccount(address), account)
88 assert(address in node.getaddressesbyaccount(account))
90 node.sendfrom("", address, amount_to_send)
92 node.generate(1)
94 for i in range(len(accounts)):
95 from_account = accounts[i]
96 to_account = accounts[(i+1) % len(accounts)]
97 to_address = account_addresses[to_account]
98 node.sendfrom(from_account, to_address, amount_to_send)
100 node.generate(1)
102 for account in accounts:
103 address = node.getaccountaddress(account)
104 assert(address != account_addresses[account])
105 assert_equal(node.getreceivedbyaccount(account), 2)
106 node.move(account, "", node.getbalance(account))
108 node.generate(101)
110 expected_account_balances = {"": 5200}
111 for account in accounts:
112 expected_account_balances[account] = 0
114 assert_equal(node.listaccounts(), expected_account_balances)
116 assert_equal(node.getbalance(""), 5200)
118 for account in accounts:
119 address = node.getaccountaddress("")
120 node.setaccount(address, account)
121 assert(address in node.getaddressesbyaccount(account))
122 assert(address not in node.getaddressesbyaccount(""))
124 for account in accounts:
125 addresses = []
126 for x in range(10):
127 addresses.append(node.getnewaddress())
128 multisig_address = node.addmultisigaddress(5, addresses, account)
129 node.sendfrom("", multisig_address, 50)
131 node.generate(101)
133 for account in accounts:
134 assert_equal(node.getbalance(account), 50)
136 if __name__ == '__main__':
137 WalletAccountsTest().main()