5
5
"""Test label RPCs.
6
6
7
7
RPCs tested are:
8
- - getaccountaddress
9
- - getaddressesbyaccount/getaddressesbylabel
8
+ - getaddressesbylabel
10
9
- listaddressgroupings
11
10
- 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.
17
11
"""
18
12
from collections import defaultdict
19
13
23
17
class WalletLabelsTest (BitcoinTestFramework ):
24
18
def set_test_params (self ):
25
19
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
32
21
33
22
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 ]
42
25
assert_equal (len (node .listunspent ()), 0 )
43
26
44
27
# Note each time we call generate, all generated coins go into
@@ -61,17 +44,12 @@ def _run_subtest(self, accounts_api, node):
61
44
linked_addresses .add (address_group [0 ][0 ])
62
45
63
46
# 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.
66
47
common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr"
67
- txid = node .sendmany (
68
- fromaccount = "" ,
48
+ node .sendmany (
69
49
amounts = {common_address : 100 },
70
50
subtractfeefrom = [common_address ],
71
51
minconf = 1 ,
72
52
)
73
- tx_details = node .gettransaction (txid )
74
- fee = - tx_details ['details' ][0 ]['fee' ]
75
53
# there should be 1 address group, with the previously
76
54
# unlinked addresses now linked (they both have 0 balance)
77
55
address_groups = node .listaddressgroupings ()
@@ -85,32 +63,22 @@ def _run_subtest(self, accounts_api, node):
85
63
# we want to reset so that the "" label has what's expected.
86
64
# otherwise we're off by exactly the fee amount as that's mined
87
65
# and matures in the next 100 blocks
88
- if accounts_api :
89
- node .sendfrom ("" , common_address , fee )
90
66
amount_to_send = 1.0
91
67
92
68
# Create labels and make sure subsequent label API calls
93
69
# 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" )]
95
71
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 )
100
73
label .add_receive_address (address )
101
74
label .verify (node )
102
75
103
76
# Check all labels are returned by listlabels.
104
77
assert_equal (node .listlabels (), [label .name for label in labels ])
105
78
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.
108
80
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 )
114
82
label .verify (node )
115
83
116
84
# Check the amounts received.
@@ -120,43 +88,25 @@ def _run_subtest(self, accounts_api, node):
120
88
node .getreceivedbyaddress (label .addresses [0 ]), amount_to_send )
121
89
assert_equal (node .getreceivedbylabel (label .name ), amount_to_send )
122
90
123
- # Check that sendfrom label reduces listaccounts balances.
124
91
for i , label in enumerate (labels ):
125
92
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 )
130
94
node .generate (1 )
131
95
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 )
136
97
label .add_receive_address (address )
137
98
label .verify (node )
138
99
assert_equal (node .getreceivedbylabel (label .name ), 2 )
139
- if accounts_api :
140
- node .move (label .name , "" , node .getbalance (label .name ))
141
100
label .verify (node )
142
101
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 )
149
102
150
103
# Check that setlabel can assign a label to a new unused address.
151
104
for label in labels :
152
105
address = node .getnewaddress ()
153
106
node .setlabel (address , label .name )
154
107
label .add_address (address )
155
108
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 , "" )
160
110
161
111
# Check that addmultisigaddress can assign labels.
162
112
for label in labels :
@@ -167,35 +117,20 @@ def _run_subtest(self, accounts_api, node):
167
117
label .add_address (multisig_address )
168
118
label .purpose [multisig_address ] = "send"
169
119
label .verify (node )
170
- if accounts_api :
171
- node .sendfrom ("" , multisig_address , 50 )
172
120
node .generate (101 )
173
- if accounts_api :
174
- for label in labels :
175
- assert_equal (node .getbalance (label .name ), 50 )
176
121
177
122
# Check that setlabel can change the label of an address from a
178
123
# 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 ])
180
125
181
126
# Check that setlabel can set the label of an address already
182
127
# 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 ])
193
129
194
130
class Label :
195
- def __init__ (self , name , accounts_api ):
131
+ def __init__ (self , name ):
196
132
# Label name
197
133
self .name = name
198
- self .accounts_api = accounts_api
199
134
# Current receiving address associated with this label.
200
135
self .receive_address = None
201
136
# List of all addresses assigned with this label
@@ -209,56 +144,31 @@ def add_address(self, address):
209
144
210
145
def add_receive_address (self , address ):
211
146
self .add_address (address )
212
- if self .accounts_api :
213
- self .receive_address = address
214
147
215
148
def verify (self , node ):
216
149
if self .receive_address is not None :
217
150
assert self .receive_address in self .addresses
218
- if self .accounts_api :
219
- assert_equal (node .getaccountaddress (self .name ), self .receive_address )
220
151
221
152
for address in self .addresses :
222
153
assert_equal (
223
154
node .getaddressinfo (address )['labels' ][0 ],
224
155
{"name" : self .name ,
225
156
"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 )
230
158
231
159
assert_equal (
232
160
node .getaddressesbylabel (self .name ),
233
161
{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
-
237
162
238
- def change_label (node , address , old_label , new_label , accounts_api ):
163
+ def change_label (node , address , old_label , new_label ):
239
164
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 )
244
166
245
167
old_label .addresses .remove (address )
246
168
new_label .add_address (address )
247
169
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
-
259
170
old_label .verify (node )
260
171
new_label .verify (node )
261
172
262
-
263
173
if __name__ == '__main__' :
264
174
WalletLabelsTest ().main ()
0 commit comments