Skip to content

Commit 95d7de0

Browse files
committed
test: Update python tests to use named parameters instead of options objects
1 parent 9623314 commit 95d7de0

13 files changed

+140
-140
lines changed

test/functional/rpc_psbt.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def run_test(self):
373373

374374
self.log.info("Test various PSBT operations")
375375
# partially sign multisig things with node 1
376-
psbtx = wmulti.walletcreatefundedpsbt(inputs=[{"txid":txid,"vout":p2wsh_pos},{"txid":txid,"vout":p2sh_pos},{"txid":txid,"vout":p2sh_p2wsh_pos}], outputs={self.nodes[1].getnewaddress():29.99}, options={'changeAddress': self.nodes[1].getrawchangeaddress()})['psbt']
376+
psbtx = wmulti.walletcreatefundedpsbt(inputs=[{"txid":txid,"vout":p2wsh_pos},{"txid":txid,"vout":p2sh_pos},{"txid":txid,"vout":p2sh_p2wsh_pos}], outputs={self.nodes[1].getnewaddress():29.99}, changeAddress=self.nodes[1].getrawchangeaddress())['psbt']
377377
walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(psbtx)
378378
psbtx = walletprocesspsbt_out['psbt']
379379
assert_equal(walletprocesspsbt_out['complete'], False)
@@ -778,7 +778,7 @@ def test_psbt_input_keys(psbt_input, keys):
778778
psbt = wallet.walletcreatefundedpsbt(
779779
inputs=[{"txid": ext_utxo["txid"], "vout": ext_utxo["vout"], "weight": input_weight}],
780780
outputs={self.nodes[0].getnewaddress(): 15},
781-
options={"add_inputs": True}
781+
add_inputs=True,
782782
)
783783
signed = wallet.walletprocesspsbt(psbt["psbt"])
784784
signed = self.nodes[0].walletprocesspsbt(signed["psbt"])
@@ -788,21 +788,21 @@ def test_psbt_input_keys(psbt_input, keys):
788788
psbt2 = wallet.walletcreatefundedpsbt(
789789
inputs=[{"txid": ext_utxo["txid"], "vout": ext_utxo["vout"], "weight": low_input_weight}],
790790
outputs={self.nodes[0].getnewaddress(): 15},
791-
options={"add_inputs": True}
791+
add_inputs=True,
792792
)
793793
assert_greater_than(psbt["fee"], psbt2["fee"])
794794
# Increasing the weight should have a higher fee
795795
psbt2 = wallet.walletcreatefundedpsbt(
796796
inputs=[{"txid": ext_utxo["txid"], "vout": ext_utxo["vout"], "weight": high_input_weight}],
797797
outputs={self.nodes[0].getnewaddress(): 15},
798-
options={"add_inputs": True}
798+
add_inputs=True,
799799
)
800800
assert_greater_than(psbt2["fee"], psbt["fee"])
801801
# The provided weight should override the calculated weight when solving data is provided
802802
psbt3 = wallet.walletcreatefundedpsbt(
803803
inputs=[{"txid": ext_utxo["txid"], "vout": ext_utxo["vout"], "weight": high_input_weight}],
804804
outputs={self.nodes[0].getnewaddress(): 15},
805-
options={'add_inputs': True, "solving_data":{"descriptors": [desc]}}
805+
add_inputs=True, solving_data={"descriptors": [desc]},
806806
)
807807
assert_equal(psbt2["fee"], psbt3["fee"])
808808

@@ -816,7 +816,7 @@ def test_psbt_input_keys(psbt_input, keys):
816816
psbt3 = wallet.walletcreatefundedpsbt(
817817
inputs=[{"txid": ext_utxo["txid"], "vout": ext_utxo["vout"], "weight": high_input_weight}],
818818
outputs={self.nodes[0].getnewaddress(): 15},
819-
options={"add_inputs": True}
819+
add_inputs=True,
820820
)
821821
assert_equal(psbt2["fee"], psbt3["fee"])
822822

test/functional/wallet_bumpfee.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,36 +123,36 @@ def test_invalid_parameters(self, rbf_node, peer_node, dest_address):
123123
assert_raises_rpc_error(-3, "Unexpected key {}".format(key), rbf_node.bumpfee, rbfid, {key: NORMAL})
124124

125125
# Bumping to just above minrelay should fail to increase the total fee enough.
126-
assert_raises_rpc_error(-8, "Insufficient total fee 0.00000141", rbf_node.bumpfee, rbfid, {"fee_rate": INSUFFICIENT})
126+
assert_raises_rpc_error(-8, "Insufficient total fee 0.00000141", rbf_node.bumpfee, rbfid, fee_rate=INSUFFICIENT)
127127

128128
self.log.info("Test invalid fee rate settings")
129129
assert_raises_rpc_error(-4, "Specified or calculated fee 0.141 is too high (cannot be higher than -maxtxfee 0.10",
130-
rbf_node.bumpfee, rbfid, {"fee_rate": TOO_HIGH})
130+
rbf_node.bumpfee, rbfid, fee_rate=TOO_HIGH)
131131
# Test fee_rate with zero values.
132132
msg = "Insufficient total fee 0.00"
133133
for zero_value in [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]:
134-
assert_raises_rpc_error(-8, msg, rbf_node.bumpfee, rbfid, {"fee_rate": zero_value})
134+
assert_raises_rpc_error(-8, msg, rbf_node.bumpfee, rbfid, fee_rate=zero_value)
135135
msg = "Invalid amount"
136136
# Test fee_rate values that don't pass fixed-point parsing checks.
137137
for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
138-
assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, {"fee_rate": invalid_value})
138+
assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, fee_rate=invalid_value)
139139
# Test fee_rate values that cannot be represented in sat/vB.
140140
for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
141-
assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, {"fee_rate": invalid_value})
141+
assert_raises_rpc_error(-3, msg, rbf_node.bumpfee, rbfid, fee_rate=invalid_value)
142142
# Test fee_rate out of range (negative number).
143-
assert_raises_rpc_error(-3, "Amount out of range", rbf_node.bumpfee, rbfid, {"fee_rate": -1})
143+
assert_raises_rpc_error(-3, "Amount out of range", rbf_node.bumpfee, rbfid, fee_rate=-1)
144144
# Test type error.
145145
for value in [{"foo": "bar"}, True]:
146-
assert_raises_rpc_error(-3, "Amount is not a number or string", rbf_node.bumpfee, rbfid, {"fee_rate": value})
146+
assert_raises_rpc_error(-3, "Amount is not a number or string", rbf_node.bumpfee, rbfid, fee_rate=value)
147147

148148
self.log.info("Test explicit fee rate raises RPC error if both fee_rate and conf_target are passed")
149149
assert_raises_rpc_error(-8, "Cannot specify both conf_target and fee_rate. Please provide either a confirmation "
150150
"target in blocks for automatic fee estimation, or an explicit fee rate.",
151-
rbf_node.bumpfee, rbfid, {"conf_target": NORMAL, "fee_rate": NORMAL})
151+
rbf_node.bumpfee, rbfid, conf_target=NORMAL, fee_rate=NORMAL)
152152

153153
self.log.info("Test explicit fee rate raises RPC error if both fee_rate and estimate_mode are passed")
154154
assert_raises_rpc_error(-8, "Cannot specify both estimate_mode and fee_rate",
155-
rbf_node.bumpfee, rbfid, {"estimate_mode": "economical", "fee_rate": NORMAL})
155+
rbf_node.bumpfee, rbfid, estimate_mode="economical", fee_rate=NORMAL)
156156

157157
self.log.info("Test invalid conf_target settings")
158158
assert_raises_rpc_error(-8, "confTarget and conf_target options should not both be set",
@@ -161,10 +161,10 @@ def test_invalid_parameters(self, rbf_node, peer_node, dest_address):
161161
self.log.info("Test invalid estimate_mode settings")
162162
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
163163
assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string",
164-
rbf_node.bumpfee, rbfid, {"estimate_mode": v})
164+
rbf_node.bumpfee, rbfid, estimate_mode=v)
165165
for mode in ["foo", Decimal("3.1415"), "sat/B", "BTC/kB"]:
166166
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
167-
rbf_node.bumpfee, rbfid, {"estimate_mode": mode})
167+
rbf_node.bumpfee, rbfid, estimate_mode=mode)
168168

169169
self.log.info("Test invalid outputs values")
170170
assert_raises_rpc_error(-8, "Invalid parameter, output argument cannot be an empty array",
@@ -232,12 +232,12 @@ def test_simple_bumpfee_succeeds(self, mode, rbf_node, peer_node, dest_address):
232232
self.sync_mempools((rbf_node, peer_node))
233233
assert rbfid in rbf_node.getrawmempool() and rbfid in peer_node.getrawmempool()
234234
if mode == "fee_rate":
235-
bumped_psbt = rbf_node.psbtbumpfee(rbfid, {"fee_rate": str(NORMAL)})
236-
bumped_tx = rbf_node.bumpfee(rbfid, {"fee_rate": NORMAL})
235+
bumped_psbt = rbf_node.psbtbumpfee(rbfid, fee_rate=str(NORMAL))
236+
bumped_tx = rbf_node.bumpfee(rbfid, fee_rate=NORMAL)
237237
elif mode == "new_outputs":
238238
new_address = peer_node.getnewaddress()
239-
bumped_psbt = rbf_node.psbtbumpfee(rbfid, {"outputs": {new_address: 0.0003}})
240-
bumped_tx = rbf_node.bumpfee(rbfid, {"outputs": {new_address: 0.0003}})
239+
bumped_psbt = rbf_node.psbtbumpfee(rbfid, outputs={new_address: 0.0003})
240+
bumped_tx = rbf_node.bumpfee(rbfid, outputs={new_address: 0.0003})
241241
else:
242242
bumped_psbt = rbf_node.psbtbumpfee(rbfid)
243243
bumped_tx = rbf_node.bumpfee(rbfid)
@@ -305,7 +305,7 @@ def test_notmine_bumpfee(self, rbf_node, peer_node, dest_address):
305305
# Note that this test depends upon the RPC code checking input ownership prior to change outputs
306306
# (since it can't use fundrawtransaction, it lacks a proper change output)
307307
fee = Decimal("0.001")
308-
utxos = [node.listunspent(query_options={'minimumAmount': fee})[-1] for node in (rbf_node, peer_node)]
308+
utxos = [node.listunspent(minimumAmount=fee)[-1] for node in (rbf_node, peer_node)]
309309
inputs = [{
310310
"txid": utxo["txid"],
311311
"vout": utxo["vout"],
@@ -335,7 +335,7 @@ def finish_psbtbumpfee(psbt):
335335
psbt = rbf_node.psbtbumpfee(txid=rbfid)
336336
finish_psbtbumpfee(psbt["psbt"])
337337

338-
psbt = rbf_node.psbtbumpfee(txid=rbfid, options={"fee_rate": old_feerate + 10})
338+
psbt = rbf_node.psbtbumpfee(txid=rbfid, fee_rate=old_feerate + 10)
339339
finish_psbtbumpfee(psbt["psbt"])
340340

341341
self.clear_mempool()
@@ -445,7 +445,7 @@ def test_dust_to_fee(self, rbf_node, dest_address):
445445
# Expected fee is 141 vbytes * fee_rate 0.00350250 BTC / 1000 vbytes = 0.00049385 BTC.
446446
# or occasionally 140 vbytes * fee_rate 0.00350250 BTC / 1000 vbytes = 0.00049035 BTC.
447447
# Dust should be dropped to the fee, so actual bump fee is 0.00050000 BTC.
448-
bumped_tx = rbf_node.bumpfee(rbfid, {"fee_rate": 350.25})
448+
bumped_tx = rbf_node.bumpfee(rbfid, fee_rate=350.25)
449449
full_bumped_tx = rbf_node.getrawtransaction(bumped_tx["txid"], 1)
450450
assert_equal(bumped_tx["fee"], Decimal("0.00050000"))
451451
assert_equal(len(fulltx["vout"]), 2)
@@ -569,7 +569,7 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
569569
assert_raises_rpc_error(-4, "bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead.", watcher.bumpfee, original_txid)
570570

571571
# Bump fee, obnoxiously high to add additional watchonly input
572-
bumped_psbt = watcher.psbtbumpfee(original_txid, {"fee_rate": HIGH})
572+
bumped_psbt = watcher.psbtbumpfee(original_txid, fee_rate=HIGH)
573573
assert_greater_than(len(watcher.decodepsbt(bumped_psbt['psbt'])["tx"]["vin"]), 1)
574574
assert "txid" not in bumped_psbt
575575
assert_equal(bumped_psbt["origfee"], -watcher.gettransaction(original_txid)["fee"])
@@ -593,17 +593,17 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
593593
def test_rebumping(self, rbf_node, dest_address):
594594
self.log.info('Test that re-bumping the original tx fails, but bumping successor works')
595595
rbfid = spend_one_input(rbf_node, dest_address)
596-
bumped = rbf_node.bumpfee(rbfid, {"fee_rate": ECONOMICAL})
596+
bumped = rbf_node.bumpfee(rbfid, fee_rate=ECONOMICAL)
597597
assert_raises_rpc_error(-4, f"Cannot bump transaction {rbfid} which was already bumped by transaction {bumped['txid']}",
598-
rbf_node.bumpfee, rbfid, {"fee_rate": NORMAL})
599-
rbf_node.bumpfee(bumped["txid"], {"fee_rate": NORMAL})
598+
rbf_node.bumpfee, rbfid, fee_rate=NORMAL)
599+
rbf_node.bumpfee(bumped["txid"], fee_rate=NORMAL)
600600
self.clear_mempool()
601601

602602

603603
def test_rebumping_not_replaceable(self, rbf_node, dest_address):
604604
self.log.info('Test that re-bumping non-replaceable fails')
605605
rbfid = spend_one_input(rbf_node, dest_address)
606-
bumped = rbf_node.bumpfee(rbfid, {"fee_rate": ECONOMICAL, "replaceable": False})
606+
bumped = rbf_node.bumpfee(rbfid, fee_rate=ECONOMICAL, replaceable=False)
607607
assert_raises_rpc_error(-4, "Transaction is not BIP 125 replaceable", rbf_node.bumpfee, bumped["txid"],
608608
{"fee_rate": NORMAL})
609609
self.clear_mempool()
@@ -615,7 +615,7 @@ def test_bumpfee_already_spent(self, rbf_node, dest_address):
615615
self.generate(rbf_node, 1) # spend coin simply by mining block with tx
616616
spent_input = rbf_node.gettransaction(txid=txid, verbose=True)['decoded']['vin'][0]
617617
assert_raises_rpc_error(-1, f"{spent_input['txid']}:{spent_input['vout']} is already spent",
618-
rbf_node.bumpfee, txid, {"fee_rate": NORMAL})
618+
rbf_node.bumpfee, txid, fee_rate=NORMAL)
619619

620620

621621
def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
@@ -694,7 +694,7 @@ def test_change_script_match(self, rbf_node, dest_address):
694694
assert_equal(len(change_addresses), 1)
695695

696696
# Now find that address in each subsequent tx, and no other change
697-
bumped_total_tx = rbf_node.bumpfee(rbfid, {"fee_rate": ECONOMICAL})
697+
bumped_total_tx = rbf_node.bumpfee(rbfid, fee_rate=ECONOMICAL)
698698
assert_equal(change_addresses, get_change_address(bumped_total_tx['txid'], rbf_node))
699699
bumped_rate_tx = rbf_node.bumpfee(bumped_total_tx["txid"])
700700
assert_equal(change_addresses, get_change_address(bumped_rate_tx['txid'], rbf_node))

0 commit comments

Comments
 (0)