Changeset View
Changeset View
Standalone View
Standalone View
src/test/rpc_tests.cpp
// Copyright (c) 2012-2019 The Bitcoin Core developers | // Copyright (c) 2012-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <rpc/client.h> | #include <rpc/client.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <core_io.h> | #include <core_io.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <util/ref.h> | |||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/algorithm/string.hpp> | #include <boost/algorithm/string.hpp> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
UniValue CallRPC(std::string args) { | UniValue CallRPC(const std::string &args, const util::Ref &context) { | ||||
std::vector<std::string> vArgs; | std::vector<std::string> vArgs; | ||||
boost::split(vArgs, args, boost::is_any_of(" \t")); | boost::split(vArgs, args, boost::is_any_of(" \t")); | ||||
std::string strMethod = vArgs[0]; | std::string strMethod = vArgs[0]; | ||||
vArgs.erase(vArgs.begin()); | vArgs.erase(vArgs.begin()); | ||||
GlobalConfig config; | GlobalConfig config; | ||||
JSONRPCRequest request; | JSONRPCRequest request(context); | ||||
request.strMethod = strMethod; | request.strMethod = strMethod; | ||||
request.params = RPCConvertValues(strMethod, vArgs); | request.params = RPCConvertValues(strMethod, vArgs); | ||||
request.fHelp = false; | request.fHelp = false; | ||||
if (RPCIsInWarmup(nullptr)) { | if (RPCIsInWarmup(nullptr)) { | ||||
SetRPCWarmupFinished(); | SetRPCWarmupFinished(); | ||||
} | } | ||||
try { | try { | ||||
UniValue result = tableRPC.execute(config, request); | UniValue result = tableRPC.execute(config, request); | ||||
return result; | return result; | ||||
} catch (const UniValue &objError) { | } catch (const UniValue &objError) { | ||||
throw std::runtime_error(find_value(objError, "message").get_str()); | throw std::runtime_error(find_value(objError, "message").get_str()); | ||||
} | } | ||||
} | } | ||||
BOOST_FIXTURE_TEST_SUITE(rpc_tests, TestingSetup) | class RPCTestingSetup : public TestingSetup { | ||||
public: | |||||
UniValue CallRPC(const std::string &args) { | |||||
const util::Ref context{m_node}; | |||||
return ::CallRPC(args, context); | |||||
} | |||||
}; | |||||
BOOST_FIXTURE_TEST_SUITE(rpc_tests, RPCTestingSetup) | |||||
BOOST_AUTO_TEST_CASE(rpc_rawparams) { | BOOST_AUTO_TEST_CASE(rpc_rawparams) { | ||||
// Test raw transaction API argument handling | // Test raw transaction API argument handling | ||||
UniValue r; | UniValue r; | ||||
BOOST_CHECK_THROW(CallRPC("getrawtransaction"), std::runtime_error); | BOOST_CHECK_THROW(CallRPC("getrawtransaction"), std::runtime_error); | ||||
BOOST_CHECK_THROW(CallRPC("getrawtransaction not_hex"), std::runtime_error); | BOOST_CHECK_THROW(CallRPC("getrawtransaction not_hex"), std::runtime_error); | ||||
BOOST_CHECK_THROW(CallRPC("getrawtransaction " | BOOST_CHECK_THROW(CallRPC("getrawtransaction " | ||||
▲ Show 20 Lines • Show All 454 Lines • Show Last 20 Lines |