@@ -481,6 +481,41 @@ BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_size)
481
481
}
482
482
}
483
483
484
+ BOOST_AUTO_TEST_CASE (help_example)
485
+ {
486
+ // test different argument types
487
+ const RPCArgList& args = {{" foo" , " bar" }, {" b" , true }, {" n" , 1 }};
488
+ BOOST_CHECK_EQUAL (HelpExampleCliNamed (" test" , args), " > dash-cli -named test foo=bar b=true n=1\n " );
489
+ BOOST_CHECK_EQUAL (HelpExampleRpcNamed (" test" , args), " > curl --user myusername --data-binary '{\" jsonrpc\" : \" 1.0\" , \" id\" : \" curltest\" , \" method\" : \" test\" , \" params\" : {\" foo\" :\" bar\" ,\" b\" :true,\" n\" :1}}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n " );
490
+
491
+ // test shell escape
492
+ BOOST_CHECK_EQUAL (HelpExampleCliNamed (" test" , {{" foo" , " b'ar" }}), " > dash-cli -named test foo='b'''ar'\n " );
493
+ BOOST_CHECK_EQUAL (HelpExampleCliNamed (" test" , {{" foo" , " b\" ar" }}), " > dash-cli -named test foo='b\" ar'\n " );
494
+ BOOST_CHECK_EQUAL (HelpExampleCliNamed (" test" , {{" foo" , " b ar" }}), " > dash-cli -named test foo='b ar'\n " );
495
+
496
+ // test object params
497
+ UniValue obj_value (UniValue::VOBJ);
498
+ obj_value.pushKV (" foo" , " bar" );
499
+ obj_value.pushKV (" b" , false );
500
+ obj_value.pushKV (" n" , 1 );
501
+ BOOST_CHECK_EQUAL (HelpExampleCliNamed (" test" , {{" name" , obj_value}}), " > dash-cli -named test name='{\" foo\" :\" bar\" ,\" b\" :false,\" n\" :1}'\n " );
502
+ BOOST_CHECK_EQUAL (HelpExampleRpcNamed (" test" , {{" name" , obj_value}}), " > curl --user myusername --data-binary '{\" jsonrpc\" : \" 1.0\" , \" id\" : \" curltest\" , \" method\" : \" test\" , \" params\" : {\" name\" :{\" foo\" :\" bar\" ,\" b\" :false,\" n\" :1}}}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n " );
503
+
504
+ // test array params
505
+ UniValue arr_value (UniValue::VARR);
506
+ arr_value.push_back (" bar" );
507
+ arr_value.push_back (false );
508
+ arr_value.push_back (1 );
509
+ BOOST_CHECK_EQUAL (HelpExampleCliNamed (" test" , {{" name" , arr_value}}), " > dash-cli -named test name='[\" bar\" ,false,1]'\n " );
510
+ BOOST_CHECK_EQUAL (HelpExampleRpcNamed (" test" , {{" name" , arr_value}}), " > curl --user myusername --data-binary '{\" jsonrpc\" : \" 1.0\" , \" id\" : \" curltest\" , \" method\" : \" test\" , \" params\" : {\" name\" :[\" bar\" ,false,1]}}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n " );
511
+
512
+ // test types don't matter for shell
513
+ BOOST_CHECK_EQUAL (HelpExampleCliNamed (" foo" , {{" arg" , true }}), HelpExampleCliNamed (" foo" , {{" arg" , " true" }}));
514
+
515
+ // test types matter for Rpc
516
+ BOOST_CHECK_NE (HelpExampleRpcNamed (" foo" , {{" arg" , true }}), HelpExampleRpcNamed (" foo" , {{" arg" , " true" }}));
517
+ }
518
+
484
519
BOOST_AUTO_TEST_CASE (rpc_bls)
485
520
{
486
521
UniValue r;
0 commit comments