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)
@@ -30,16 +31,57 @@ def setup_network(self):
30
31
self .nodes = start_nodes (self .num_nodes , self .options .tmpdir , self .node_args )
31
32
self .is_network_split = False
32
33
33
- def run_test (self ):
34
+ def run_test (self ):
34
35
node = self .nodes [0 ]
35
36
# Check that there's no UTXO on any of the nodes
36
37
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 )
38
42
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" ]
43
85
amount_to_send = 1.0
44
86
account_addresses = dict ()
45
87
for account in accounts :
@@ -56,7 +98,7 @@ def run_test (self):
56
98
57
99
for i in range (len (accounts )):
58
100
from_account = accounts [i ]
59
- to_account = accounts [(i + 1 )% len (accounts )]
101
+ to_account = accounts [(i + 1 ) % len (accounts )]
60
102
to_address = account_addresses [to_account ]
61
103
node .sendfrom (from_account , to_address , amount_to_send )
62
104
@@ -67,7 +109,7 @@ def run_test (self):
67
109
assert (address != account_addresses [account ])
68
110
assert_equal (node .getreceivedbyaccount (account ), 2 )
69
111
node .move (account , "" , node .getbalance (account ))
70
-
112
+
71
113
node .generate (101 )
72
114
73
115
expected_account_balances = {"" : 5200 }
@@ -97,4 +139,4 @@ def run_test (self):
97
139
assert_equal (node .getbalance (account ), 50 )
98
140
99
141
if __name__ == '__main__' :
100
- WalletAccountsTest ().main ()
142
+ WalletAccountsTest ().main ()
0 commit comments