Skip to content

Commit 3c5e6c9

Browse files
author
MarcoFalke
committed
Merge #10255: [test] Add test for listaddressgroupings
dadfee3 [test] Add test for listaddressgroupings (Jimmy Song) Tree-SHA512: 21cf0233c7fcf585f9a31306612ae1113ea916d2972b834efef0cb2154bd4dd24d9746d0632c778c699328f7e7a336d2da6e2bac9f0fb657c30290757563ad22
2 parents dc8fc0c + dadfee3 commit 3c5e6c9

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)
@@ -26,16 +27,57 @@ def __init__(self):
2627
self.num_nodes = 1
2728
self.extra_args = [[]]
2829

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

5395
for i in range(len(accounts)):
5496
from_account = accounts[i]
55-
to_account = accounts[(i+1)%len(accounts)]
97+
to_account = accounts[(i+1) % len(accounts)]
5698
to_address = account_addresses[to_account]
5799
node.sendfrom(from_account, to_address, amount_to_send)
58100

@@ -63,7 +105,7 @@ def run_test (self):
63105
assert(address != account_addresses[account])
64106
assert_equal(node.getreceivedbyaccount(account), 2)
65107
node.move(account, "", node.getbalance(account))
66-
108+
67109
node.generate(101)
68110

69111
expected_account_balances = {"": 5200}
@@ -93,4 +135,4 @@ def run_test (self):
93135
assert_equal(node.getbalance(account), 50)
94136

95137
if __name__ == '__main__':
96-
WalletAccountsTest().main ()
138+
WalletAccountsTest().main()

0 commit comments

Comments
 (0)