Skip to content

Commit dadfee3

Browse files
committed
[test] Add test for listaddressgroupings
Test added as part of wallet-accounts.py. Make file a little more flake8 compliant
1 parent e2b99b1 commit dadfee3

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

test/functional/wallet-accounts.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
RPCs tested are:
88
- getaccountaddress
99
- getaddressesbyaccount
10+
- listaddressgroupings
1011
- setaccount
1112
- sendfrom (with account arguments)
1213
- move (with account arguments)
@@ -30,16 +31,57 @@ def setup_network(self):
3031
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.node_args)
3132
self.is_network_split = False
3233

33-
def run_test (self):
34+
def run_test(self):
3435
node = self.nodes[0]
3536
# Check that there's no UTXO on any of the nodes
3637
assert_equal(len(node.listunspent()), 0)
37-
38+
39+
# Note each time we call generate, all generated coins go into
40+
# the same address, so we call twice to get two addresses w/50 each
41+
node.generate(1)
3842
node.generate(101)
39-
40-
assert_equal(node.getbalance(), 50)
41-
42-
accounts = ["a","b","c","d","e"]
43+
assert_equal(node.getbalance(), 100)
44+
45+
# there should be 2 address groups
46+
# each with 1 address with a balance of 50 Bitcoins
47+
address_groups = node.listaddressgroupings()
48+
assert_equal(len(address_groups), 2)
49+
# the addresses aren't linked now, but will be after we send to the
50+
# common address
51+
linked_addresses = set()
52+
for address_group in address_groups:
53+
assert_equal(len(address_group), 1)
54+
assert_equal(len(address_group[0]), 2)
55+
assert_equal(address_group[0][1], 50)
56+
linked_addresses.add(address_group[0][0])
57+
58+
# send 50 from each address to a third address not in this wallet
59+
# There's some fee that will come back to us when the miner reward
60+
# matures.
61+
common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr"
62+
txid = node.sendmany(
63+
fromaccount="",
64+
amounts={common_address: 100},
65+
subtractfeefrom=[common_address],
66+
minconf=1,
67+
)
68+
tx_details = node.gettransaction(txid)
69+
fee = -tx_details['details'][0]['fee']
70+
# there should be 1 address group, with the previously
71+
# unlinked addresses now linked (they both have 0 balance)
72+
address_groups = node.listaddressgroupings()
73+
assert_equal(len(address_groups), 1)
74+
assert_equal(len(address_groups[0]), 2)
75+
assert_equal(set([a[0] for a in address_groups[0]]), linked_addresses)
76+
assert_equal([a[1] for a in address_groups[0]], [0, 0])
77+
78+
node.generate(1)
79+
80+
# we want to reset so that the "" account has what's expected.
81+
# otherwise we're off by exactly the fee amount as that's mined
82+
# and matures in the next 100 blocks
83+
node.sendfrom("", common_address, fee)
84+
accounts = ["a", "b", "c", "d", "e"]
4385
amount_to_send = 1.0
4486
account_addresses = dict()
4587
for account in accounts:
@@ -56,7 +98,7 @@ def run_test (self):
5698

5799
for i in range(len(accounts)):
58100
from_account = accounts[i]
59-
to_account = accounts[(i+1)%len(accounts)]
101+
to_account = accounts[(i+1) % len(accounts)]
60102
to_address = account_addresses[to_account]
61103
node.sendfrom(from_account, to_address, amount_to_send)
62104

@@ -67,7 +109,7 @@ def run_test (self):
67109
assert(address != account_addresses[account])
68110
assert_equal(node.getreceivedbyaccount(account), 2)
69111
node.move(account, "", node.getbalance(account))
70-
112+
71113
node.generate(101)
72114

73115
expected_account_balances = {"": 5200}
@@ -97,4 +139,4 @@ def run_test (self):
97139
assert_equal(node.getbalance(account), 50)
98140

99141
if __name__ == '__main__':
100-
WalletAccountsTest().main ()
142+
WalletAccountsTest().main()

0 commit comments

Comments
 (0)