solidity/jsonrpc.cpp

77 lines
1.8 KiB
C++
Raw Normal View History

2014-10-13 09:22:28 +00:00
#if ETH_JSONRPC && 1
#include <boost/test/unit_test.hpp>
#include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h>
2014-10-13 10:28:53 +00:00
#include <libdevcore/CommonJS.h>
2014-10-13 09:22:28 +00:00
#include <libwebthree/WebThree.h>
2014-10-13 10:28:53 +00:00
#include <libethrpc/EthStubServer.h>
2014-10-13 09:22:28 +00:00
#include <jsonrpc/connectors/httpserver.h>
2014-10-13 10:28:53 +00:00
#include <jsonrpc/connectors/httpclient.h>
2014-10-13 09:22:28 +00:00
#include "JsonSpiritHeaders.h"
#include "ethstubclient.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
namespace js = json_spirit;
namespace jsonrpc_tests {
2014-10-13 10:28:53 +00:00
KeyPair us;
2014-10-13 09:22:28 +00:00
auto_ptr<EthStubServer> jsonrpcServer;
2014-10-13 10:28:53 +00:00
auto_ptr<EthStubClient> jsonrpcClient;
2014-10-13 09:22:28 +00:00
struct JsonrpcFixture {
JsonrpcFixture()
{
cnote << "setup jsonrpc";
string name = "Ethereum(++) tests";
string dbPath;
dev::WebThreeDirect web3(name, dbPath);
web3.setIdealPeerCount(5);
2014-10-13 10:28:53 +00:00
us = KeyPair::create();
2014-10-13 09:22:28 +00:00
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::HttpServer(8080), web3));
2014-10-13 10:28:53 +00:00
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
jsonrpcClient = auto_ptr<EthStubClient>(new EthStubClient(new jsonrpc::HttpClient("http://localhost:8080")));
2014-10-13 09:22:28 +00:00
}
~JsonrpcFixture()
{
cnote << "teardown jsonrpc";
}
};
BOOST_GLOBAL_FIXTURE(JsonrpcFixture)
2014-10-13 10:28:53 +00:00
BOOST_AUTO_TEST_CASE(jsonrpc_key)
2014-10-13 09:22:28 +00:00
{
2014-10-13 10:28:53 +00:00
cnote << "Testing jsonrpc key...";
Json::Value key = jsonrpcClient->key();
BOOST_CHECK_EQUAL(key.isString(), true);
BOOST_CHECK_EQUAL(jsToSecret(key.asString()), us.secret());
2014-10-13 09:22:28 +00:00
}
2014-10-13 10:28:53 +00:00
BOOST_AUTO_TEST_CASE(jsonrpc_keys)
2014-10-13 09:22:28 +00:00
{
2014-10-13 10:28:53 +00:00
cnote << "Testing jsonrpc keys...";
Json::Value keys = jsonrpcClient->keys();
BOOST_CHECK_EQUAL(keys.isArray(), true);
BOOST_CHECK_EQUAL(keys.size(), 1);
BOOST_CHECK_EQUAL(jsToSecret(keys[0u].asString()) , us.secret());
2014-10-13 09:22:28 +00:00
}
2014-10-13 10:28:53 +00:00
2014-10-13 09:22:28 +00:00
}
#endif