@@ -63,6 +63,12 @@ def assert_unspent(node, total_count=None, total_sum=None, reused_supported=None
63
63
if reused_sum is not None :
64
64
assert_approx (stats ["reused" ]["sum" ], reused_sum , 0.001 )
65
65
66
+ def assert_balances (node , mine ):
67
+ '''Make assertions about a node's getbalances output'''
68
+ got = node .getbalances ()["mine" ]
69
+ for k ,v in mine .items ():
70
+ assert_approx (got [k ], v , 0.001 )
71
+
66
72
class AvoidReuseTest (BitcoinTestFramework ):
67
73
68
74
def set_test_params (self ):
@@ -140,25 +146,35 @@ def test_fund_send_fund_senddirty(self):
140
146
141
147
# listunspent should show 1 single, unused 10 btc output
142
148
assert_unspent (self .nodes [1 ], total_count = 1 , total_sum = 10 , reused_supported = True , reused_count = 0 )
149
+ # getbalances should show no used, 10 btc trusted
150
+ assert_balances (self .nodes [1 ], mine = {"used" : 0 , "trusted" : 10 })
151
+ # node 0 should not show a used entry, as it does not enable avoid_reuse
152
+ assert ("used" not in self .nodes [0 ].getbalances ()["mine" ])
143
153
144
154
self .nodes [1 ].sendtoaddress (retaddr , 5 )
145
155
self .nodes [0 ].generate (1 )
146
156
self .sync_all ()
147
157
148
158
# listunspent should show 1 single, unused 5 btc output
149
159
assert_unspent (self .nodes [1 ], total_count = 1 , total_sum = 5 , reused_supported = True , reused_count = 0 )
160
+ # getbalances should show no used, 5 btc trusted
161
+ assert_balances (self .nodes [1 ], mine = {"used" : 0 , "trusted" : 5 })
150
162
151
163
self .nodes [0 ].sendtoaddress (fundaddr , 10 )
152
164
self .nodes [0 ].generate (1 )
153
165
self .sync_all ()
154
166
155
167
# listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10)
156
168
assert_unspent (self .nodes [1 ], total_count = 2 , total_sum = 15 , reused_count = 1 , reused_sum = 10 )
169
+ # getbalances should show 10 used, 5 btc trusted
170
+ assert_balances (self .nodes [1 ], mine = {"used" : 10 , "trusted" : 5 })
157
171
158
172
self .nodes [1 ].sendtoaddress (address = retaddr , amount = 10 , avoid_reuse = False )
159
173
160
174
# listunspent should show 1 total outputs (5 btc), unused
161
175
assert_unspent (self .nodes [1 ], total_count = 1 , total_sum = 5 , reused_count = 0 )
176
+ # getbalances should show no used, 5 btc trusted
177
+ assert_balances (self .nodes [1 ], mine = {"used" : 0 , "trusted" : 5 })
162
178
163
179
# node 1 should now have about 5 btc left (for both cases)
164
180
assert_approx (self .nodes [1 ].getbalance (), 5 , 0.001 )
@@ -183,20 +199,26 @@ def test_fund_send_fund_send(self):
183
199
184
200
# listunspent should show 1 single, unused 10 btc output
185
201
assert_unspent (self .nodes [1 ], total_count = 1 , total_sum = 10 , reused_supported = True , reused_count = 0 )
202
+ # getbalances should show no used, 10 btc trusted
203
+ assert_balances (self .nodes [1 ], mine = {"used" : 0 , "trusted" : 10 })
186
204
187
205
self .nodes [1 ].sendtoaddress (retaddr , 5 )
188
206
self .nodes [0 ].generate (1 )
189
207
self .sync_all ()
190
208
191
209
# listunspent should show 1 single, unused 5 btc output
192
210
assert_unspent (self .nodes [1 ], total_count = 1 , total_sum = 5 , reused_supported = True , reused_count = 0 )
211
+ # getbalances should show no used, 5 btc trusted
212
+ assert_balances (self .nodes [1 ], mine = {"used" : 0 , "trusted" : 5 })
193
213
194
214
self .nodes [0 ].sendtoaddress (fundaddr , 10 )
195
215
self .nodes [0 ].generate (1 )
196
216
self .sync_all ()
197
217
198
218
# listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10)
199
219
assert_unspent (self .nodes [1 ], total_count = 2 , total_sum = 15 , reused_count = 1 , reused_sum = 10 )
220
+ # getbalances should show 10 used, 5 btc trusted
221
+ assert_balances (self .nodes [1 ], mine = {"used" : 10 , "trusted" : 5 })
200
222
201
223
# node 1 should now have a balance of 5 (no dirty) or 15 (including dirty)
202
224
assert_approx (self .nodes [1 ].getbalance (), 5 , 0.001 )
@@ -208,6 +230,8 @@ def test_fund_send_fund_send(self):
208
230
209
231
# listunspent should show 2 total outputs (1, 10 btc), one unused (1), one reused (10)
210
232
assert_unspent (self .nodes [1 ], total_count = 2 , total_sum = 11 , reused_count = 1 , reused_sum = 10 )
233
+ # getbalances should show 10 used, 1 btc trusted
234
+ assert_balances (self .nodes [1 ], mine = {"used" : 10 , "trusted" : 1 })
211
235
212
236
# node 1 should now have about 1 btc left (no dirty) and 11 (including dirty)
213
237
assert_approx (self .nodes [1 ].getbalance (), 1 , 0.001 )
0 commit comments