Skip to content

Commit 3f72791

Browse files
committed
wallet: fix bug in RPC send options
when empty, options were not being populated by arguments of the same name found while adding test coverage in 603c005
1 parent 155bf91 commit 3f72791

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4087,7 +4087,7 @@ static RPCHelpMan send()
40874087
if (!wallet) return NullUniValue;
40884088
CWallet* const pwallet = wallet.get();
40894089

4090-
UniValue options = request.params[3];
4090+
UniValue options{request.params[3].isNull() ? UniValue::VOBJ : request.params[3]};
40914091
if (options.exists("feeRate") || options.exists("fee_rate") || options.exists("estimate_mode") || options.exists("conf_target")) {
40924092
if (!request.params[1].isNull() || !request.params[2].isNull()) {
40934093
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use either conf_target and estimate_mode or the options dictionary to control fee rate");

test/functional/wallet_send.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
"""Test the send RPC command."""
66

77
from decimal import Decimal, getcontext
8+
from itertools import product
9+
810
from test_framework.authproxy import JSONRPCException
911
from test_framework.test_framework import BitcoinTestFramework
1012
from test_framework.util import (
1113
assert_equal,
1214
assert_fee_amount,
1315
assert_greater_than,
14-
assert_raises_rpc_error
16+
assert_raises_rpc_error,
1517
)
1618

1719
class WalletSendTest(BitcoinTestFramework):
@@ -271,8 +273,9 @@ def run_test(self):
271273
fee = self.nodes[1].decodepsbt(res["psbt"])["fee"]
272274
assert_fee_amount(fee, Decimal(len(res["hex"]) / 2), Decimal("0.00003"))
273275

274-
# TODO: This test should pass with all modes, e.g. with the next line uncommented, for consistency with the other explicit feerate RPCs.
275-
# for mode in ["unset", "economical", "conservative", "btc/kb", "sat/b"]:
276+
for target, mode in product([-1, 0, 1009], ["economical", "conservative"]):
277+
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=target, estimate_mode=mode,
278+
expect_error=(-8, "Invalid conf_target, must be between 1 and 1008"))
276279
for mode in ["btc/kb", "sat/b"]:
277280
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=-1, estimate_mode=mode,
278281
expect_error=(-3, "Amount out of range"))
@@ -282,17 +285,15 @@ def run_test(self):
282285
for mode in ["foo", Decimal("3.141592")]:
283286
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=0.1, estimate_mode=mode,
284287
expect_error=(-8, "Invalid estimate_mode parameter"))
285-
# TODO: these 2 equivalent sends with an invalid estimate_mode arg should both fail, but they do not...why?
286-
# self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_conf_target=0.1, arg_estimate_mode=mode,
287-
# expect_error=(-8, "Invalid estimate_mode parameter"))
288-
# assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", lambda: w0.send({w1.getnewaddress(): 1}, 0.1, mode))
289-
290-
# TODO: These tests should pass for consistency with the other explicit feerate RPCs, but they do not.
291-
# for mode in ["unset", "economical", "conservative", "btc/kb", "sat/b"]:
292-
# self.log.debug("{}".format(mode))
293-
# for k, v in {"string": "", "object": {"foo": "bar"}}.items():
294-
# self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
295-
# expect_error=(-3, "Expected type number for conf_target, got {}".format(k)))
288+
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_conf_target=0.1, arg_estimate_mode=mode,
289+
expect_error=(-8, "Invalid estimate_mode parameter"))
290+
assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", lambda: w0.send({w1.getnewaddress(): 1}, 0.1, mode))
291+
292+
for mode in ["economical", "conservative", "btc/kb", "sat/b"]:
293+
self.log.debug("{}".format(mode))
294+
for k, v in {"string": "true", "object": {"foo": "bar"}}.items():
295+
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
296+
expect_error=(-3, "Expected type number for conf_target, got {}".format(k)))
296297

297298
# TODO: error should use sat/B instead of BTC/kB if sat/B is selected.
298299
# Test setting explicit fee rate just below the minimum.

0 commit comments

Comments
 (0)