MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/rpc_tests.cpp:90–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88BOOST_FIXTURE_TEST_SUITE(rpc_tests, RPCTestingSetup)
89
90BOOST_AUTO_TEST_CASE(rpc_namedparams)
91{
92 const std::vector<std::pair<std::string, bool>> arg_names{{"arg1", false}, {"arg2", false}, {"arg3", false}, {"arg4", false}, {"arg5", false}};
93
94 // Make sure named arguments are transformed into positional arguments in correct places separated by nulls
95 BOOST_CHECK_EQUAL(TransformParams(JSON(R"({"arg2": 2, "arg4": 4})"), arg_names).write(), "[null,2,null,4]");
96
97 // Make sure named argument specified multiple times raises an exception
98 BOOST_CHECK_EXCEPTION(TransformParams(JSON(R"({"arg2": 2, "arg2": 4})"), arg_names), UniValue,
99 HasJSON(R"({"code":-8,"message":"Parameter arg2 specified multiple times"})"));
100
101 // Make sure named and positional arguments can be combined.
102 BOOST_CHECK_EQUAL(TransformParams(JSON(R"({"arg5": 5, "args": [1, 2], "arg4": 4})"), arg_names).write(), "[1,2,null,4,5]");
103
104 // Make sure a unknown named argument raises an exception
105 BOOST_CHECK_EXCEPTION(TransformParams(JSON(R"({"arg2": 2, "unknown": 6})"), arg_names), UniValue,
106 HasJSON(R"({"code":-8,"message":"Unknown named parameter unknown"})"));
107
108 // Make sure an overlap between a named argument and positional argument raises an exception
109 BOOST_CHECK_EXCEPTION(TransformParams(JSON(R"({"args": [1,2,3], "arg4": 4, "arg2": 2})"), arg_names), UniValue,
110 HasJSON(R"({"code":-8,"message":"Parameter arg2 specified twice both as positional and named argument"})"));
111
112 // Make sure extra positional arguments can be passed through to the method implementation, as long as they don't overlap with named arguments.
113 BOOST_CHECK_EQUAL(TransformParams(JSON(R"({"args": [1,2,3,4,5,6,7,8,9,10]})"), arg_names).write(), "[1,2,3,4,5,6,7,8,9,10]");
114 BOOST_CHECK_EQUAL(TransformParams(JSON(R"([1,2,3,4,5,6,7,8,9,10])"), arg_names).write(), "[1,2,3,4,5,6,7,8,9,10]");
115}
116
117BOOST_AUTO_TEST_CASE(rpc_namedonlyparams)
118{

Callers

nothing calls this directly

Calls 15

JSONFunction · 0.85
HasJSONClass · 0.85
CallRPCFunction · 0.85
ValueFromAmountFunction · 0.85
ValueFromStringFunction · 0.85
RPCConvertValuesFunction · 0.85
HelpExampleCliNamedFunction · 0.85
HelpExampleRpcNamedFunction · 0.85
CheckRpcFunction · 0.85
get_boolMethod · 0.80
pushKVMethod · 0.80

Tested by

no test coverage detected