Browse Source

Merge branch 'develop' into reqpeer

Conflicts:
	libp2p/Network.h
cl-refactor
subtly 10 years ago
parent
commit
9f575d3465
  1. 1
      libdevcore/FixedHash.h
  2. 2
      libp2p/Network.h
  3. 2
      libtestutils/Common.cpp
  4. 8
      libtestutils/TransientDirectory.cpp
  5. 3
      libtestutils/TransientDirectory.h
  6. 36
      test/blockchain.cpp

1
libdevcore/FixedHash.h

@ -141,6 +141,7 @@ public:
return ret; return ret;
} }
/// @returns a random valued object.
static FixedHash random() { return random(s_fixedHashEngine); } static FixedHash random() { return random(s_fixedHashEngine); }
/// A generic std::hash compatible function object. /// A generic std::hash compatible function object.

2
libp2p/Network.h

@ -68,7 +68,7 @@ public:
static int tcp4Listen(bi::tcp::acceptor& _acceptor, NetworkPreferences const& _netPrefs); static int tcp4Listen(bi::tcp::acceptor& _acceptor, NetworkPreferences const& _netPrefs);
/// Return public endpoint of upnp interface. If successful o_upnpifaddr will be a private interface address and endpoint will contain public address and port. /// Return public endpoint of upnp interface. If successful o_upnpifaddr will be a private interface address and endpoint will contain public address and port.
static bi::tcp::endpoint traverseNAT(std::set<bi::address> const& _ifAddresses, unsigned short _listenPort, bi::address& o_upnpifaddr); static bi::tcp::endpoint traverseNAT(std::set<bi::address> const& _ifAddresses, unsigned short _listenPort, bi::address& o_upnpInterfaceAddr);
/// Resolve "host:port" string as TCP endpoint. Returns unspecified endpoint on failure. /// Resolve "host:port" string as TCP endpoint. Returns unspecified endpoint on failure.
static bi::tcp::endpoint resolveHost(std::string const& _host); static bi::tcp::endpoint resolveHost(std::string const& _host);

2
libtestutils/Common.cpp

@ -74,7 +74,7 @@ std::string dev::test::toTestFilePath(std::string const& _filename)
std::string dev::test::getRandomPath() std::string dev::test::getRandomPath()
{ {
std::stringstream stream; std::stringstream stream;
stream << getDataDir() << "/EthereumTests/" << randomNumber(); stream << getDataDir("EthereumTests") << "/" << randomNumber();
return stream.str(); return stream.str();
} }

8
libtestutils/TransientDirectory.cpp

@ -22,12 +22,16 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include "TransientDirectory.h" #include "TransientDirectory.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::test; using namespace dev::test;
TransientDirectory::TransientDirectory(std::string const& _path) : m_path(_path) TransientDirectory::TransientDirectory():
TransientDirectory((boost::filesystem::temp_directory_path() / "eth_transient" / toString(FixedHash<4>::random())).string())
{}
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. // we never ever want to delete a directory (including all its contents) that we did not create ourselves.
if (boost::filesystem::exists(m_path)) if (boost::filesystem::exists(m_path))

3
libtestutils/TransientDirectory.h

@ -37,7 +37,8 @@ namespace test
class TransientDirectory class TransientDirectory
{ {
public: public:
TransientDirectory(std::string const& _path = getRandomPath()); TransientDirectory();
TransientDirectory(std::string const& _path);
~TransientDirectory(); ~TransientDirectory();
std::string const& path() const { return m_path; } std::string const& path() const { return m_path; }

36
test/blockchain.cpp

@ -20,7 +20,9 @@
* block test functions. * block test functions.
*/ */
#include <boost/filesystem.hpp>
#include <libdevcrypto/FileSystem.h> #include <libdevcrypto/FileSystem.h>
#include <libtestutils/TransientDirectory.h>
#include <libethereum/CanonBlockChain.h> #include <libethereum/CanonBlockChain.h>
#include "TestHelper.h" #include "TestHelper.h"
@ -35,8 +37,8 @@ bytes createBlockRLPFromFields(mObject& _tObj);
void overwriteBlockHeader(BlockInfo& _current_BlockHeader, mObject& _blObj); void overwriteBlockHeader(BlockInfo& _current_BlockHeader, mObject& _blObj);
BlockInfo constructBlock(mObject& _o); BlockInfo constructBlock(mObject& _o);
void updatePoW(BlockInfo& _bi); void updatePoW(BlockInfo& _bi);
void writeBlockHeaderToJson(mObject& _o, const BlockInfo& _bi); void writeBlockHeaderToJson(mObject& _o, BlockInfo const& _bi);
RLPStream createFullBlockFromHeader(const BlockInfo& _bi, const bytes& _txs = RLPEmptyList, const bytes& _uncles = RLPEmptyList); RLPStream createFullBlockFromHeader(BlockInfo const& _bi, bytes const& _txs = RLPEmptyList, bytes const& _uncles = RLPEmptyList);
void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
{ {
@ -75,7 +77,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
o["genesisRLP"] = "0x" + toHex(rlpGenesisBlock.out()); o["genesisRLP"] = "0x" + toHex(rlpGenesisBlock.out());
// construct blockchain // construct blockchain
BlockChain bc(rlpGenesisBlock.out(), string(), true); TransientDirectory td;
BlockChain bc(rlpGenesisBlock.out(), td.path(), true);
if (_fillin) if (_fillin)
{ {
@ -241,6 +244,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
if (sha3(RLP(state.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) if (sha3(RLP(state.blockData())[2].data()) != sha3(RLP(block2.out())[2].data()))
cnote << "uncle list mismatch\n" << RLP(state.blockData())[2].data() << "\n" << RLP(block2.out())[2].data(); cnote << "uncle list mismatch\n" << RLP(state.blockData())[2].data() << "\n" << RLP(block2.out())[2].data();
try try
{ {
state.sync(bc); state.sync(bc);
@ -292,7 +296,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
BOOST_CHECK(blObj.count("uncleHeaders") == 0); BOOST_CHECK(blObj.count("uncleHeaders") == 0);
continue; continue;
} }
catch(...) catch (...)
{ {
cnote << "state sync or block import did throw an exception\n"; cnote << "state sync or block import did throw an exception\n";
BOOST_CHECK(blObj.count("blockHeader") == 0); BOOST_CHECK(blObj.count("blockHeader") == 0);
@ -388,7 +392,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "transactions from rlp and transaction from field do not match"); BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "transactions from rlp and transaction from field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].rlp() == txsFromRlp[i].rlp(), "transactions rlp do not match"); BOOST_CHECK_MESSAGE(txsFromField[i].rlp() == txsFromRlp[i].rlp(), "transactions rlp do not match");
} }
// check uncle list // check uncle list
@ -488,12 +491,12 @@ bytes createBlockRLPFromFields(mObject& _tObj)
return rlpStream.out(); return rlpStream.out();
} }
void overwriteBlockHeader(BlockInfo& _current_BlockHeader, mObject& _blObj) void overwriteBlockHeader(BlockInfo& _currentBlockHeader, mObject& _blObj)
{ {
if (_blObj["blockHeader"].get_obj().size() != 14) if (_blObj["blockHeader"].get_obj().size() != 14)
{ {
BlockInfo tmp = _current_BlockHeader; BlockInfo tmp = _currentBlockHeader;
if (_blObj["blockHeader"].get_obj().count("parentHash")) if (_blObj["blockHeader"].get_obj().count("parentHash"))
tmp.parentHash = h256(_blObj["blockHeader"].get_obj()["parentHash"].get_str()); tmp.parentHash = h256(_blObj["blockHeader"].get_obj()["parentHash"].get_str());
@ -539,16 +542,16 @@ void overwriteBlockHeader(BlockInfo& _current_BlockHeader, mObject& _blObj)
// find new valid nonce // find new valid nonce
if (tmp != _current_BlockHeader) if (tmp != _currentBlockHeader)
{ {
_current_BlockHeader = tmp; _currentBlockHeader = tmp;
ProofOfWork pow; ProofOfWork pow;
std::pair<MineInfo, Ethash::Proof> ret; std::pair<MineInfo, Ethash::Proof> ret;
while (!ProofOfWork::verify(_current_BlockHeader)) while (!ProofOfWork::verify(_currentBlockHeader))
{ {
ret = pow.mine(_current_BlockHeader, 1000, true, true); ret = pow.mine(_currentBlockHeader, 1000, true, true);
Ethash::assignResult(ret.second, _current_BlockHeader); Ethash::assignResult(ret.second, _currentBlockHeader);
} }
} }
} }
@ -557,13 +560,12 @@ void overwriteBlockHeader(BlockInfo& _current_BlockHeader, mObject& _blObj)
// take the blockheader as is // take the blockheader as is
const bytes c_blockRLP = createBlockRLPFromFields(_blObj["blockHeader"].get_obj()); const bytes c_blockRLP = createBlockRLPFromFields(_blObj["blockHeader"].get_obj());
const RLP c_bRLP(c_blockRLP); const RLP c_bRLP(c_blockRLP);
_current_BlockHeader.populateFromHeader(c_bRLP, IgnoreNonce); _currentBlockHeader.populateFromHeader(c_bRLP, IgnoreNonce);
} }
} }
BlockInfo constructBlock(mObject& _o) BlockInfo constructBlock(mObject& _o)
{ {
BlockInfo ret; BlockInfo ret;
try try
{ {
@ -600,7 +602,7 @@ void updatePoW(BlockInfo& _bi)
_bi.hash = _bi.headerHash(WithNonce); _bi.hash = _bi.headerHash(WithNonce);
} }
void writeBlockHeaderToJson(mObject& _o, const BlockInfo& _bi) void writeBlockHeaderToJson(mObject& _o, BlockInfo const& _bi)
{ {
_o["parentHash"] = toString(_bi.parentHash); _o["parentHash"] = toString(_bi.parentHash);
_o["uncleHash"] = toString(_bi.sha3Uncles); _o["uncleHash"] = toString(_bi.sha3Uncles);
@ -620,7 +622,7 @@ void writeBlockHeaderToJson(mObject& _o, const BlockInfo& _bi)
_o["hash"] = toString(_bi.hash); _o["hash"] = toString(_bi.hash);
} }
RLPStream createFullBlockFromHeader(const BlockInfo& _bi,const bytes& _txs, const bytes& _uncles ) RLPStream createFullBlockFromHeader(BlockInfo const& _bi, bytes const& _txs, bytes const& _uncles)
{ {
RLPStream rlpStream; RLPStream rlpStream;
_bi.streamRLP(rlpStream, WithNonce); _bi.streamRLP(rlpStream, WithNonce);
@ -632,8 +634,8 @@ RLPStream createFullBlockFromHeader(const BlockInfo& _bi,const bytes& _txs, cons
return ret; return ret;
} }
} }// Namespace Close
} }// Namespace Close
BOOST_AUTO_TEST_SUITE(BlockChainTests) BOOST_AUTO_TEST_SUITE(BlockChainTests)

Loading…
Cancel
Save