@@ -42,25 +42,25 @@ def count_unspent(node):
42
42
r ["reused" ]["supported" ] = supports_reused
43
43
return r
44
44
45
- def assert_unspent (node , total_count = None , total_sum = None , reused_supported = None , reused_count = None , reused_sum = None ):
45
+ def assert_unspent (node , total_count = None , total_sum = None , reused_supported = None , reused_count = None , reused_sum = None , margin = 0.001 ):
46
46
'''Make assertions about a node's unspent output statistics'''
47
47
stats = count_unspent (node )
48
48
if total_count is not None :
49
49
assert_equal (stats ["total" ]["count" ], total_count )
50
50
if total_sum is not None :
51
- assert_approx (stats ["total" ]["sum" ], total_sum , 0.001 )
51
+ assert_approx (stats ["total" ]["sum" ], total_sum , margin )
52
52
if reused_supported is not None :
53
53
assert_equal (stats ["reused" ]["supported" ], reused_supported )
54
54
if reused_count is not None :
55
55
assert_equal (stats ["reused" ]["count" ], reused_count )
56
56
if reused_sum is not None :
57
- assert_approx (stats ["reused" ]["sum" ], reused_sum , 0.001 )
57
+ assert_approx (stats ["reused" ]["sum" ], reused_sum , margin )
58
58
59
- def assert_balances (node , mine ):
59
+ def assert_balances (node , mine , margin = 0.001 ):
60
60
'''Make assertions about a node's getbalances output'''
61
61
got = node .getbalances ()["mine" ]
62
62
for k ,v in mine .items ():
63
- assert_approx (got [k ], v , 0.001 )
63
+ assert_approx (got [k ], v , margin )
64
64
65
65
class AvoidReuseTest (BitcoinTestFramework ):
66
66
@@ -299,7 +299,7 @@ def test_getbalances_used(self):
299
299
ret_addr = self .nodes [0 ].getnewaddress ()
300
300
301
301
# send multiple transactions, reusing one address
302
- for _ in range (11 ):
302
+ for _ in range (101 ):
303
303
self .nodes [0 ].sendtoaddress (new_addr , 1 )
304
304
305
305
self .nodes [0 ].generate (1 )
@@ -311,14 +311,14 @@ def test_getbalances_used(self):
311
311
312
312
# getbalances and listunspent should show the remaining outputs
313
313
# in the reused address as used/reused
314
- assert_unspent (self .nodes [1 ], total_count = 2 , total_sum = 6 , reused_count = 1 , reused_sum = 1 )
315
- assert_balances (self .nodes [1 ], mine = {"used" : 1 , "trusted" : 5 } )
314
+ assert_unspent (self .nodes [1 ], total_count = 2 , total_sum = 96 , reused_count = 1 , reused_sum = 1 , margin = 0.01 )
315
+ assert_balances (self .nodes [1 ], mine = {"used" : 1 , "trusted" : 95 }, margin = 0.01 )
316
316
317
317
def test_full_destination_group_is_preferred (self ):
318
318
'''
319
- Test the case where [1] only has 11 outputs of 1 BTC in the same reused
319
+ Test the case where [1] only has 101 outputs of 1 BTC in the same reused
320
320
address and tries to send a small payment of 0.5 BTC. The wallet
321
- should use 10 outputs from the reused address as inputs and not a
321
+ should use 100 outputs from the reused address as inputs and not a
322
322
single 1 BTC input, in order to join several outputs from the reused
323
323
address.
324
324
'''
@@ -330,8 +330,8 @@ def test_full_destination_group_is_preferred(self):
330
330
new_addr = self .nodes [1 ].getnewaddress ()
331
331
ret_addr = self .nodes [0 ].getnewaddress ()
332
332
333
- # Send 11 outputs of 1 BTC to the same, reused address in the wallet
334
- for _ in range (11 ):
333
+ # Send 101 outputs of 1 BTC to the same, reused address in the wallet
334
+ for _ in range (101 ):
335
335
self .nodes [0 ].sendtoaddress (new_addr , 1 )
336
336
337
337
self .nodes [0 ].generate (1 )
@@ -342,14 +342,14 @@ def test_full_destination_group_is_preferred(self):
342
342
txid = self .nodes [1 ].sendtoaddress (address = ret_addr , amount = 0.5 )
343
343
inputs = self .nodes [1 ].getrawtransaction (txid , 1 )["vin" ]
344
344
345
- # The transaction should use 10 inputs exactly
346
- assert_equal (len (inputs ), 10 )
345
+ # The transaction should use 100 inputs exactly
346
+ assert_equal (len (inputs ), 100 )
347
347
348
348
def test_all_destination_groups_are_used (self ):
349
349
'''
350
- Test the case where [1] only has 22 outputs of 1 BTC in the same reused
351
- address and tries to send a payment of 20 .5 BTC. The wallet
352
- should use all 22 outputs from the reused address as inputs.
350
+ Test the case where [1] only has 202 outputs of 1 BTC in the same reused
351
+ address and tries to send a payment of 200 .5 BTC. The wallet
352
+ should use all 202 outputs from the reused address as inputs.
353
353
'''
354
354
self .log .info ("Test that all destination groups are used" )
355
355
@@ -359,20 +359,20 @@ def test_all_destination_groups_are_used(self):
359
359
new_addr = self .nodes [1 ].getnewaddress ()
360
360
ret_addr = self .nodes [0 ].getnewaddress ()
361
361
362
- # Send 22 outputs of 1 BTC to the same, reused address in the wallet
363
- for _ in range (22 ):
362
+ # Send 202 outputs of 1 BTC to the same, reused address in the wallet
363
+ for _ in range (202 ):
364
364
self .nodes [0 ].sendtoaddress (new_addr , 1 )
365
365
366
366
self .nodes [0 ].generate (1 )
367
367
self .sync_all ()
368
368
369
369
# Sending a transaction that needs to use the full groups
370
- # of 10 inputs but also the incomplete group of 2 inputs.
371
- txid = self .nodes [1 ].sendtoaddress (address = ret_addr , amount = 20 .5 )
370
+ # of 100 inputs but also the incomplete group of 2 inputs.
371
+ txid = self .nodes [1 ].sendtoaddress (address = ret_addr , amount = 200 .5 )
372
372
inputs = self .nodes [1 ].getrawtransaction (txid , 1 )["vin" ]
373
373
374
- # The transaction should use 22 inputs exactly
375
- assert_equal (len (inputs ), 22 )
374
+ # The transaction should use 202 inputs exactly
375
+ assert_equal (len (inputs ), 202 )
376
376
377
377
378
378
if __name__ == '__main__' :
0 commit comments