[wallet] [tests] Add listwallets to multiwallet test
[bitcoinplatinum.git] / test / functional / wallet-accounts.py
blob158aa9ae896c75894f433769b105e1e3c0d8cc45
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 assert_equal
19 class WalletAccountsTest(BitcoinTestFramework):
21 def __init__(self):
22 super().__init__()
23 self.setup_clean_chain = True
24 self.num_nodes = 1
25 self.extra_args = [[]]
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)
32 # Note each time we call generate, all generated coins go into
33 # the same address, so we call twice to get two addresses w/50 each
34 node.generate(1)
35 node.generate(101)
36 assert_equal(node.getbalance(), 100)
38 # there should be 2 address groups
39 # each with 1 address with a balance of 50 Bitcoins
40 address_groups = node.listaddressgroupings()
41 assert_equal(len(address_groups), 2)
42 # the addresses aren't linked now, but will be after we send to the
43 # common address
44 linked_addresses = set()
45 for address_group in address_groups:
46 assert_equal(len(address_group), 1)
47 assert_equal(len(address_group[0]), 2)
48 assert_equal(address_group[0][1], 50)
49 linked_addresses.add(address_group[0][0])
51 # send 50 from each address to a third address not in this wallet
52 # There's some fee that will come back to us when the miner reward
53 # matures.
54 common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr"
55 txid = node.sendmany(
56 fromaccount="",
57 amounts={common_address: 100},
58 subtractfeefrom=[common_address],
59 minconf=1,
61 tx_details = node.gettransaction(txid)
62 fee = -tx_details['details'][0]['fee']
63 # there should be 1 address group, with the previously
64 # unlinked addresses now linked (they both have 0 balance)
65 address_groups = node.listaddressgroupings()
66 assert_equal(len(address_groups), 1)
67 assert_equal(len(address_groups[0]), 2)
68 assert_equal(set([a[0] for a in address_groups[0]]), linked_addresses)
69 assert_equal([a[1] for a in address_groups[0]], [0, 0])
71 node.generate(1)
73 # we want to reset so that the "" account has what's expected.
74 # otherwise we're off by exactly the fee amount as that's mined
75 # and matures in the next 100 blocks
76 node.sendfrom("", common_address, fee)
77 accounts = ["a", "b", "c", "d", "e"]
78 amount_to_send = 1.0
79 account_addresses = dict()
80 for account in accounts:
81 address = node.getaccountaddress(account)
82 account_addresses[account] = address
84 node.getnewaddress(account)
85 assert_equal(node.getaccount(address), account)
86 assert(address in node.getaddressesbyaccount(account))
88 node.sendfrom("", address, amount_to_send)
90 node.generate(1)
92 for i in range(len(accounts)):
93 from_account = accounts[i]
94 to_account = accounts[(i+1) % len(accounts)]
95 to_address = account_addresses[to_account]
96 node.sendfrom(from_account, to_address, amount_to_send)
98 node.generate(1)
100 for account in accounts:
101 address = node.getaccountaddress(account)
102 assert(address != account_addresses[account])
103 assert_equal(node.getreceivedbyaccount(account), 2)
104 node.move(account, "", node.getbalance(account))
106 node.generate(101)
108 expected_account_balances = {"": 5200}
109 for account in accounts:
110 expected_account_balances[account] = 0
112 assert_equal(node.listaccounts(), expected_account_balances)
114 assert_equal(node.getbalance(""), 5200)
116 for account in accounts:
117 address = node.getaccountaddress("")
118 node.setaccount(address, account)
119 assert(address in node.getaddressesbyaccount(account))
120 assert(address not in node.getaddressesbyaccount(""))
122 for account in accounts:
123 addresses = []
124 for x in range(10):
125 addresses.append(node.getnewaddress())
126 multisig_address = node.addmultisigaddress(5, addresses, account)
127 node.sendfrom("", multisig_address, 50)
129 node.generate(101)
131 for account in accounts:
132 assert_equal(node.getbalance(account), 50)
134 if __name__ == '__main__':
135 WalletAccountsTest().main()