Skip to content

Commit c907f15

Browse files
committed
test: add setfeerate functional coverage in wallet_bumpfee.py
1 parent 529bfc1 commit c907f15

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

test/functional/wallet_bumpfee.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import io
1818

1919
from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness
20-
from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction
20+
from test_framework.messages import BIP125_SEQUENCE_NUMBER, COIN, CTransaction
2121
from test_framework.test_framework import BitcoinTestFramework
2222
from test_framework.util import (
2323
assert_equal,
@@ -46,6 +46,7 @@ def set_test_params(self):
4646
"-mintxfee=0.00002",
4747
"-addresstype=bech32",
4848
] for i in range(self.num_nodes)]
49+
self.wallet_names = [self.default_wallet_name, "RBF wallet"]
4950

5051
def skip_test_if_missing_module(self):
5152
self.skip_if_no_wallet()
@@ -91,6 +92,7 @@ def run_test(self):
9192
test_bumpfee_metadata(self, rbf_node, dest_address)
9293
test_locked_wallet_fails(self, rbf_node, dest_address)
9394
test_change_script_match(self, rbf_node, dest_address)
95+
test_setfeerate(self, rbf_node, dest_address)
9496
test_settxfee(self, rbf_node, dest_address)
9597
test_maxtxfee_fails(self, rbf_node, dest_address)
9698
# These tests wipe out a number of utxos that are expected in other tests
@@ -315,6 +317,42 @@ def test_dust_to_fee(self, rbf_node, dest_address):
315317
self.clear_mempool()
316318

317319

320+
def test_setfeerate(self, rbf_node, dest_address):
321+
self.log.info("Test setfeerate")
322+
323+
def test_response(*, wallet="RBF wallet", requested=0, expected=0, error=None, msg):
324+
assert_equal(rbf_node.setfeerate(requested), {"wallet_name": wallet, "fee_rate": expected, ("error" if error else "result"): msg})
325+
326+
# Test setfeerate with too high/low values returns expected errors
327+
new = Decimal("10000.001")
328+
test_response(requested=new, error=True, msg=f"The requested fee rate of {new} sat/vB cannot be greater than the wallet max fee rate of 10000.000 sat/vB. The current setting of 0 (unset) for this wallet remains unchanged.")
329+
new = Decimal("0.999")
330+
test_response(requested=new, error=True, msg=f"The requested fee rate of {new} sat/vB cannot be less than the minimum relay fee rate of 1.000 sat/vB. The current setting of 0 (unset) for this wallet remains unchanged.")
331+
fee_rate = Decimal("2.001")
332+
test_response(requested=fee_rate, expected=fee_rate, msg=f"Fee rate for transactions with this wallet successfully set to {fee_rate} sat/vB")
333+
new = Decimal("1.999")
334+
test_response(requested=new, expected=fee_rate, error=True, msg=f"The requested fee rate of {new} sat/vB cannot be less than the wallet min fee rate of 2.000 sat/vB. The current setting of {fee_rate} sat/vB for this wallet remains unchanged.")
335+
336+
# Test setfeerate with valid values returns expected results
337+
rbfid = spend_one_input(rbf_node, dest_address)
338+
fee_rate = 25
339+
test_response(requested=fee_rate, expected=fee_rate, msg="Fee rate for transactions with this wallet successfully set to 25.000 sat/vB")
340+
bumped_tx = rbf_node.bumpfee(rbfid)
341+
actual_feerate = bumped_tx["fee"] * COIN / rbf_node.getrawtransaction(bumped_tx["txid"], True)["vsize"]
342+
assert_greater_than(Decimal("0.01"), abs(fee_rate - actual_feerate))
343+
test_response(msg="Fee rate for transactions with this wallet successfully unset. By default, automatic fee selection will be used.")
344+
345+
# Test setfeerate with a different -maxtxfee
346+
self.restart_node(1, ["-maxtxfee=0.000025"] + self.extra_args[1])
347+
new = "2.501"
348+
test_response(requested=new, error=True, msg=f"The requested fee rate of {new} sat/vB cannot be greater than the wallet max fee rate of 2.500 sat/vB. The current setting of 0 (unset) for this wallet remains unchanged.")
349+
350+
self.restart_node(1, self.extra_args[1])
351+
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
352+
self.connect_nodes(1, 0)
353+
self.clear_mempool()
354+
355+
318356
def test_settxfee(self, rbf_node, dest_address):
319357
self.log.info('Test settxfee')
320358
assert_raises_rpc_error(-8, "txfee cannot be less than min relay tx fee", rbf_node.settxfee, Decimal('0.000005'))

0 commit comments

Comments
 (0)