7
7
RPCs tested are:
8
8
- getaccountaddress
9
9
- getaddressesbyaccount
10
+ - listaddressgroupings
10
11
- setaccount
11
12
- sendfrom (with account arguments)
12
13
- move (with account arguments)
@@ -26,16 +27,57 @@ def __init__(self):
26
27
self .num_nodes = 1
27
28
self .extra_args = [[]]
28
29
29
- def run_test (self ):
30
+ def run_test (self ):
30
31
node = self .nodes [0 ]
31
32
# Check that there's no UTXO on any of the nodes
32
33
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 )
34
38
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" ]
39
81
amount_to_send = 1.0
40
82
account_addresses = dict ()
41
83
for account in accounts :
@@ -52,7 +94,7 @@ def run_test (self):
52
94
53
95
for i in range (len (accounts )):
54
96
from_account = accounts [i ]
55
- to_account = accounts [(i + 1 )% len (accounts )]
97
+ to_account = accounts [(i + 1 ) % len (accounts )]
56
98
to_address = account_addresses [to_account ]
57
99
node .sendfrom (from_account , to_address , amount_to_send )
58
100
@@ -63,7 +105,7 @@ def run_test (self):
63
105
assert (address != account_addresses [account ])
64
106
assert_equal (node .getreceivedbyaccount (account ), 2 )
65
107
node .move (account , "" , node .getbalance (account ))
66
-
108
+
67
109
node .generate (101 )
68
110
69
111
expected_account_balances = {"" : 5200 }
@@ -93,4 +135,4 @@ def run_test (self):
93
135
assert_equal (node .getbalance (account ), 50 )
94
136
95
137
if __name__ == '__main__' :
96
- WalletAccountsTest ().main ()
138
+ WalletAccountsTest ().main ()
0 commit comments