66
77RPCs tested are:
88 - getlabeladdress
9- - getaddressesbyaccount
9+ - getaddressesbyaccount/getaddressesbylabel
1010 - listaddressgroupings
1111 - setlabel
1212 - sendfrom (with account arguments)
1313 - move (with account arguments)
14+
15+ Run the test twice - once using the accounts API and once using the labels API.
16+ The accounts API test can be removed in V0.18.
1417"""
1518from collections import defaultdict
1619
1720from test_framework .test_framework import BitcoinTestFramework
18- from test_framework .util import assert_equal
21+ from test_framework .util import assert_equal , assert_raises_rpc_error
1922
2023class WalletLabelsTest (BitcoinTestFramework ):
2124 def set_test_params (self ):
2225 self .setup_clean_chain = True
23- self .num_nodes = 1
24- self .extra_args = [['-deprecatedrpc=accounts' ]]
26+ self .num_nodes = 2
27+ self .extra_args = [['-deprecatedrpc=accounts' ], []]
28+
29+ def setup_network (self ):
30+ """Don't connect nodes."""
31+ self .setup_nodes ()
2532
2633 def run_test (self ):
27- node = self .nodes [0 ]
34+ """Run the test twice - once using the accounts API and once using the labels API."""
35+ self .log .info ("Test accounts API" )
36+ self ._run_subtest (True , self .nodes [0 ])
37+ self .log .info ("Test labels API" )
38+ self ._run_subtest (False , self .nodes [1 ])
39+
40+ def _run_subtest (self , accounts_api , node ):
2841 # Check that there's no UTXO on any of the nodes
2942 assert_equal (len (node .listunspent ()), 0 )
3043
@@ -77,7 +90,7 @@ def run_test(self):
7790
7891 # Create labels and make sure subsequent label API calls
7992 # recognize the label/address associations.
80- labels = [Label (name ) for name in ("a" , "b" , "c" , "d" , "e" )]
93+ labels = [Label (name , accounts_api ) for name in ("a" , "b" , "c" , "d" , "e" )]
8194 for label in labels :
8295 label .add_receive_address (node .getlabeladdress (label = label .name , force = True ))
8396 label .verify (node )
@@ -101,29 +114,34 @@ def run_test(self):
101114
102115 # Check that sendfrom label reduces listaccounts balances.
103116 for i , label in enumerate (labels ):
104- to_label = labels [(i + 1 ) % len (labels )]
117+ to_label = labels [(i + 1 ) % len (labels )]
105118 node .sendfrom (label .name , to_label .receive_address , amount_to_send )
106119 node .generate (1 )
107120 for label in labels :
108121 label .add_receive_address (node .getlabeladdress (label .name ))
109122 label .verify (node )
110123 assert_equal (node .getreceivedbylabel (label .name ), 2 )
111- node .move (label .name , "" , node .getbalance (label .name ))
124+ if accounts_api :
125+ node .move (label .name , "" , node .getbalance (label .name ))
112126 label .verify (node )
113127 node .generate (101 )
114128 expected_account_balances = {"" : 5200 }
115129 for label in labels :
116130 expected_account_balances [label .name ] = 0
117- assert_equal (node .listaccounts (), expected_account_balances )
118- assert_equal (node .getbalance ("" ), 5200 )
131+ if accounts_api :
132+ assert_equal (node .listaccounts (), expected_account_balances )
133+ assert_equal (node .getbalance ("" ), 5200 )
119134
120135 # Check that setlabel can assign a label to a new unused address.
121136 for label in labels :
122137 address = node .getlabeladdress (label = "" , force = True )
123138 node .setlabel (address , label .name )
124139 label .add_address (address )
125140 label .verify (node )
126- assert (address not in node .getaddressesbyaccount ("" ))
141+ if accounts_api :
142+ assert (address not in node .getaddressesbyaccount ("" ))
143+ else :
144+ assert_raises_rpc_error (- 11 , "No addresses with label" , node .getaddressesbylabel , "" )
127145
128146 # Check that addmultisigaddress can assign labels.
129147 for label in labels :
@@ -136,8 +154,9 @@ def run_test(self):
136154 label .verify (node )
137155 node .sendfrom ("" , multisig_address , 50 )
138156 node .generate (101 )
139- for label in labels :
140- assert_equal (node .getbalance (label .name ), 50 )
157+ if accounts_api :
158+ for label in labels :
159+ assert_equal (node .getbalance (label .name ), 50 )
141160
142161 # Check that setlabel can change the label of an address from a
143162 # different label.
@@ -156,9 +175,10 @@ def run_test(self):
156175 change_label (node , labels [2 ].receive_address , labels [2 ], labels [2 ])
157176
158177class Label :
159- def __init__ (self , name ):
178+ def __init__ (self , name , accounts_api ):
160179 # Label name
161180 self .name = name
181+ self .accounts_api = accounts_api
162182 # Current receiving address associated with this label.
163183 self .receive_address = None
164184 # List of all addresses assigned with this label
@@ -184,13 +204,16 @@ def verify(self, node):
184204 node .getaddressinfo (address )['labels' ][0 ],
185205 {"name" : self .name ,
186206 "purpose" : self .purpose [address ]})
187- assert_equal (node .getaccount (address ), self .name )
207+ if self .accounts_api :
208+ assert_equal (node .getaccount (address ), self .name )
209+ else :
210+ assert_equal (node .getaddressinfo (address )['label' ], self .name )
188211
189212 assert_equal (
190213 node .getaddressesbylabel (self .name ),
191214 {address : {"purpose" : self .purpose [address ]} for address in self .addresses })
192- assert_equal (
193- set (node .getaddressesbyaccount (self .name )), set (self .addresses ))
215+ if self . accounts_api :
216+ assert_equal ( set (node .getaddressesbyaccount (self .name )), set (self .addresses ))
194217
195218
196219def change_label (node , address , old_label , new_label ):
0 commit comments