diff --git a/CMakeLists.txt b/CMakeLists.txt index e623c7319..df67d94f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,6 +335,9 @@ endif() endif() add_subdirectory(lllc) add_subdirectory(sc) +if(JSONRPC_LS) +add_subdirectory(libethrpc) +endif() if (NOT LANGUAGES) add_subdirectory(secp256k1) add_subdirectory(libp2p) diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index eee1d258b..2ede84a31 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) if(JSONRPC_LS) target_link_libraries(${EXECUTABLE} ${JSONRPC_LS}) +target_link_libraries(${EXECUTABLE} ethrpc) endif() if(READLINE_LS) target_link_libraries(${EXECUTABLE} ${READLINE_LS}) diff --git a/eth/main.cpp b/eth/main.cpp index 76cd0dac0..40932d0a4 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -39,7 +39,7 @@ #include #endif #if ETH_JSONRPC -#include "EthStubServer.h" +#include #endif #include "BuildInfo.h" using namespace std; diff --git a/eth/BigInteger.js b/libethrpc/BigInteger.js similarity index 100% rename from eth/BigInteger.js rename to libethrpc/BigInteger.js diff --git a/libethrpc/CMakeLists.txt b/libethrpc/CMakeLists.txt new file mode 100644 index 000000000..069104fee --- /dev/null +++ b/libethrpc/CMakeLists.txt @@ -0,0 +1,57 @@ +cmake_policy(SET CMP0015 NEW) + +aux_source_directory(. SRC_LIST) + +include_directories(..) +link_directories(../libethcore) +link_directories(../libwebthree) + +set(EXECUTABLE ethrpc) + +if(ETH_STATIC) + add_library(${EXECUTABLE} STATIC ${SRC_LIST}) +else() + add_library(${EXECUTABLE} SHARED ${SRC_LIST}) +endif() + +file(GLOB HEADERS "*.h") + +target_link_libraries(${EXECUTABLE} webthree) +target_link_libraries(${EXECUTABLE} secp256k1) +target_link_libraries(${EXECUTABLE} gmp) +if(MINIUPNPC_LS) + target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS}) +endif() +target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) +target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) +if(JSONRPC_LS) +target_link_libraries(${EXECUTABLE} ${JSONRPC_LS}) +endif() +if(READLINE_LS) +target_link_libraries(${EXECUTABLE} ${READLINE_LS}) +endif() + +if ("${TARGET_PLATFORM}" STREQUAL "w64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + target_link_libraries(${EXECUTABLE} boost_system-mt-s) + target_link_libraries(${EXECUTABLE} boost_filesystem-mt-s) + target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) + target_link_libraries(${EXECUTABLE} gcc) + target_link_libraries(${EXECUTABLE} gdi32) + target_link_libraries(${EXECUTABLE} ws2_32) + target_link_libraries(${EXECUTABLE} mswsock) + target_link_libraries(${EXECUTABLE} shlwapi) + target_link_libraries(${EXECUTABLE} iphlpapi) + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) +elseif (UNIX) +else () + target_link_libraries(${EXECUTABLE} boost_system) + target_link_libraries(${EXECUTABLE} boost_filesystem) + find_package(Threads REQUIRED) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +endif () + +install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) + + diff --git a/eth/EthStubServer.cpp b/libethrpc/EthStubServer.cpp similarity index 100% rename from eth/EthStubServer.cpp rename to libethrpc/EthStubServer.cpp diff --git a/eth/EthStubServer.h b/libethrpc/EthStubServer.h similarity index 100% rename from eth/EthStubServer.h rename to libethrpc/EthStubServer.h diff --git a/eth/abstractethstubserver.h b/libethrpc/abstractethstubserver.h similarity index 100% rename from eth/abstractethstubserver.h rename to libethrpc/abstractethstubserver.h diff --git a/eth/eth.js b/libethrpc/eth.js similarity index 100% rename from eth/eth.js rename to libethrpc/eth.js diff --git a/eth/ethString.js b/libethrpc/ethString.js similarity index 100% rename from eth/ethString.js rename to libethrpc/ethString.js diff --git a/eth/spec.json b/libethrpc/spec.json similarity index 100% rename from eth/spec.json rename to libethrpc/spec.json diff --git a/neth/CMakeLists.txt b/neth/CMakeLists.txt index 2b3f92947..ddd0d9752 100644 --- a/neth/CMakeLists.txt +++ b/neth/CMakeLists.txt @@ -22,6 +22,7 @@ target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) if(JSONRPC_LS) target_link_libraries(${EXECUTABLE} ${JSONRPC_LS}) +target_link_libraries(${EXECUTABLE} ethrpc) endif() if ("${TARGET_PLATFORM}" STREQUAL "w64") diff --git a/neth/main.cpp b/neth/main.cpp index 661556283..a5d914ffb 100644 --- a/neth/main.cpp +++ b/neth/main.cpp @@ -33,9 +33,8 @@ #include #include #if ETH_JSONRPC -#include -#include -#include +#include +#include #include #endif #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1824e8d4d..e9250ebe3 100644 --- a/test/CMakeLists.txt +++ b/test/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/test/jsonrpc.cpp b/test/jsonrpc.cpp index 751539c69..101e3d25f 100644 --- a/test/jsonrpc.cpp +++ b/test/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