55"""Test label RPCs.
66
77RPCs tested are:
8- - getaccountaddress
9- - getaddressesbyaccount/getaddressesbylabel
8+ - getaddressesbylabel
109 - listaddressgroupings
1110 - setlabel
12- - sendfrom (with account arguments)
13- - 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.
1711"""
1812from collections import defaultdict
1913
2317class WalletLabelsTest (BitcoinTestFramework ):
2418 def set_test_params (self ):
2519 self .setup_clean_chain = True
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 ()
20+ self .num_nodes = 1
3221
3322 def run_test (self ):
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 ):
41- # Check that there's no UTXO on any of the nodes
23+ # Check that there's no UTXO on the node
24+ node = self .nodes [0 ]
4225 assert_equal (len (node .listunspent ()), 0 )
4326
4427 # Note each time we call generate, all generated coins go into
@@ -61,17 +44,12 @@ def _run_subtest(self, accounts_api, node):
6144 linked_addresses .add (address_group [0 ][0 ])
6245
6346 # send 50 from each address to a third address not in this wallet
64- # There's some fee that will come back to us when the miner reward
65- # matures.
6647 common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr"
67- txid = node .sendmany (
68- fromaccount = "" ,
48+ node .sendmany (
6949 amounts = {common_address : 100 },
7050 subtractfeefrom = [common_address ],
7151 minconf = 1 ,
7252 )
73- tx_details = node .gettransaction (txid )
74- fee = - tx_details ['details' ][0 ]['fee' ]
7553 # there should be 1 address group, with the previously
7654 # unlinked addresses now linked (they both have 0 balance)
7755 address_groups = node .listaddressgroupings ()
@@ -85,32 +63,22 @@ def _run_subtest(self, accounts_api, node):
8563 # we want to reset so that the "" label has what's expected.
8664 # otherwise we're off by exactly the fee amount as that's mined
8765 # and matures in the next 100 blocks
88- if accounts_api :
89- node .sendfrom ("" , common_address , fee )
9066 amount_to_send = 1.0
9167
9268 # Create labels and make sure subsequent label API calls
9369 # recognize the label/address associations.
94- labels = [Label (name , accounts_api ) for name in ("a" , "b" , "c" , "d" , "e" )]
70+ labels = [Label (name ) for name in ("a" , "b" , "c" , "d" , "e" )]
9571 for label in labels :
96- if accounts_api :
97- address = node .getaccountaddress (label .name )
98- else :
99- address = node .getnewaddress (label .name )
72+ address = node .getnewaddress (label .name )
10073 label .add_receive_address (address )
10174 label .verify (node )
10275
10376 # Check all labels are returned by listlabels.
10477 assert_equal (node .listlabels (), [label .name for label in labels ])
10578
106- # Send a transaction to each label, and make sure this forces
107- # getaccountaddress to generate a new receiving address.
79+ # Send a transaction to each label.
10880 for label in labels :
109- if accounts_api :
110- node .sendtoaddress (label .receive_address , amount_to_send )
111- label .add_receive_address (node .getaccountaddress (label .name ))
112- else :
113- node .sendtoaddress (label .addresses [0 ], amount_to_send )
81+ node .sendtoaddress (label .addresses [0 ], amount_to_send )
11482 label .verify (node )
11583
11684 # Check the amounts received.
@@ -120,43 +88,25 @@ def _run_subtest(self, accounts_api, node):
12088 node .getreceivedbyaddress (label .addresses [0 ]), amount_to_send )
12189 assert_equal (node .getreceivedbylabel (label .name ), amount_to_send )
12290
123- # Check that sendfrom label reduces listaccounts balances.
12491 for i , label in enumerate (labels ):
12592 to_label = labels [(i + 1 ) % len (labels )]
126- if accounts_api :
127- node .sendfrom (label .name , to_label .receive_address , amount_to_send )
128- else :
129- node .sendtoaddress (to_label .addresses [0 ], amount_to_send )
93+ node .sendtoaddress (to_label .addresses [0 ], amount_to_send )
13094 node .generate (1 )
13195 for label in labels :
132- if accounts_api :
133- address = node .getaccountaddress (label .name )
134- else :
135- address = node .getnewaddress (label .name )
96+ address = node .getnewaddress (label .name )
13697 label .add_receive_address (address )
13798 label .verify (node )
13899 assert_equal (node .getreceivedbylabel (label .name ), 2 )
139- if accounts_api :
140- node .move (label .name , "" , node .getbalance (label .name ))
141100 label .verify (node )
142101 node .generate (101 )
143- expected_account_balances = {"" : 5200 }
144- for label in labels :
145- expected_account_balances [label .name ] = 0
146- if accounts_api :
147- assert_equal (node .listaccounts (), expected_account_balances )
148- assert_equal (node .getbalance ("" ), 5200 )
149102
150103 # Check that setlabel can assign a label to a new unused address.
151104 for label in labels :
152105 address = node .getnewaddress ()
153106 node .setlabel (address , label .name )
154107 label .add_address (address )
155108 label .verify (node )
156- if accounts_api :
157- assert address not in node .getaddressesbyaccount ("" )
158- else :
159- assert_raises_rpc_error (- 11 , "No addresses with label" , node .getaddressesbylabel , "" )
109+ assert_raises_rpc_error (- 11 , "No addresses with label" , node .getaddressesbylabel , "" )
160110
161111 # Check that addmultisigaddress can assign labels.
162112 for label in labels :
@@ -167,35 +117,20 @@ def _run_subtest(self, accounts_api, node):
167117 label .add_address (multisig_address )
168118 label .purpose [multisig_address ] = "send"
169119 label .verify (node )
170- if accounts_api :
171- node .sendfrom ("" , multisig_address , 50 )
172120 node .generate (101 )
173- if accounts_api :
174- for label in labels :
175- assert_equal (node .getbalance (label .name ), 50 )
176121
177122 # Check that setlabel can change the label of an address from a
178123 # different label.
179- change_label (node , labels [0 ].addresses [0 ], labels [0 ], labels [1 ], accounts_api )
124+ change_label (node , labels [0 ].addresses [0 ], labels [0 ], labels [1 ])
180125
181126 # Check that setlabel can set the label of an address already
182127 # in the label. This is a no-op.
183- change_label (node , labels [2 ].addresses [0 ], labels [2 ], labels [2 ], accounts_api )
184-
185- if accounts_api :
186- # Check that setaccount can change the label of an address which
187- # is the receiving address of a different label.
188- change_label (node , labels [0 ].receive_address , labels [0 ], labels [1 ], accounts_api )
189-
190- # Check that setaccount can set the label of an address which is
191- # already the receiving address of the label. This is a no-op.
192- change_label (node , labels [2 ].receive_address , labels [2 ], labels [2 ], accounts_api )
128+ change_label (node , labels [2 ].addresses [0 ], labels [2 ], labels [2 ])
193129
194130class Label :
195- def __init__ (self , name , accounts_api ):
131+ def __init__ (self , name ):
196132 # Label name
197133 self .name = name
198- self .accounts_api = accounts_api
199134 # Current receiving address associated with this label.
200135 self .receive_address = None
201136 # List of all addresses assigned with this label
@@ -209,56 +144,31 @@ def add_address(self, address):
209144
210145 def add_receive_address (self , address ):
211146 self .add_address (address )
212- if self .accounts_api :
213- self .receive_address = address
214147
215148 def verify (self , node ):
216149 if self .receive_address is not None :
217150 assert self .receive_address in self .addresses
218- if self .accounts_api :
219- assert_equal (node .getaccountaddress (self .name ), self .receive_address )
220151
221152 for address in self .addresses :
222153 assert_equal (
223154 node .getaddressinfo (address )['labels' ][0 ],
224155 {"name" : self .name ,
225156 "purpose" : self .purpose [address ]})
226- if self .accounts_api :
227- assert_equal (node .getaccount (address ), self .name )
228- else :
229- assert_equal (node .getaddressinfo (address )['label' ], self .name )
157+ assert_equal (node .getaddressinfo (address )['label' ], self .name )
230158
231159 assert_equal (
232160 node .getaddressesbylabel (self .name ),
233161 {address : {"purpose" : self .purpose [address ]} for address in self .addresses })
234- if self .accounts_api :
235- assert_equal (set (node .getaddressesbyaccount (self .name )), set (self .addresses ))
236-
237162
238- def change_label (node , address , old_label , new_label , accounts_api ):
163+ def change_label (node , address , old_label , new_label ):
239164 assert_equal (address in old_label .addresses , True )
240- if accounts_api :
241- node .setaccount (address , new_label .name )
242- else :
243- node .setlabel (address , new_label .name )
165+ node .setlabel (address , new_label .name )
244166
245167 old_label .addresses .remove (address )
246168 new_label .add_address (address )
247169
248- # Calling setaccount on an address which was previously the receiving
249- # address of a different account should reset the receiving address of
250- # the old account, causing getaccountaddress to return a brand new
251- # address.
252- if accounts_api :
253- if old_label .name != new_label .name and address == old_label .receive_address :
254- new_address = node .getaccountaddress (old_label .name )
255- assert_equal (new_address not in old_label .addresses , True )
256- assert_equal (new_address not in new_label .addresses , True )
257- old_label .add_receive_address (new_address )
258-
259170 old_label .verify (node )
260171 new_label .verify (node )
261172
262-
263173if __name__ == '__main__' :
264174 WalletLabelsTest ().main ()
0 commit comments