Browse Source

preparing for tests

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
1fc7e1b76b
  1. 8
      eth/EthStubServer.cpp
  2. 2
      eth/EthStubServer.h
  3. 6
      eth/abstractethstubserver.h
  4. 2
      eth/eth.js
  5. 2
      eth/main.cpp
  6. 2
      eth/spec.json
  7. 3
      libethereum/BlockChain.cpp
  8. 6
      test/CMakeLists.txt
  9. 414
      test/ethstubclient.h
  10. 69
      test/jsonrpc.cpp

8
eth/EthStubServer.cpp

@ -20,7 +20,7 @@
* @date 2014
*/
//#if ETH_JSONRPC
#if ETH_JSONRPC
#include "EthStubServer.h"
#include <libevmface/Instruction.h>
#include <liblll/Compiler.h>
@ -327,9 +327,9 @@ std::string EthStubServer::sha3(const string &s)
return toJS(dev::eth::sha3(jsToBytes(s)));
}
std::string EthStubServer::stateAt(const string &a, const int& block, const string &p)
std::string EthStubServer::stateAt(const string &a, const int& block, const string &s)
{
return client() ? toJS(client()->stateAt(jsToAddress(a), jsToU256(p), block)) : "";
return client() ? toJS(client()->stateAt(jsToAddress(a), jsToU256(s), block)) : "";
}
std::string EthStubServer::toAscii(const string &s)
@ -422,4 +422,4 @@ Json::Value EthStubServer::jsontypeToValue(int _jsontype)
}
}
//#endif
#endif

2
eth/EthStubServer.h

@ -58,7 +58,7 @@ public:
virtual Json::Value setListening(const bool& l);
virtual Json::Value setMining(const bool& l);
virtual std::string sha3(const std::string& s);
virtual std::string stateAt(const std::string& a, const int& block, const std::string& p);
virtual std::string stateAt(const std::string& a, const int& block, const std::string& s);
virtual std::string toAscii(const std::string& s);
virtual std::string toDecimal(const std::string& s);
virtual std::string toFixed(const double& s);

6
eth/abstractethstubserver.h

@ -35,7 +35,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "l",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "l",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::sha3I);
this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER,"p",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("toDecimal", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toDecimalI);
this->bindAndAddMethod(new jsonrpc::Procedure("toFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_REAL, NULL), &AbstractEthStubServer::toFixedI);
@ -158,7 +158,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void stateAtI(const Json::Value& request, Json::Value& response)
{
response = this->stateAt(request["a"].asString(), request["block"].asInt(), request["p"].asString());
response = this->stateAt(request["a"].asString(), request["block"].asInt(), request["s"].asString());
}
inline virtual void toAsciiI(const Json::Value& request, Json::Value& response)
@ -219,7 +219,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual Json::Value setListening(const bool& l) = 0;
virtual Json::Value setMining(const bool& l) = 0;
virtual std::string sha3(const std::string& s) = 0;
virtual std::string stateAt(const std::string& a, const int& block, const std::string& p) = 0;
virtual std::string stateAt(const std::string& a, const int& block, const std::string& s) = 0;
virtual std::string toAscii(const std::string& s) = 0;
virtual std::string toDecimal(const std::string& s) = 0;
virtual std::string toFixed(const double& s) = 0;

2
eth/eth.js

@ -32,7 +32,7 @@ var spec = [
// synchronous getters
{ "method": "balanceAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "a": "", "p": "", "block": 0}, "order": ["a", "p", "block"], "returns": ""},
{ "method": "stateAt", "params": { "a": "", "s": "", "block": 0}, "order": ["a", "s", "block"], "returns": ""},
{ "method": "countAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "codeAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns": ""},

2
eth/main.cpp

@ -177,7 +177,7 @@ int main(int argc, char** argv)
unsigned peers = 5;
bool interactive = false;
#if ETH_JSONRPC
int jsonrpc = -1;
int jsonrpc = -1;
#endif
string publicIP;
bool bootstrap = false;

2
eth/spec.json

@ -13,7 +13,7 @@
{ "method": "balanceAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "a": "", "p": "", "block": 0}, "order": ["a", "p", "block"], "returns": ""},
{ "method": "stateAt", "params": { "a": "", "s": "", "block": 0}, "order": ["a", "s", "block"], "returns": ""},
{ "method": "countAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "codeAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns": ""},

3
libethereum/BlockChain.cpp

@ -159,7 +159,8 @@ void BlockChain::open(std::string _path, bool _killExisting)
m_lastBlockHash = l.empty() ? m_genesisHash : *(h256*)l.data();
cnote << "Opened blockchain DB. Latest: " << currentHash();
cnote << _path;
cnote << "Opened blockchain DB. Latest: " << currentHash();
}
void BlockChain::close()

6
test/CMakeLists.txt

@ -6,6 +6,7 @@ include_directories(..)
link_directories(../libethcore)
link_directories(../libethereum)
add_executable(testeth ${SRC_LIST})
target_link_libraries(testeth ethereum)
@ -13,6 +14,11 @@ target_link_libraries(testeth ethcore)
target_link_libraries(testeth secp256k1)
target_link_libraries(testeth gmp)
target_link_libraries(testeth ${CRYPTOPP_LS})
target_link_libraries(testeth webthree)
if(JSONRPC_LS)
target_link_libraries(testeth ${JSONRPC_LS})
endif()
if ("${TARGET_PLATFORM}" STREQUAL "w64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")

414
test/ethstubclient.h

@ -0,0 +1,414 @@
/**
* THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!!
*/
#ifndef _ETHSTUBCLIENT_H_
#define _ETHSTUBCLIENT_H_
#include <jsonrpc/rpc.h>
class EthStubClient
{
public:
EthStubClient(jsonrpc::AbstractClientConnector* conn)
{
this->client = new jsonrpc::Client(conn);
}
~EthStubClient()
{
delete this->client;
}
std::string balanceAt(const std::string& a, const int& block) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["block"] = block;
Json::Value result = this->client->CallMethod("balanceAt",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value block(const std::string& numberOrHash) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["numberOrHash"] = numberOrHash;
Json::Value result = this->client->CallMethod("block",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string call(const Json::Value& json) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["json"] = json;
Json::Value result = this->client->CallMethod("call",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string codeAt(const std::string& a, const int& block) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["block"] = block;
Json::Value result = this->client->CallMethod("codeAt",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string coinbase() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("coinbase",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string countAt(const std::string& a, const int& block) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["block"] = block;
Json::Value result = this->client->CallMethod("countAt",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int defaultBlock() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("defaultBlock",p);
if (result.isInt())
return result.asInt();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string fromAscii(const int& padding, const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["padding"] = padding;
p["s"] = s;
Json::Value result = this->client->CallMethod("fromAscii",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
double fromFixed(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("fromFixed",p);
if (result.isDouble())
return result.asDouble();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string gasPrice() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("gasPrice",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool isListening() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("isListening",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool isMining() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("isMining",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string key() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("key",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value keys() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("keys",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string lll(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("lll",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value messages(const Json::Value& json) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["json"] = json;
Json::Value result = this->client->CallMethod("messages",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int number() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("number",p);
if (result.isInt())
return result.asInt();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int peerCount() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("peerCount",p);
if (result.isInt())
return result.asInt();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string secretToAddress(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("secretToAddress",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value setListening(const bool& l) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["l"] = l;
Json::Value result = this->client->CallMethod("setListening",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value setMining(const bool& l) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["l"] = l;
Json::Value result = this->client->CallMethod("setMining",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string sha3(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("sha3",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string stateAt(const std::string& a, const int& block, const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["block"] = block;
p["s"] = s;
Json::Value result = this->client->CallMethod("stateAt",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string toAscii(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("toAscii",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string toDecimal(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("toDecimal",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string toFixed(const double& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("toFixed",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string transact(const std::string& json) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["json"] = json;
Json::Value result = this->client->CallMethod("transact",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value transaction(const int& i, const std::string& numberOrHash) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["i"] = i;
p["numberOrHash"] = numberOrHash;
Json::Value result = this->client->CallMethod("transaction",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value uncle(const int& i, const std::string& numberOrHash) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["i"] = i;
p["numberOrHash"] = numberOrHash;
Json::Value result = this->client->CallMethod("uncle",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string watch(const std::string& json) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["json"] = json;
Json::Value result = this->client->CallMethod("watch",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
private:
jsonrpc::Client* client;
};
#endif //_ETHSTUBCLIENT_H_

69
test/jsonrpc.cpp

@ -0,0 +1,69 @@
#if ETH_JSONRPC && 1
#include <boost/test/unit_test.hpp>
#include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h>
#include <libwebthree/WebThree.h>
#include <eth/EthStubServer.h>
#include <jsonrpc/connectors/httpserver.h>
#include "JsonSpiritHeaders.h"
#include "ethstubclient.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
namespace js = json_spirit;
namespace jsonrpc_tests {
auto_ptr<EthStubServer> jsonrpcServer;
struct JsonrpcFixture {
JsonrpcFixture()
{
cnote << "setup jsonrpc";
string name = "Ethereum(++) tests";
string dbPath;
dev::WebThreeDirect web3(name, dbPath);
web3.setIdealPeerCount(5);
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::HttpServer(8080), web3));
}
~JsonrpcFixture()
{
cnote << "teardown jsonrpc";
}
};
//BOOST_AUTO_TEST_CASE(jsonrpc_test)
//{
// cnote << "testing jsonrpc";
// js::mValue v;
// string s = asString(contents("../../jsonrpc.json"));
// BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content from 'jsonrpc.json' is empty. Have you cloned the 'tests' repo branch develop?");
// js::read_string(s, v);
//}
BOOST_GLOBAL_FIXTURE(JsonrpcFixture)
BOOST_AUTO_TEST_CASE( test_case1 )
{
// BOOST_CHECK( i == 1 );
}
BOOST_AUTO_TEST_CASE( test_case2 )
{
// BOOST_CHECK_EQUAL( i, 0 );
}
}
#endif
Loading…
Cancel
Save