Skip to content

Commit 6a32c0f

Browse files
luke-jrjonasschnelli
authored andcommitted
Qt/Test: Check handling of empty arguments in RPC debug console
1 parent 89c8d2c commit 6a32c0f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/qt/test/rpcnestedtests.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818

1919
#include <boost/filesystem.hpp>
2020

21+
static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request)
22+
{
23+
if (request.fHelp) {
24+
return "help message";
25+
}
26+
return request.params.write(0, 0);
27+
}
28+
29+
static const CRPCCommand vRPCCommands[] =
30+
{
31+
{ "test", "rpcNestedTest", &rpcNestedTest_rpc, true },
32+
};
33+
2134
void RPCNestedTests::rpcNestedTests()
2235
{
2336
UniValue jsonRPCError;
@@ -26,6 +39,7 @@ void RPCNestedTests::rpcNestedTests()
2639
// could be moved to a more generic place when we add more tests on QT level
2740
const CChainParams& chainparams = Params();
2841
RegisterAllCoreRPCCommands(tableRPC);
42+
tableRPC.appendCommand("rpcNestedTest", &vRPCCommands[0]);
2943
ClearDatadirCache();
3044
std::string path = QDir::tempPath().toStdString() + "/" + strprintf("test_bitcoin_qt_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
3145
QDir dir(QString::fromStdString(path));
@@ -85,6 +99,23 @@ void RPCNestedTests::rpcNestedTests()
8599
RPCConsole::RPCExecuteCommandLine(result, "getblock(getbestblockhash())[tx][0]");
86100
QVERIFY(result == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
87101

102+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest");
103+
QVERIFY(result == "[]");
104+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest ''");
105+
QVERIFY(result == "[\"\"]");
106+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest \"\"");
107+
QVERIFY(result == "[\"\"]");
108+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest '' abc");
109+
QVERIFY(result == "[\"\",\"abc\"]");
110+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc '' abc");
111+
QVERIFY(result == "[\"abc\",\"\",\"abc\"]");
112+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc abc");
113+
QVERIFY(result == "[\"abc\",\"abc\"]");
114+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc\t\tabc");
115+
QVERIFY(result == "[\"abc\",\"abc\"]");
116+
RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc,,abc");
117+
QVERIFY(result == "[\"abc\",\"\",\"abc\"]");
118+
88119
delete pcoinsTip;
89120
delete pcoinsdbview;
90121
delete pblocktree;

0 commit comments

Comments
 (0)