Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / src / qt / test / rpcnestedtests.cpp
blobaaec15cc1321331af17bd4d3a58c1f82b36f389d
1 // Copyright (c) 2016-2017 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include <qt/test/rpcnestedtests.h>
7 #include <chainparams.h>
8 #include <consensus/validation.h>
9 #include <fs.h>
10 #include <validation.h>
11 #include <rpc/register.h>
12 #include <rpc/server.h>
13 #include <qt/rpcconsole.h>
14 #include <test/test_bitcoin.h>
15 #include <univalue.h>
16 #include <util.h>
18 #include <QDir>
19 #include <QtGlobal>
21 static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request)
23 if (request.fHelp) {
24 return "help message";
26 return request.params.write(0, 0);
29 static const CRPCCommand vRPCCommands[] =
31 { "test", "rpcNestedTest", &rpcNestedTest_rpc, {} },
34 void RPCNestedTests::rpcNestedTests()
36 // do some test setup
37 // could be moved to a more generic place when we add more tests on QT level
38 tableRPC.appendCommand("rpcNestedTest", &vRPCCommands[0]);
39 //mempool.setSanityCheck(1.0);
41 TestingSetup test;
43 SetRPCWarmupFinished();
45 std::string result;
46 std::string result2;
47 std::string filtered;
48 RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo()[chain]", &filtered); //simple result filtering with path
49 QVERIFY(result=="main");
50 QVERIFY(filtered == "getblockchaininfo()[chain]");
52 RPCConsole::RPCExecuteCommandLine(result, "getblock(getbestblockhash())"); //simple 2 level nesting
53 RPCConsole::RPCExecuteCommandLine(result, "getblock(getblock(getbestblockhash())[hash], true)");
55 RPCConsole::RPCExecuteCommandLine(result, "getblock( getblock( getblock(getbestblockhash())[hash] )[hash], true)"); //4 level nesting with whitespace, filtering path and boolean parameter
57 RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo");
58 QVERIFY(result.substr(0,1) == "{");
60 RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo()");
61 QVERIFY(result.substr(0,1) == "{");
63 RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo "); //whitespace at the end will be tolerated
64 QVERIFY(result.substr(0,1) == "{");
66 (RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo()[\"chain\"]")); //Quote path identifier are allowed, but look after a child containing the quotes in the key
67 QVERIFY(result == "null");
69 (RPCConsole::RPCExecuteCommandLine(result, "createrawtransaction [] {} 0")); //parameter not in brackets are allowed
70 (RPCConsole::RPCExecuteCommandLine(result2, "createrawtransaction([],{},0)")); //parameter in brackets are allowed
71 QVERIFY(result == result2);
72 (RPCConsole::RPCExecuteCommandLine(result2, "createrawtransaction( [], {} , 0 )")); //whitespace between parameters is allowed
73 QVERIFY(result == result2);
75 RPCConsole::RPCExecuteCommandLine(result, "getblock(getbestblockhash())[tx][0]", &filtered);
76 QVERIFY(result == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
77 QVERIFY(filtered == "getblock(getbestblockhash())[tx][0]");
79 RPCConsole::RPCParseCommandLine(result, "importprivkey", false, &filtered);
80 QVERIFY(filtered == "importprivkey(…)");
81 RPCConsole::RPCParseCommandLine(result, "signmessagewithprivkey abc", false, &filtered);
82 QVERIFY(filtered == "signmessagewithprivkey(…)");
83 RPCConsole::RPCParseCommandLine(result, "signmessagewithprivkey abc,def", false, &filtered);
84 QVERIFY(filtered == "signmessagewithprivkey(…)");
85 RPCConsole::RPCParseCommandLine(result, "signrawtransaction(abc)", false, &filtered);
86 QVERIFY(filtered == "signrawtransaction(…)");
87 RPCConsole::RPCParseCommandLine(result, "walletpassphrase(help())", false, &filtered);
88 QVERIFY(filtered == "walletpassphrase(…)");
89 RPCConsole::RPCParseCommandLine(result, "walletpassphrasechange(help(walletpassphrasechange(abc)))", false, &filtered);
90 QVERIFY(filtered == "walletpassphrasechange(…)");
91 RPCConsole::RPCParseCommandLine(result, "help(encryptwallet(abc, def))", false, &filtered);
92 QVERIFY(filtered == "help(encryptwallet(…))");
93 RPCConsole::RPCParseCommandLine(result, "help(importprivkey())", false, &filtered);
94 QVERIFY(filtered == "help(importprivkey(…))");
95 RPCConsole::RPCParseCommandLine(result, "help(importprivkey(help()))", false, &filtered);
96 QVERIFY(filtered == "help(importprivkey(…))");
97 RPCConsole::RPCParseCommandLine(result, "help(importprivkey(abc), walletpassphrase(def))", false, &filtered);
98 QVERIFY(filtered == "help(importprivkey(…), walletpassphrase(…))");
100 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest");
101 QVERIFY(result == "[]");
102 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest ''");
103 QVERIFY(result == "[\"\"]");
104 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest \"\"");
105 QVERIFY(result == "[\"\"]");
106 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest '' abc");
107 QVERIFY(result == "[\"\",\"abc\"]");
108 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc '' abc");
109 QVERIFY(result == "[\"abc\",\"\",\"abc\"]");
110 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc abc");
111 QVERIFY(result == "[\"abc\",\"abc\"]");
112 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc\t\tabc");
113 QVERIFY(result == "[\"abc\",\"abc\"]");
114 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest(abc )");
115 QVERIFY(result == "[\"abc\"]");
116 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest( abc )");
117 QVERIFY(result == "[\"abc\"]");
118 RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest( abc , cba )");
119 QVERIFY(result == "[\"abc\",\"cba\"]");
121 #if QT_VERSION >= 0x050300
122 // do the QVERIFY_EXCEPTION_THROWN checks only with Qt5.3 and higher (QVERIFY_EXCEPTION_THROWN was introduced in Qt5.3)
123 QVERIFY_EXCEPTION_THROWN(RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo() .\n"), std::runtime_error); //invalid syntax
124 QVERIFY_EXCEPTION_THROWN(RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo() getblockchaininfo()"), std::runtime_error); //invalid syntax
125 (RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo(")); //tolerate non closing brackets if we have no arguments
126 (RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo()()()")); //tolerate non command brackts
127 QVERIFY_EXCEPTION_THROWN(RPCConsole::RPCExecuteCommandLine(result, "getblockchaininfo(True)"), UniValue); //invalid argument
128 QVERIFY_EXCEPTION_THROWN(RPCConsole::RPCExecuteCommandLine(result, "a(getblockchaininfo(True))"), UniValue); //method not found
129 QVERIFY_EXCEPTION_THROWN(RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest abc,,abc"), std::runtime_error); //don't tollerate empty arguments when using ,
130 QVERIFY_EXCEPTION_THROWN(RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest(abc,,abc)"), std::runtime_error); //don't tollerate empty arguments when using ,
131 QVERIFY_EXCEPTION_THROWN(RPCConsole::RPCExecuteCommandLine(result, "rpcNestedTest(abc,,)"), std::runtime_error); //don't tollerate empty arguments when using ,
132 #endif