Browse Source

Expose CRPCTable via bitcoinrpc.h for testing

pull/1/head
Pieter Wuille 10 years ago
parent
commit
e46704dd90
  1. 31
      src/bitcoinrpc.cpp
  2. 34
      src/bitcoinrpc.h
  3. 9
      src/test/rpc_tests.cpp

31
src/bitcoinrpc.cpp

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
#include "net.h"
#include "init.h"
#include "ui_interface.h"
#include "bitcoinrpc.h"
#undef printf
#include <boost/asio.hpp>
@ -22,9 +23,6 @@ @@ -22,9 +23,6 @@
#include <boost/filesystem/fstream.hpp>
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream;
#include "json/json_spirit_reader_template.h"
#include "json/json_spirit_writer_template.h"
#include "json/json_spirit_utils.h"
#define printf OutputDebugStringF
// MinGW 3.4.5 gets "fatal error: had to relocate PCH" if the json headers are
// precompiled in headers.h. The problem might be when the pch file goes over
@ -37,27 +35,6 @@ using namespace boost::asio; @@ -37,27 +35,6 @@ using namespace boost::asio;
using namespace json_spirit;
void ThreadRPCServer2(void* parg);
typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
class CRPCCommand
{
public:
string name;
rpcfn_type actor;
bool okSafeMode;
};
class CRPCTable
{
private:
map<string, const CRPCCommand*> mapCommands;
public:
CRPCTable();
const CRPCCommand* operator[](string name) const;
string help(string name) const;
};
const CRPCTable tableRPC;
static std::string strRPCUserColonPass;
@ -2028,7 +2005,7 @@ Value getblock(const Array& params, bool fHelp) @@ -2028,7 +2005,7 @@ Value getblock(const Array& params, bool fHelp)
//
static CRPCCommand vRPCCommands[] =
static const CRPCCommand vRPCCommands[] =
{ // name function safe mode?
// ------------------------ ----------------------- ----------
{ "help", &help, true },
@ -2084,7 +2061,7 @@ CRPCTable::CRPCTable() @@ -2084,7 +2061,7 @@ CRPCTable::CRPCTable()
unsigned int vcidx;
for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++)
{
CRPCCommand *pcmd;
const CRPCCommand *pcmd;
pcmd = &vRPCCommands[vcidx];
mapCommands[pcmd->name] = pcmd;
@ -2785,3 +2762,5 @@ int main(int argc, char *argv[]) @@ -2785,3 +2762,5 @@ int main(int argc, char *argv[])
return 0;
}
#endif
const CRPCTable tableRPC;

34
src/bitcoinrpc.h

@ -3,5 +3,39 @@ @@ -3,5 +3,39 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef _BITCOINRPC_H_
#define _BITCOINRPC_H_ 1
#include <string>
#include <map>
#include "json/json_spirit_reader_template.h"
#include "json/json_spirit_writer_template.h"
#include "json/json_spirit_utils.h"
void ThreadRPCServer(void* parg);
int CommandLineRPC(int argc, char *argv[]);
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
class CRPCCommand
{
public:
std::string name;
rpcfn_type actor;
bool okSafeMode;
};
class CRPCTable
{
private:
std::map<std::string, const CRPCCommand*> mapCommands;
public:
CRPCTable();
const CRPCCommand* operator[](std::string name) const;
std::string help(std::string name) const;
};
extern const CRPCTable tableRPC;
#endif

9
src/test/rpc_tests.cpp

@ -3,16 +3,11 @@ @@ -3,16 +3,11 @@
#include "base58.h"
#include "util.h"
#include "json/json_spirit_reader_template.h"
#include "json/json_spirit_writer_template.h"
#include "json/json_spirit_utils.h"
#include "bitcoinrpc.h"
using namespace std;
using namespace json_spirit;
typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
extern map<string, rpcfn_type> mapCallTable;
BOOST_AUTO_TEST_SUITE(rpc_tests)
static Array
@ -36,7 +31,7 @@ struct TestNetFixture @@ -36,7 +31,7 @@ struct TestNetFixture
BOOST_FIXTURE_TEST_CASE(rpc_addmultisig, TestNetFixture)
{
rpcfn_type addmultisig = mapCallTable["addmultisigaddress"];
rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor;
// old, 65-byte-long:
const char* address1Hex = "0434e3e09f49ea168c5bbf53f877ff4206923858aab7c7e1df25bc263978107c95e35065a27ef6f1b27222db0ec97e0e895eaca603d3ee0d4c060ce3d8a00286c8";

Loading…
Cancel
Save