Skip to content

Commit 529bfc1

Browse files
committed
test: add setfeerate functional coverage in wallet_create_tx.py
1 parent 8e863e3 commit 529bfc1

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

test/functional/wallet_create_tx.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
from decimal import Decimal
7+
8+
from test_framework.blocktools import TIME_GENESIS_BLOCK
69
from test_framework.test_framework import BitcoinTestFramework
710
from test_framework.util import (
811
assert_equal,
912
assert_raises_rpc_error,
1013
)
11-
from test_framework.blocktools import (
12-
TIME_GENESIS_BLOCK,
13-
)
1414

1515

1616
class CreateTxWalletTest(BitcoinTestFramework):
1717
def set_test_params(self):
1818
self.setup_clean_chain = True
1919
self.num_nodes = 1
20+
self.wallet_names = ["test_wallet"]
2021

2122
def skip_test_if_missing_module(self):
2223
self.skip_if_no_wallet()
@@ -29,6 +30,7 @@ def run_test(self):
2930

3031
self.test_anti_fee_sniping()
3132
self.test_tx_size_too_large()
33+
self.test_setfeerate()
3234

3335
def test_anti_fee_sniping(self):
3436
self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')
@@ -77,6 +79,51 @@ def test_tx_size_too_large(self):
7779
)
7880
self.nodes[0].settxfee(0)
7981

82+
def test_setfeerate(self):
83+
self.log.info("Test setfeerate")
84+
self.restart_node(0, extra_args=["-mintxfee=0.00003141"]) # 3.141 sat/vB
85+
node = self.nodes[0]
86+
87+
def test_response(*, requested=0, expected=0, error=None, msg):
88+
assert_equal(node.setfeerate(requested), {"wallet_name": "test_wallet", "fee_rate": expected, ("error" if error else "result"): msg})
89+
90+
# Test setfeerate with 10.0001 (CFeeRate rounding), "10.001" and "4" sat/vB
91+
test_response(requested=10.0001, expected=10, msg="Fee rate for transactions with this wallet successfully set to 10.000 sat/vB")
92+
assert_equal(node.getwalletinfo()["paytxfee"], Decimal("0.00010000"))
93+
test_response(requested="10.001", expected=Decimal("10.001"), msg="Fee rate for transactions with this wallet successfully set to 10.001 sat/vB")
94+
assert_equal(node.getwalletinfo()["paytxfee"], Decimal("0.00010001"))
95+
test_response(requested="4", expected=4, msg="Fee rate for transactions with this wallet successfully set to 4.000 sat/vB")
96+
assert_equal(node.getwalletinfo()["paytxfee"], Decimal("0.00004000"))
97+
98+
# Test setfeerate with too-high/low values returns expected errors
99+
test_response(requested=Decimal("10000.001"), expected=4, error=True, msg="The requested fee rate of 10000.001 sat/vB cannot be greater than the wallet max fee rate of 10000.000 sat/vB. The current setting of 4.000 sat/vB for this wallet remains unchanged.")
100+
test_response(requested=Decimal("0.999"), expected=4, error=True, msg="The requested fee rate of 0.999 sat/vB cannot be less than the minimum relay fee rate of 1.000 sat/vB. The current setting of 4.000 sat/vB for this wallet remains unchanged.")
101+
test_response(requested=Decimal("3.140"), expected=4, error=True, msg="The requested fee rate of 3.140 sat/vB cannot be less than the wallet min fee rate of 3.141 sat/vB. The current setting of 4.000 sat/vB for this wallet remains unchanged.")
102+
assert_equal(node.getwalletinfo()["paytxfee"], Decimal("0.00004000"))
103+
104+
# Test setfeerate to 3.141 sat/vB
105+
test_response(requested=3.141, expected=Decimal("3.141"), msg="Fee rate for transactions with this wallet successfully set to 3.141 sat/vB")
106+
assert_equal(node.getwalletinfo()["paytxfee"], Decimal("0.00003141"))
107+
108+
# Test setfeerate with values non-representable by CFeeRate
109+
for invalid_value in [0.00000001, 0.0009, 0.00099999]:
110+
assert_raises_rpc_error(-3, "Invalid amount", node.setfeerate, amount=invalid_value)
111+
112+
# Test setfeerate with values rejected by ParseFixedPoint() called in AmountFromValue()
113+
for invalid_value in ["", 0.000000001, "1.111111111", 11111111111]:
114+
assert_raises_rpc_error(-3, "Invalid amount", node.setfeerate, amount=invalid_value)
115+
116+
# Test deactivating setfeerate
117+
test_response(msg="Fee rate for transactions with this wallet successfully unset. By default, automatic fee selection will be used.")
118+
assert_equal(node.getwalletinfo()["paytxfee"], 0)
119+
120+
# Test currently-unset setfeerate with too-high/low values returns expected errors
121+
test_response(requested=Decimal("10000.001"), error=True, msg="The requested fee rate of 10000.001 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.")
122+
assert_equal(node.getwalletinfo()["paytxfee"], 0)
123+
test_response(requested=Decimal("0.999"), error=True, msg="The requested fee rate of 0.999 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.")
124+
test_response(requested=Decimal("3.140"), error=True, msg="The requested fee rate of 3.140 sat/vB cannot be less than the wallet min fee rate of 3.141 sat/vB. The current setting of 0 (unset) for this wallet remains unchanged.")
125+
assert_equal(node.getwalletinfo()["paytxfee"], 0)
126+
80127

81128
if __name__ == '__main__':
82129
CreateTxWalletTest().main()

0 commit comments

Comments
 (0)