Skip to content

Commit fa6fba3

Browse files
author
MarcoFalke
committed
test: Make local symbols in run_test members
1 parent 2f717fb commit fa6fba3

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

test/functional/rpc_fundrawtransaction.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ def setup_network(self):
4141
connect_nodes_bi(self.nodes, 0, 3)
4242

4343
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']
4545
# This test is not meant to test fee estimation and we'd like
4646
# to be sure all txs are sent at a consistent desired feerate
4747
for node in self.nodes:
48-
node.settxfee(min_relay_tx_fee)
48+
node.settxfee(self.min_relay_tx_fee)
4949

5050
# if the fee's positive delta is higher than this value tests will fail,
5151
# neg. delta always fail the tests.
5252
# The size of the signature of every input may be at most 2 bytes larger
5353
# than a minimum sized signature.
5454

5555
# = 2 bytes * minRelayTxFeePerByte
56-
feeTolerance = 2 * min_relay_tx_fee/1000
56+
self.fee_tolerance = 2 * self.min_relay_tx_fee / 1000
5757

5858
self.nodes[2].generate(1)
5959
self.sync_all()
@@ -67,15 +67,15 @@ def run_test(self):
6767

6868
watchonly_address = self.nodes[0].getnewaddress()
6969
watchonly_pubkey = self.nodes[0].getaddressinfo(watchonly_address)["pubkey"]
70-
watchonly_amount = Decimal(200)
70+
self.watchonly_amount = Decimal(200)
7171
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)
7373

7474
# 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}])
7777

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)
7979

8080
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5)
8181
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
@@ -156,6 +156,7 @@ def run_test(self):
156156

157157
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
158158
fee = rawtxfund['fee']
159+
self.test_no_change_fee = fee # Use the same fee for the next tx
159160
dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
160161
totalOut = 0
161162
for out in dec_tx['vout']:
@@ -170,7 +171,7 @@ def run_test(self):
170171
utx = get_unspent(self.nodes[2].listunspent(), 5)
171172

172173
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}
174175
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
175176
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
176177
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
@@ -363,7 +364,7 @@ def run_test(self):
363364

364365
#compare fee
365366
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
366-
assert feeDelta >= 0 and feeDelta <= feeTolerance
367+
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
367368
############################################################
368369

369370
############################################################
@@ -378,7 +379,7 @@ def run_test(self):
378379

379380
#compare fee
380381
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
381-
assert feeDelta >= 0 and feeDelta <= feeTolerance
382+
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
382383
############################################################
383384

384385

@@ -405,7 +406,7 @@ def run_test(self):
405406

406407
#compare fee
407408
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
408-
assert feeDelta >= 0 and feeDelta <= feeTolerance
409+
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
409410
############################################################
410411

411412

@@ -438,7 +439,7 @@ def run_test(self):
438439

439440
#compare fee
440441
feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
441-
assert feeDelta >= 0 and feeDelta <= feeTolerance
442+
assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
442443
############################################################
443444

444445

@@ -485,15 +486,15 @@ def run_test(self):
485486
# This test is not meant to test fee estimation and we'd like
486487
# to be sure all txs are sent at a consistent desired feerate
487488
for node in self.nodes:
488-
node.settxfee(min_relay_tx_fee)
489+
node.settxfee(self.min_relay_tx_fee)
489490

490491
connect_nodes_bi(self.nodes,0,1)
491492
connect_nodes_bi(self.nodes,1,2)
492493
connect_nodes_bi(self.nodes,0,2)
493494
connect_nodes_bi(self.nodes,0,3)
494495
# Again lock the watchonly UTXO or nodes[0] may spend it, because
495496
# 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}])
497498
self.sync_all()
498499

499500
# drain the keypool
@@ -558,7 +559,7 @@ def run_test(self):
558559

559560
#compare fee
560561
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
562563

563564

564565
#############################################
@@ -612,13 +613,13 @@ def run_test(self):
612613
##################################################
613614

614615
inputs = []
615-
outputs = {self.nodes[2].getnewaddress() : watchonly_amount / 2}
616+
outputs = {self.nodes[2].getnewaddress(): self.watchonly_amount / 2}
616617
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
617618

618619
result = self.nodes[3].fundrawtransaction(rawtx, {'includeWatching': True })
619620
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
620621
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)
622623

623624
assert "fee" in result.keys()
624625
assert_greater_than(result["changepos"], -1)
@@ -628,18 +629,18 @@ def run_test(self):
628629
###############################################################
629630

630631
inputs = []
631-
outputs = {self.nodes[2].getnewaddress() : watchonly_amount}
632+
outputs = {self.nodes[2].getnewaddress(): self.watchonly_amount}
632633
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
633634

634635
# Backward compatibility test (2nd param is includeWatching)
635636
result = self.nodes[3].fundrawtransaction(rawtx, True)
636637
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
637638
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
639640

640641
assert_greater_than(result["fee"], 0)
641642
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)
643644

644645
signedtx = self.nodes[3].signrawtransactionwithwallet(result["hex"])
645646
assert not signedtx["complete"]
@@ -659,9 +660,9 @@ def run_test(self):
659660
inputs = []
660661
outputs = {self.nodes[3].getnewaddress() : 1}
661662
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})
665666
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by -maxtxfee", self.nodes[3].fundrawtransaction, rawtx, {"feeRate": 1})
666667
result_fee_rate = result['fee'] * 1000 / count_bytes(result['hex'])
667668
assert_fee_amount(result2['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
@@ -671,6 +672,7 @@ def run_test(self):
671672
# Test no address reuse occurs #
672673
################################
673674

675+
rawtx = self.nodes[3].createrawtransaction(inputs=[], outputs={self.nodes[3].getnewaddress(): 1})
674676
result3 = self.nodes[3].fundrawtransaction(rawtx)
675677
res_dec = self.nodes[0].decoderawtransaction(result3["hex"])
676678
changeaddress = ""
@@ -693,11 +695,11 @@ def run_test(self):
693695
outputs = {self.nodes[2].getnewaddress(): 1}
694696
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
695697

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]}),]
701703

702704
dec_tx = [self.nodes[3].decoderawtransaction(tx_['hex']) for tx_ in result]
703705
output = [d['vout'][1 - r['changepos']]['value'] for d, r in zip(dec_tx, result)]

0 commit comments

Comments
 (0)