From d47f9be77534022ad8c5e6fa614219d95302e79f Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 13 Oct 2014 12:28:53 +0200 Subject: ethrpc separated && first tests --- CMakeLists.txt | 2 +- jsonrpc.cpp | 41 ++++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1824e8d4..e9250ebe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ target_link_libraries(testeth ${CRYPTOPP_LS}) target_link_libraries(testeth webthree) if(JSONRPC_LS) -target_link_libraries(testeth ${JSONRPC_LS}) +target_link_libraries(testeth ethrpc) endif() if ("${TARGET_PLATFORM}" STREQUAL "w64") diff --git a/jsonrpc.cpp b/jsonrpc.cpp index 751539c6..101e3d25 100644 --- a/jsonrpc.cpp +++ b/jsonrpc.cpp @@ -5,9 +5,11 @@ #include #include #include +#include #include -#include +#include #include +#include #include "JsonSpiritHeaders.h" #include "ethstubclient.h" @@ -17,11 +19,11 @@ using namespace dev::eth; namespace js = json_spirit; - - namespace jsonrpc_tests { +KeyPair us; auto_ptr jsonrpcServer; +auto_ptr jsonrpcClient; struct JsonrpcFixture { @@ -32,7 +34,13 @@ struct JsonrpcFixture { string dbPath; dev::WebThreeDirect web3(name, dbPath); web3.setIdealPeerCount(5); + + us = KeyPair::create(); jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(8080), web3)); + jsonrpcServer->setKeys({us}); + jsonrpcServer->StartListening(); + + jsonrpcClient = auto_ptr(new EthStubClient(new jsonrpc::HttpClient("http://localhost:8080"))); } ~JsonrpcFixture() { @@ -40,27 +48,26 @@ struct JsonrpcFixture { } }; -//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_AUTO_TEST_CASE(jsonrpc_key) { -// BOOST_CHECK( i == 1 ); + cnote << "Testing jsonrpc key..."; + Json::Value key = jsonrpcClient->key(); + BOOST_CHECK_EQUAL(key.isString(), true); + BOOST_CHECK_EQUAL(jsToSecret(key.asString()), us.secret()); } - -BOOST_AUTO_TEST_CASE( test_case2 ) + +BOOST_AUTO_TEST_CASE(jsonrpc_keys) { -// BOOST_CHECK_EQUAL( i, 0 ); + 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()); } + } #endif -- cgit v1.2.3