Browse Source

Merge branch '1351_libtestutils' into 1351_ethrpctest

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
989aeb8e50
  1. 3
      libtestutils/BlockChainLoader.h
  2. 16
      libtestutils/CMakeLists.txt
  3. 4
      libtestutils/FixedClient.h
  4. 20
      libtestutils/FixedWebThreeServer.cpp
  5. 25
      libtestutils/FixedWebThreeServer.h
  6. 13
      libtestutils/ShortLivingDirectory.cpp
  7. 11
      libtestutils/ShortLivingDirectory.h
  8. 3
      libtestutils/StateLoader.cpp
  9. 5
      libtestutils/StateLoader.h

3
libtestutils/BlockChainLoader.h

@ -32,7 +32,8 @@ namespace test
{
/**
* @brief - loads the blockchain from json, creates temporary directory to store it, removes this temporary directory on dealloc
* @brief Should be used to load test blockchain from json file
* Loads the blockchain from json, creates temporary directory to store it, removes the directory on dealloc
*/
class BlockChainLoader
{

16
libtestutils/CMakeLists.txt

@ -11,9 +11,7 @@ aux_source_directory(. SRC_LIST)
include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS})
include_directories(BEFORE ..)
include_directories(${MHD_INCLUDE_DIRS})
include_directories(${JSON_RPC_CPP_INCLUDE_DIRS})
include_directories(${LEVELDB_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
set(EXECUTABLE testutils)
@ -26,18 +24,10 @@ else()
add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS})
endif()
target_link_libraries(${EXECUTABLE} ${LEVELDB_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${JSON_RPC_CPP_SERVER_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${MHD_LIBRARIES})
target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} secp256k1)
target_link_libraries(${EXECUTABLE} solidity)
if (NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"))
target_link_libraries(${EXECUTABLE} serpent)
endif()
target_link_libraries(${EXECUTABLE} ethereum)
target_link_libraries(${EXECUTABLE} web3jsonrpc)
install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )

4
libtestutils/FixedClient.h

@ -30,6 +30,10 @@ namespace dev
namespace test
{
/**
* @brief mvp implementation of ClientBase
* Doesn't support mining interface
*/
class FixedClient: public dev::eth::ClientBase
{
public:

20
libtestutils/FixedWebThreeServer.cpp

@ -1,2 +1,22 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file FixedWebThreeStubServer.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
#include "FixedWebThreeServer.h"

25
libtestutils/FixedWebThreeServer.h

@ -1,10 +1,35 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file FixedWebThreeStubServer.h
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
#pragma once
#include <libdevcore/Exceptions.h>
#include <libweb3jsonrpc/WebThreeStubServerBase.h>
/**
* @brief dummy JSON-RPC api implementation
* Should be used for test purposes only
* Supports eth && db interfaces
* Doesn't support shh && net interfaces
*/
class FixedWebThreeServer: public dev::WebThreeStubServerBase, public dev::WebThreeStubDatabaseFace
{
public:

13
libtestutils/ShortLivingDirectory.cpp

@ -20,21 +20,20 @@
*/
#include <boost/filesystem.hpp>
#include <libdevcore/Exceptions.h>
#include "ShortLivingDirectory.h"
#include "Common.h"
using namespace std;
using namespace dev;
using namespace dev::test;
ShortLivingDirectory::ShortLivingDirectory()
{
m_path = getRandomPath();
boost::filesystem::create_directories(m_path);
}
ShortLivingDirectory::ShortLivingDirectory(std::string const& _path) : m_path(_path)
{
// we never ever want to delete a directory (including all its contents) that we did not create ourselves.
if (boost::filesystem::exists(m_path)) {
BOOST_THROW_EXCEPTION(FileError());
}
boost::filesystem::create_directories(m_path);
}

11
libtestutils/ShortLivingDirectory.h

@ -22,20 +22,25 @@
#pragma once
#include <string>
#include "Common.h"
namespace dev
{
namespace test
{
/**
* @brief temporary directory implementation
* It creates temporary directory in the given path. On dealloc it removes the directory
* @throws if the given path already exists, throws an exception
*/
class ShortLivingDirectory
{
public:
ShortLivingDirectory();
ShortLivingDirectory(std::string const& _path);
ShortLivingDirectory(std::string const& _path = getRandomPath());
~ShortLivingDirectory();
std::string path(){ return m_path; }
std::string const& path() { return m_path; }
private:
std::string m_path;

3
libtestutils/StateLoader.cpp

@ -26,8 +26,7 @@ using namespace dev;
using namespace dev::eth;
using namespace dev::test;
StateLoader::StateLoader(Json::Value const& _json)
: m_state(Address(), OverlayDB(), BaseState::Empty)
StateLoader::StateLoader(Json::Value const& _json) : m_state(Address(), OverlayDB(), BaseState::Empty)
{
for (string const& name: _json.getMemberNames())
{

5
libtestutils/StateLoader.h

@ -29,11 +29,14 @@ namespace dev
namespace test
{
/**
* @brief Friend of State, loads State from given JSON object
*/
class StateLoader
{
public:
StateLoader(Json::Value const& _json);
eth::State state() { return m_state; }
eth::State const& state() { return m_state; }
private:
eth::State m_state;

Loading…
Cancel
Save