MCPcopy Create free account
hub / github.com/ElementsProject/elements / rpcNestedTests

Method rpcNestedTests

src/qt/test/rpcnestedtests.cpp:41–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39};
40
41void RPCNestedTests::rpcNestedTests()
42{
43 // do some test setup
44 // could be moved to a more generic place when we add more tests on QT level
45 for (const auto& c : vRPCCommands) {
46 tableRPC.appendCommand(c.name, &c);
47 }
48
49 TestingSetup test;
50 m_node.setContext(&test.m_node);
51 CBlockIndex::SetNodeContext(&test.m_node);
52
53 if (RPCIsInWarmup(nullptr)) SetRPCWarmupFinished();
54
55 std::string result;
56 std::string result2;
57 std::string filtered;
58 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo()[chain]", &filtered); //simple result filtering with path
59 QVERIFY(result=="main");
60 QVERIFY(filtered == "getblockchaininfo()[chain]");
61
62 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblock(getbestblockhash())"); //simple 2 level nesting
63 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblock(getblock(getbestblockhash())[hash], true)");
64
65 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblock( getblock( getblock(getbestblockhash())[hash] )[hash], true)"); //4 level nesting with whitespace, filtering path and boolean parameter
66
67 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo");
68 QVERIFY(result.substr(0,1) == "{");
69
70 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo()");
71 QVERIFY(result.substr(0,1) == "{");
72
73 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo "); //whitespace at the end will be tolerated
74 QVERIFY(result.substr(0,1) == "{");
75
76 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo()[\"chain\"]"); //Quote path identifier are allowed, but look after a child containing the quotes in the key
77 QVERIFY(result == "null");
78
79 RPCConsole::RPCExecuteCommandLine(m_node, result, "createrawtransaction [] [] 0"); //parameter not in brackets are allowed
80 RPCConsole::RPCExecuteCommandLine(m_node, result2, "createrawtransaction([],[],0)"); //parameter in brackets are allowed
81 QVERIFY(result == result2);
82 RPCConsole::RPCExecuteCommandLine(m_node, result2, "createrawtransaction( [], [] , 0 )"); //whitespace between parameters is allowed
83 QVERIFY(result == result2);
84
85 RPCConsole::RPCExecuteCommandLine(m_node, result, "getblock(getbestblockhash())[tx][0]", &filtered);
86 QVERIFY(result == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
87 QVERIFY(filtered == "getblock(getbestblockhash())[tx][0]");
88
89 RPCConsole::RPCParseCommandLine(nullptr, result, "importprivkey", false, &filtered);
90 QVERIFY(filtered == "importprivkey(…)");
91 RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc", false, &filtered);
92 QVERIFY(filtered == "signmessagewithprivkey(…)");
93 RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc,def", false, &filtered);
94 QVERIFY(filtered == "signmessagewithprivkey(…)");
95 RPCConsole::RPCParseCommandLine(nullptr, result, "signrawtransactionwithkey(abc)", false, &filtered);
96 QVERIFY(filtered == "signrawtransactionwithkey(…)");
97 RPCConsole::RPCParseCommandLine(nullptr, result, "walletpassphrase(help())", false, &filtered);
98 QVERIFY(filtered == "walletpassphrase(…)");

Callers

nothing calls this directly

Calls 5

RPCIsInWarmupFunction · 0.85
SetRPCWarmupFinishedFunction · 0.85
RPCExecuteCommandLineFunction · 0.85
appendCommandMethod · 0.80
setContextMethod · 0.45

Tested by

no test coverage detected