6
6
7
7
RPCs tested are:
8
8
- getlabeladdress
9
- - getaddressesbyaccount
9
+ - getaddressesbyaccount/getaddressesbylabel
10
10
- listaddressgroupings
11
11
- setlabel
12
12
- sendfrom (with account arguments)
13
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.
14
17
"""
15
18
from collections import defaultdict
16
19
17
20
from 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
19
22
20
23
class WalletLabelsTest (BitcoinTestFramework ):
21
24
def set_test_params (self ):
22
25
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 ()
25
32
26
33
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 ):
28
41
# Check that there's no UTXO on any of the nodes
29
42
assert_equal (len (node .listunspent ()), 0 )
30
43
@@ -77,7 +90,7 @@ def run_test(self):
77
90
78
91
# Create labels and make sure subsequent label API calls
79
92
# 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" )]
81
94
for label in labels :
82
95
label .add_receive_address (node .getlabeladdress (label = label .name , force = True ))
83
96
label .verify (node )
@@ -101,29 +114,34 @@ def run_test(self):
101
114
102
115
# Check that sendfrom label reduces listaccounts balances.
103
116
for i , label in enumerate (labels ):
104
- to_label = labels [(i + 1 ) % len (labels )]
117
+ to_label = labels [(i + 1 ) % len (labels )]
105
118
node .sendfrom (label .name , to_label .receive_address , amount_to_send )
106
119
node .generate (1 )
107
120
for label in labels :
108
121
label .add_receive_address (node .getlabeladdress (label .name ))
109
122
label .verify (node )
110
123
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 ))
112
126
label .verify (node )
113
127
node .generate (101 )
114
128
expected_account_balances = {"" : 5200 }
115
129
for label in labels :
116
130
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 )
119
134
120
135
# Check that setlabel can assign a label to a new unused address.
121
136
for label in labels :
122
137
address = node .getlabeladdress (label = "" , force = True )
123
138
node .setlabel (address , label .name )
124
139
label .add_address (address )
125
140
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 , "" )
127
145
128
146
# Check that addmultisigaddress can assign labels.
129
147
for label in labels :
@@ -136,8 +154,9 @@ def run_test(self):
136
154
label .verify (node )
137
155
node .sendfrom ("" , multisig_address , 50 )
138
156
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 )
141
160
142
161
# Check that setlabel can change the label of an address from a
143
162
# different label.
@@ -156,9 +175,10 @@ def run_test(self):
156
175
change_label (node , labels [2 ].receive_address , labels [2 ], labels [2 ])
157
176
158
177
class Label :
159
- def __init__ (self , name ):
178
+ def __init__ (self , name , accounts_api ):
160
179
# Label name
161
180
self .name = name
181
+ self .accounts_api = accounts_api
162
182
# Current receiving address associated with this label.
163
183
self .receive_address = None
164
184
# List of all addresses assigned with this label
@@ -184,13 +204,16 @@ def verify(self, node):
184
204
node .getaddressinfo (address )['labels' ][0 ],
185
205
{"name" : self .name ,
186
206
"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 )
188
211
189
212
assert_equal (
190
213
node .getaddressesbylabel (self .name ),
191
214
{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 ))
194
217
195
218
196
219
def change_label (node , address , old_label , new_label ):
0 commit comments