|
17 | 17 | import io |
18 | 18 |
|
19 | 19 | 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 |
21 | 21 | from test_framework.test_framework import BitcoinTestFramework |
22 | 22 | from test_framework.util import ( |
23 | 23 | assert_equal, |
@@ -46,6 +46,7 @@ def set_test_params(self): |
46 | 46 | "-mintxfee=0.00002", |
47 | 47 | "-addresstype=bech32", |
48 | 48 | ] for i in range(self.num_nodes)] |
| 49 | + self.wallet_names = [self.default_wallet_name, "RBF wallet"] |
49 | 50 |
|
50 | 51 | def skip_test_if_missing_module(self): |
51 | 52 | self.skip_if_no_wallet() |
@@ -91,6 +92,7 @@ def run_test(self): |
91 | 92 | test_bumpfee_metadata(self, rbf_node, dest_address) |
92 | 93 | test_locked_wallet_fails(self, rbf_node, dest_address) |
93 | 94 | test_change_script_match(self, rbf_node, dest_address) |
| 95 | + test_setfeerate(self, rbf_node, dest_address) |
94 | 96 | test_settxfee(self, rbf_node, dest_address) |
95 | 97 | test_maxtxfee_fails(self, rbf_node, dest_address) |
96 | 98 | # 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): |
315 | 317 | self.clear_mempool() |
316 | 318 |
|
317 | 319 |
|
| 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 | + |
318 | 356 | def test_settxfee(self, rbf_node, dest_address): |
319 | 357 | self.log.info('Test settxfee') |
320 | 358 | assert_raises_rpc_error(-8, "txfee cannot be less than min relay tx fee", rbf_node.settxfee, Decimal('0.000005')) |
|
0 commit comments