Browse Source

Merge branch '1351_libtestutils' into 1351_ethrpctest

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
724dcc83eb
  1. 1
      libtestutils/BlockChainLoader.cpp
  2. 10
      libtestutils/BlockChainLoader.h
  3. 11
      libtestutils/FixedClient.cpp
  4. 4
      libtestutils/FixedClient.h
  5. 2
      libtestutils/StateLoader.h
  6. 8
      libtestutils/TransientDirectory.cpp
  7. 10
      libtestutils/TransientDirectory.h

1
libtestutils/BlockChainLoader.cpp

@ -34,7 +34,6 @@ namespace test
{
dev::eth::BlockInfo toBlockInfo(Json::Value const& _json);
bytes toGenesisBlock(Json::Value const& _json);
}
}

10
libtestutils/BlockChainLoader.h

@ -24,7 +24,7 @@
#include <json/json.h>
#include <libethereum/BlockChain.h>
#include <libethereum/State.h>
#include "ShortLivingDirectory.h"
#include "TransientDirectory.h"
namespace dev
{
@ -39,11 +39,11 @@ class BlockChainLoader
{
public:
BlockChainLoader(Json::Value const& _json);
eth::BlockChain& bc() { return *m_bc; }
eth::State state() { return m_state; }
eth::BlockChain const& bc() const { return *m_bc; }
eth::State const& state() const { return m_state; }
private:
ShortLivingDirectory m_dir;
TransientDirectory m_dir;
std::auto_ptr<eth::BlockChain> m_bc;
eth::State m_state;
};

11
libtestutils/FixedClient.cpp

@ -25,16 +25,7 @@ using namespace dev;
using namespace dev::eth;
using namespace dev::test;
eth::State FixedClient::asOf(BlockNumber _h) const
{
ReadGuard l(x_stateDB);
if (_h == PendingBlock || _h == LatestBlock)
return m_state;
return State(m_state.db(), bc(), bc().numberHash(_h));
}
eth::State FixedClient::asOf(h256 _h) const
eth::State FixedClient::asOf(h256 const& _h) const
{
ReadGuard l(x_stateDB);
return State(m_state.db(), bc(), _h);

4
libtestutils/FixedClient.h

@ -43,8 +43,8 @@ public:
// stub
virtual void flushTransactions() override {}
virtual eth::BlockChain const& bc() const override { return m_bc; }
virtual eth::State asOf(eth::BlockNumber _h) const override;
virtual eth::State asOf(h256 _h) const override;
using ClientBase::asOf;
virtual eth::State asOf(h256 const& _h) const override;
virtual eth::State preMine() const override { ReadGuard l(x_stateDB); return m_state; }
virtual eth::State postMine() const override { ReadGuard l(x_stateDB); return m_state; }
virtual void prepareForTransaction() override {}

2
libtestutils/StateLoader.h

@ -36,7 +36,7 @@ class StateLoader
{
public:
StateLoader(Json::Value const& _json);
eth::State const& state() { return m_state; }
eth::State const& state() const { return m_state; }
private:
eth::State m_state;

8
libtestutils/ShortLivingDirectory.cpp → libtestutils/TransientDirectory.cpp

@ -14,20 +14,20 @@
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 ShortLivingDirectory.cpp
/** @file TransientDirectory.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
#include <boost/filesystem.hpp>
#include <libdevcore/Exceptions.h>
#include "ShortLivingDirectory.h"
#include "TransientDirectory.h"
using namespace std;
using namespace dev;
using namespace dev::test;
ShortLivingDirectory::ShortLivingDirectory(std::string const& _path) : m_path(_path)
TransientDirectory::TransientDirectory(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))
@ -36,7 +36,7 @@ ShortLivingDirectory::ShortLivingDirectory(std::string const& _path) : m_path(_p
boost::filesystem::create_directories(m_path);
}
ShortLivingDirectory::~ShortLivingDirectory()
TransientDirectory::~TransientDirectory()
{
boost::filesystem::remove_all(m_path);
}

10
libtestutils/ShortLivingDirectory.h → libtestutils/TransientDirectory.h

@ -14,7 +14,7 @@
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 ShortLivingDirectory.h
/** @file TransientDirectory.h
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
@ -34,13 +34,13 @@ namespace test
* 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
class TransientDirectory
{
public:
ShortLivingDirectory(std::string const& _path = getRandomPath());
~ShortLivingDirectory();
TransientDirectory(std::string const& _path = getRandomPath());
~TransientDirectory();
std::string const& path() { return m_path; }
std::string const& path() const { return m_path; }
private:
std::string m_path;
Loading…
Cancel
Save