@@ -41,19 +41,19 @@ def setup_network(self):
41
41
connect_nodes_bi (self .nodes , 0 , 3 )
42
42
43
43
def run_test (self ):
44
- min_relay_tx_fee = self .nodes [0 ].getnetworkinfo ()['relayfee' ]
44
+ self . min_relay_tx_fee = self .nodes [0 ].getnetworkinfo ()['relayfee' ]
45
45
# This test is not meant to test fee estimation and we'd like
46
46
# to be sure all txs are sent at a consistent desired feerate
47
47
for node in self .nodes :
48
- node .settxfee (min_relay_tx_fee )
48
+ node .settxfee (self . min_relay_tx_fee )
49
49
50
50
# if the fee's positive delta is higher than this value tests will fail,
51
51
# neg. delta always fail the tests.
52
52
# The size of the signature of every input may be at most 2 bytes larger
53
53
# than a minimum sized signature.
54
54
55
55
# = 2 bytes * minRelayTxFeePerByte
56
- feeTolerance = 2 * min_relay_tx_fee / 1000
56
+ self . fee_tolerance = 2 * self . min_relay_tx_fee / 1000
57
57
58
58
self .nodes [2 ].generate (1 )
59
59
self .sync_all ()
@@ -67,15 +67,15 @@ def run_test(self):
67
67
68
68
watchonly_address = self .nodes [0 ].getnewaddress ()
69
69
watchonly_pubkey = self .nodes [0 ].getaddressinfo (watchonly_address )["pubkey" ]
70
- watchonly_amount = Decimal (200 )
70
+ self . watchonly_amount = Decimal (200 )
71
71
self .nodes [3 ].importpubkey (watchonly_pubkey , "" , True )
72
- watchonly_txid = self .nodes [0 ].sendtoaddress (watchonly_address , watchonly_amount )
72
+ self . watchonly_txid = self .nodes [0 ].sendtoaddress (watchonly_address , self . watchonly_amount )
73
73
74
74
# Lock UTXO so nodes[0] doesn't accidentally spend it
75
- watchonly_vout = find_vout_for_address (self .nodes [0 ], watchonly_txid , watchonly_address )
76
- self .nodes [0 ].lockunspent (False , [{"txid" : watchonly_txid , "vout" : watchonly_vout }])
75
+ self . watchonly_vout = find_vout_for_address (self .nodes [0 ], self . watchonly_txid , watchonly_address )
76
+ self .nodes [0 ].lockunspent (False , [{"txid" : self . watchonly_txid , "vout" : self . watchonly_vout }])
77
77
78
- self .nodes [0 ].sendtoaddress (self .nodes [3 ].getnewaddress (), watchonly_amount / 10 )
78
+ self .nodes [0 ].sendtoaddress (self .nodes [3 ].getnewaddress (), self . watchonly_amount / 10 )
79
79
80
80
self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 1.5 )
81
81
self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 1.0 )
@@ -156,6 +156,7 @@ def run_test(self):
156
156
157
157
rawtxfund = self .nodes [2 ].fundrawtransaction (rawtx )
158
158
fee = rawtxfund ['fee' ]
159
+ self .test_no_change_fee = fee # Use the same fee for the next tx
159
160
dec_tx = self .nodes [2 ].decoderawtransaction (rawtxfund ['hex' ])
160
161
totalOut = 0
161
162
for out in dec_tx ['vout' ]:
@@ -170,7 +171,7 @@ def run_test(self):
170
171
utx = get_unspent (self .nodes [2 ].listunspent (), 5 )
171
172
172
173
inputs = [ {'txid' : utx ['txid' ], 'vout' : utx ['vout' ]}]
173
- outputs = { self .nodes [0 ].getnewaddress () : Decimal (5.0 ) - fee - feeTolerance }
174
+ outputs = {self .nodes [0 ].getnewaddress (): Decimal (5.0 ) - self . test_no_change_fee - self . fee_tolerance }
174
175
rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
175
176
dec_tx = self .nodes [2 ].decoderawtransaction (rawtx )
176
177
assert_equal (utx ['txid' ], dec_tx ['vin' ][0 ]['txid' ])
@@ -363,7 +364,7 @@ def run_test(self):
363
364
364
365
#compare fee
365
366
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
366
- assert feeDelta >= 0 and feeDelta <= feeTolerance
367
+ assert feeDelta >= 0 and feeDelta <= self . fee_tolerance
367
368
############################################################
368
369
369
370
############################################################
@@ -378,7 +379,7 @@ def run_test(self):
378
379
379
380
#compare fee
380
381
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
381
- assert feeDelta >= 0 and feeDelta <= feeTolerance
382
+ assert feeDelta >= 0 and feeDelta <= self . fee_tolerance
382
383
############################################################
383
384
384
385
@@ -405,7 +406,7 @@ def run_test(self):
405
406
406
407
#compare fee
407
408
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
408
- assert feeDelta >= 0 and feeDelta <= feeTolerance
409
+ assert feeDelta >= 0 and feeDelta <= self . fee_tolerance
409
410
############################################################
410
411
411
412
@@ -438,7 +439,7 @@ def run_test(self):
438
439
439
440
#compare fee
440
441
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
441
- assert feeDelta >= 0 and feeDelta <= feeTolerance
442
+ assert feeDelta >= 0 and feeDelta <= self . fee_tolerance
442
443
############################################################
443
444
444
445
@@ -485,15 +486,15 @@ def run_test(self):
485
486
# This test is not meant to test fee estimation and we'd like
486
487
# to be sure all txs are sent at a consistent desired feerate
487
488
for node in self .nodes :
488
- node .settxfee (min_relay_tx_fee )
489
+ node .settxfee (self . min_relay_tx_fee )
489
490
490
491
connect_nodes_bi (self .nodes ,0 ,1 )
491
492
connect_nodes_bi (self .nodes ,1 ,2 )
492
493
connect_nodes_bi (self .nodes ,0 ,2 )
493
494
connect_nodes_bi (self .nodes ,0 ,3 )
494
495
# Again lock the watchonly UTXO or nodes[0] may spend it, because
495
496
# lockunspent is memory-only and thus lost on restart
496
- self .nodes [0 ].lockunspent (False , [{"txid" : watchonly_txid , "vout" : watchonly_vout }])
497
+ self .nodes [0 ].lockunspent (False , [{"txid" : self . watchonly_txid , "vout" : self . watchonly_vout }])
497
498
self .sync_all ()
498
499
499
500
# drain the keypool
@@ -558,7 +559,7 @@ def run_test(self):
558
559
559
560
#compare fee
560
561
feeDelta = Decimal (fundedTx ['fee' ]) - Decimal (signedFee )
561
- assert feeDelta >= 0 and feeDelta <= feeTolerance * 19 #~19 inputs
562
+ assert feeDelta >= 0 and feeDelta <= self . fee_tolerance * 19 #~19 inputs
562
563
563
564
564
565
#############################################
@@ -612,13 +613,13 @@ def run_test(self):
612
613
##################################################
613
614
614
615
inputs = []
615
- outputs = {self .nodes [2 ].getnewaddress () : watchonly_amount / 2 }
616
+ outputs = {self .nodes [2 ].getnewaddress (): self . watchonly_amount / 2 }
616
617
rawtx = self .nodes [3 ].createrawtransaction (inputs , outputs )
617
618
618
619
result = self .nodes [3 ].fundrawtransaction (rawtx , {'includeWatching' : True })
619
620
res_dec = self .nodes [0 ].decoderawtransaction (result ["hex" ])
620
621
assert_equal (len (res_dec ["vin" ]), 1 )
621
- assert_equal (res_dec ["vin" ][0 ]["txid" ], watchonly_txid )
622
+ assert_equal (res_dec ["vin" ][0 ]["txid" ], self . watchonly_txid )
622
623
623
624
assert "fee" in result .keys ()
624
625
assert_greater_than (result ["changepos" ], - 1 )
@@ -628,18 +629,18 @@ def run_test(self):
628
629
###############################################################
629
630
630
631
inputs = []
631
- outputs = {self .nodes [2 ].getnewaddress () : watchonly_amount }
632
+ outputs = {self .nodes [2 ].getnewaddress (): self . watchonly_amount }
632
633
rawtx = self .nodes [3 ].createrawtransaction (inputs , outputs )
633
634
634
635
# Backward compatibility test (2nd param is includeWatching)
635
636
result = self .nodes [3 ].fundrawtransaction (rawtx , True )
636
637
res_dec = self .nodes [0 ].decoderawtransaction (result ["hex" ])
637
638
assert_equal (len (res_dec ["vin" ]), 2 )
638
- assert res_dec ["vin" ][0 ]["txid" ] == watchonly_txid or res_dec ["vin" ][1 ]["txid" ] == watchonly_txid
639
+ assert res_dec ["vin" ][0 ]["txid" ] == self . watchonly_txid or res_dec ["vin" ][1 ]["txid" ] == self . watchonly_txid
639
640
640
641
assert_greater_than (result ["fee" ], 0 )
641
642
assert_greater_than (result ["changepos" ], - 1 )
642
- assert_equal (result ["fee" ] + res_dec ["vout" ][result ["changepos" ]]["value" ], watchonly_amount / 10 )
643
+ assert_equal (result ["fee" ] + res_dec ["vout" ][result ["changepos" ]]["value" ], self . watchonly_amount / 10 )
643
644
644
645
signedtx = self .nodes [3 ].signrawtransactionwithwallet (result ["hex" ])
645
646
assert not signedtx ["complete" ]
@@ -659,9 +660,9 @@ def run_test(self):
659
660
inputs = []
660
661
outputs = {self .nodes [3 ].getnewaddress () : 1 }
661
662
rawtx = self .nodes [3 ].createrawtransaction (inputs , outputs )
662
- result = self .nodes [3 ].fundrawtransaction (rawtx ) # uses min_relay_tx_fee (set by settxfee)
663
- result2 = self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 2 * min_relay_tx_fee })
664
- result3 = self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 10 * min_relay_tx_fee })
663
+ result = self .nodes [3 ].fundrawtransaction (rawtx ) # uses self. min_relay_tx_fee (set by settxfee)
664
+ result2 = self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 2 * self . min_relay_tx_fee })
665
+ result3 = self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 10 * self . min_relay_tx_fee })
665
666
assert_raises_rpc_error (- 4 , "Fee exceeds maximum configured by -maxtxfee" , self .nodes [3 ].fundrawtransaction , rawtx , {"feeRate" : 1 })
666
667
result_fee_rate = result ['fee' ] * 1000 / count_bytes (result ['hex' ])
667
668
assert_fee_amount (result2 ['fee' ], count_bytes (result2 ['hex' ]), 2 * result_fee_rate )
@@ -671,6 +672,7 @@ def run_test(self):
671
672
# Test no address reuse occurs #
672
673
################################
673
674
675
+ rawtx = self .nodes [3 ].createrawtransaction (inputs = [], outputs = {self .nodes [3 ].getnewaddress (): 1 })
674
676
result3 = self .nodes [3 ].fundrawtransaction (rawtx )
675
677
res_dec = self .nodes [0 ].decoderawtransaction (result3 ["hex" ])
676
678
changeaddress = ""
@@ -693,11 +695,11 @@ def run_test(self):
693
695
outputs = {self .nodes [2 ].getnewaddress (): 1 }
694
696
rawtx = self .nodes [3 ].createrawtransaction (inputs , outputs )
695
697
696
- result = [self .nodes [3 ].fundrawtransaction (rawtx ), # uses min_relay_tx_fee (set by settxfee)
697
- self .nodes [3 ].fundrawtransaction (rawtx , {"subtractFeeFromOutputs" : []}), # empty subtraction list
698
- self .nodes [3 ].fundrawtransaction (rawtx , {"subtractFeeFromOutputs" : [0 ]}), # uses min_relay_tx_fee (set by settxfee)
699
- self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 2 * min_relay_tx_fee }),
700
- self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 2 * min_relay_tx_fee , "subtractFeeFromOutputs" : [0 ]})]
698
+ result = [self .nodes [3 ].fundrawtransaction (rawtx ), # uses self. min_relay_tx_fee (set by settxfee)
699
+ self .nodes [3 ].fundrawtransaction (rawtx , {"subtractFeeFromOutputs" : []}), # empty subtraction list
700
+ self .nodes [3 ].fundrawtransaction (rawtx , {"subtractFeeFromOutputs" : [0 ]}), # uses self. min_relay_tx_fee (set by settxfee)
701
+ self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 2 * self . min_relay_tx_fee }),
702
+ self .nodes [3 ].fundrawtransaction (rawtx , {"feeRate" : 2 * self . min_relay_tx_fee , "subtractFeeFromOutputs" : [0 ]}), ]
701
703
702
704
dec_tx = [self .nodes [3 ].decoderawtransaction (tx_ ['hex' ]) for tx_ in result ]
703
705
output = [d ['vout' ][1 - r ['changepos' ]]['value' ] for d , r in zip (dec_tx , result )]
0 commit comments