Skip to content

Commit e2c3b18

Browse files
committed
test: Add RPC tests for same named parameter specified more than once
Current behavior isn't ideal and will be changed in upcoming commits, but it's useful to have test coverage regardless. MarcoFalke reported the case of bitcoin-cli positional arguments overwriting the named "args" parameter in bitcoin/bitcoin#19762 (comment)
1 parent 78aee0f commit e2c3b18

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/test/rpc_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ BOOST_AUTO_TEST_CASE(rpc_namedparams)
8989
// Make sure named arguments are transformed into positional arguments in correct places separated by nulls
9090
BOOST_CHECK_EQUAL(TransformParams(JSON(R"({"arg2": 2, "arg4": 4})"), arg_names).write(), "[null,2,null,4]");
9191

92+
// Make sure later named argument value silently overwrites earlier values
93+
BOOST_CHECK_EQUAL(TransformParams(JSON(R"({"arg2": 2, "arg2": 4})"), arg_names).write(), "[null,4]");
94+
9295
// Make sure named and positional arguments can be combined.
9396
BOOST_CHECK_EQUAL(TransformParams(JSON(R"({"arg5": 5, "args": [1, 2], "arg4": 4})"), arg_names).write(), "[1,2,null,4,5]");
9497

test/functional/interface_bitcoin_cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def run_test(self):
9090
assert_raises_rpc_error(-8, "Parameter arg1 specified twice both as positional and named argument", self.nodes[0].cli.echo, 0, 1, arg1=1)
9191
assert_raises_rpc_error(-8, "Parameter arg1 specified twice both as positional and named argument", self.nodes[0].cli.echo, 0, None, 2, arg1=1)
9292

93+
self.log.info("Test that later cli named arguments values silently overwrite earlier ones")
94+
assert_equal(self.nodes[0].cli("-named", "echo", "arg0=0", "arg1=1", "arg2=2", "arg1=3").send_cli(), ['0', '3', '2'])
95+
assert_equal(self.nodes[0].cli("-named", "echo", "args=[0,1,2,3]", "4", "5", "6", ).send_cli(), ['4', '5', '6'])
96+
9397
user, password = get_auth_cookie(self.nodes[0].datadir, self.chain)
9498

9599
self.log.info("Test -stdinrpcpass option")

0 commit comments

Comments
 (0)