Merge remote-tracking branch 'upstream/develop' into evmjit

This commit is contained in:
Paweł Bylica 2015-03-05 16:49:21 +01:00
commit 51e376efb8
17 changed files with 250 additions and 193 deletions

View File

@ -23,7 +23,9 @@
#include <thread>
#include <chrono>
#include <boost/filesystem/path.hpp>
#include <libethereum/Client.h>
#include <liblll/Compiler.h>
#include <libevm/VMFactory.h>
@ -170,7 +172,7 @@ void ImportTest::importTransaction(json_spirit::mObject& _o)
}
}
void ImportTest::exportTest(bytes _output, State& _statePost)
void ImportTest::exportTest(bytes const& _output, State const& _statePost)
{
// export output
m_TestObject["out"] = "0x" + toHex(_output);

View File

@ -22,7 +22,9 @@
#pragma once
#include <functional>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h"
#include <libethereum/State.h>
#include <libevm/ExtVMFace.h>
@ -52,7 +54,7 @@ public:
void importEnv(json_spirit::mObject& _o);
void importState(json_spirit::mObject& _o, eth::State& _state);
void importTransaction(json_spirit::mObject& _o);
void exportTest(bytes _output, eth::State& _statePost);
void exportTest(bytes const& _output, eth::State const& _statePost);
eth::State m_statePre;
eth::State m_statePost;

144
block.cpp
View File

@ -81,6 +81,76 @@ bytes createBlockRLPFromFields(mObject& _tObj)
return rlpStream.out();
}
void overwriteBlockHeader(mObject& _o, BlockInfo _current_BlockHeader)
{
if (_o.count("blockHeader"))
{
if (_o["blockHeader"].get_obj().size() != 14)
{
BlockInfo tmp = _current_BlockHeader;
if (_o["blockHeader"].get_obj().count("parentHash"))
tmp.parentHash = h256(_o["blockHeader"].get_obj()["parentHash"].get_str());
if (_o["blockHeader"].get_obj().count("uncleHash"))
tmp.sha3Uncles = h256(_o["blockHeader"].get_obj()["uncleHash"].get_str());
if (_o["blockHeader"].get_obj().count("coinbase"))
tmp.coinbaseAddress = Address(_o["blockHeader"].get_obj()["coinbase"].get_str());
if (_o["blockHeader"].get_obj().count("stateRoot"))
tmp.stateRoot = h256(_o["blockHeader"].get_obj()["stateRoot"].get_str());
if (_o["blockHeader"].get_obj().count("transactionsTrie"))
tmp.transactionsRoot = h256(_o["blockHeader"].get_obj()["transactionsTrie"].get_str());
if (_o["blockHeader"].get_obj().count("receiptTrie"))
tmp.receiptsRoot = h256(_o["blockHeader"].get_obj()["receiptTrie"].get_str());
if (_o["blockHeader"].get_obj().count("bloom"))
tmp.logBloom = LogBloom(_o["blockHeader"].get_obj()["bloom"].get_str());
if (_o["blockHeader"].get_obj().count("difficulty"))
tmp.difficulty = toInt(_o["blockHeader"].get_obj()["difficulty"]);
if (_o["blockHeader"].get_obj().count("number"))
tmp.number = toInt(_o["blockHeader"].get_obj()["number"]);
if (_o["blockHeader"].get_obj().count("gasLimit"))
tmp.gasLimit = toInt(_o["blockHeader"].get_obj()["gasLimit"]);
if (_o["blockHeader"].get_obj().count("gasUsed"))
tmp.gasUsed = toInt(_o["blockHeader"].get_obj()["gasUsed"]);
if (_o["blockHeader"].get_obj().count("timestamp"))
tmp.timestamp = toInt(_o["blockHeader"].get_obj()["timestamp"]);
if (_o["blockHeader"].get_obj().count("extraData"))
tmp.extraData = importByteArray(_o["blockHeader"].get_obj()["extraData"].get_str());
// find new valid nonce
if (tmp != _current_BlockHeader)
{
_current_BlockHeader = tmp;
cout << "new header!\n";
ProofOfWork pow;
MineInfo ret;
while (!ProofOfWork::verify(_current_BlockHeader.headerHash(WithoutNonce), _current_BlockHeader.nonce, _current_BlockHeader.difficulty))
tie(ret, _current_BlockHeader.nonce) = pow.mine(_current_BlockHeader.headerHash(WithoutNonce), _current_BlockHeader.difficulty, 10000, true, true);
}
}
else
{
// take the blockheader as is
const bytes c_blockRLP = createBlockRLPFromFields(_o["blockHeader"].get_obj());
const RLP c_bRLP(c_blockRLP);
_current_BlockHeader.populateFromHeader(c_bRLP, false);
}
}
}
void doBlockTests(json_spirit::mValue& _v, bool _fillin)
{
for (auto& i: _v.get_obj())
@ -214,76 +284,9 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
BlockInfo current_BlockHeader = state.info();
// overwrite blockheader with (possible wrong) data from "blockheader" in filler;
if (o.count("blockHeader"))
{
if (o["blockHeader"].get_obj().size() != 14)
{
BlockInfo tmp = current_BlockHeader;
if (o["blockHeader"].get_obj().count("parentHash"))
tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str());
if (o["blockHeader"].get_obj().count("uncleHash"))
tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str());
if (o["blockHeader"].get_obj().count("coinbase"))
tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str());
if (o["blockHeader"].get_obj().count("stateRoot"))
tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str());
if (o["blockHeader"].get_obj().count("transactionsTrie"))
tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str());
if (o["blockHeader"].get_obj().count("receiptTrie"))
tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str());
if (o["blockHeader"].get_obj().count("bloom"))
tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str());
if (o["blockHeader"].get_obj().count("difficulty"))
tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]);
if (o["blockHeader"].get_obj().count("number"))
tmp.number = toInt(o["blockHeader"].get_obj()["number"]);
if (o["blockHeader"].get_obj().count("gasLimit"))
tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]);
if (o["blockHeader"].get_obj().count("gasUsed"))
tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]);
if (o["blockHeader"].get_obj().count("timestamp"))
tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]);
if (o["blockHeader"].get_obj().count("extraData"))
tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str());
// find new valid nonce
if (tmp != current_BlockHeader)
{
current_BlockHeader = tmp;
cout << "new header!\n";
ProofOfWork pow;
MineInfo ret;
while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty))
tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true);
}
}
else
{
// take the blockheader as is
const bytes c_blockRLP = createBlockRLPFromFields(o["blockHeader"].get_obj());
const RLP c_bRLP(c_blockRLP);
current_BlockHeader.populateFromHeader(c_bRLP, false);
}
}
overwriteBlockHeader(o, current_BlockHeader);
// write block header
mObject oBlockHeader;
oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash);
oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles);
@ -423,7 +426,6 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!");
//Check transaction list
Transactions txsFromField;
for (auto const& txObj: o["transactions"].get_array())
@ -511,9 +513,9 @@ BOOST_AUTO_TEST_CASE(blForkBlocks)
dev::test::executeTests("blForkBlocks", "/BlockTests", dev::test::doBlockTests);
}
BOOST_AUTO_TEST_CASE(userDefinedFileBl)
BOOST_AUTO_TEST_CASE(userDefinedFile)
{
dev::test::userDefinedTest("--bltest", dev::test::doBlockTests);
dev::test::userDefinedTest("--singletest", dev::test::doBlockTests);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -23,8 +23,10 @@
#include <string>
#include <iostream>
#include <chrono>
#include <boost/random.hpp>
#include <boost/filesystem/path.hpp>
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <json_spirit/json_spirit.h>
#include <json_spirit/json_spirit_reader_template.h>

View File

@ -22,6 +22,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <libethereum/Client.h>
#include <libethereum/CanonBlockChain.h>
#include <libethereum/EthereumHost.h>

View File

@ -22,10 +22,12 @@
#include <fstream>
#include <random>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h"
#include <libdevcore/CommonIO.h>
#include <libethereum/CanonBlockChain.h>
#include <boost/test/unit_test.hpp>
#include "TestHelper.h"
using namespace std;

View File

@ -21,11 +21,13 @@
*/
#include <fstream>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h"
#include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h>
#include <libdevcrypto/TrieCommon.h>
#include <boost/test/unit_test.hpp>
#include "TestHelper.h"
using namespace std;

View File

@ -20,6 +20,7 @@
*/
#include <boost/test/unit_test.hpp>
#include <libdevcore/Worker.h>
#include <libdevcrypto/Common.h>
#include <libp2p/UDP.h>

View File

@ -22,11 +22,13 @@
#include <fstream>
#include <sstream>
#include <boost/test/unit_test.hpp>
#include <libdevcore/Log.h>
#include <libdevcore/RLP.h>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <boost/test/unit_test.hpp>
#include <algorithm>
#include "JsonSpiritHeaders.h"
#include "TestHelper.h"

View File

@ -22,6 +22,7 @@
#include <boost/filesystem/operations.hpp>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h"
#include <libdevcore/CommonIO.h>
#include <libethereum/CanonBlockChain.h>
@ -241,7 +242,7 @@ BOOST_AUTO_TEST_CASE(stCreateTest)
BOOST_AUTO_TEST_CASE(userDefinedFileState)
{
dev::test::userDefinedTest("--statetest", dev::test::doStateTests);
dev::test::userDefinedTest("--singletest", dev::test::doStateTests);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -104,7 +104,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
BOOST_AUTO_TEST_SUITE(TransactionTests)
BOOST_AUTO_TEST_CASE(TransactionTest)
BOOST_AUTO_TEST_CASE(ttTransactionTest)
{
dev::test::executeTests("ttTransactionTest", "/TransactionTests", dev::test::doTransactionTests);
}
@ -167,9 +167,9 @@ BOOST_AUTO_TEST_CASE(ttCreateTest)
}
}
BOOST_AUTO_TEST_CASE(userDefinedFileTT)
BOOST_AUTO_TEST_CASE(userDefinedFile)
{
dev::test::userDefinedTest("--ttTest", dev::test::doTransactionTests);
dev::test::userDefinedTest("--singletest", dev::test::doTransactionTests);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -22,12 +22,14 @@
#include <fstream>
#include <random>
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h"
#include <libdevcore/CommonIO.h>
#include <libdevcrypto/TrieDB.h>
#include "TrieHash.h"
#include "MemTrie.h"
#include <boost/test/unit_test.hpp>
#include "TestHelper.h"
using namespace std;

View File

@ -59,6 +59,21 @@
}
},
"WrongVRSTestVOverflow" : {
"transaction" :
{
"data" : "",
"gasLimit" : "2000",
"gasPrice" : "1",
"nonce" : "0",
"to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10",
"v" : "310",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"WrongVRSTestIncorrectSize" : {
"transaction" :
{
@ -91,6 +106,22 @@
}
},
"DataTest" : {
"transaction" :
{
"data" : "0x0358ac39584bc98a7c979f984b03",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "10",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "secretkey 45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithTooManyRLPElements" : {
"transaction" :
{

View File

@ -22,6 +22,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <libethereum/Client.h>
#include <libethereum/CanonBlockChain.h>
#include <libethereum/EthereumHost.h>

6
vm.cpp
View File

@ -21,7 +21,9 @@
*/
#include <chrono>
#include <boost/filesystem.hpp>
#include <libethereum/Executive.h>
#include <libevm/VMFactory.h>
#include "vm.h"
@ -592,9 +594,9 @@ BOOST_AUTO_TEST_CASE(vmRandom)
}
}
BOOST_AUTO_TEST_CASE(userDefinedFileVM)
BOOST_AUTO_TEST_CASE(userDefinedFile)
{
dev::test::userDefinedTest("--vmtest", dev::test::doVMTests);
dev::test::userDefinedTest("--singletest", dev::test::doVMTests);
}
BOOST_AUTO_TEST_SUITE_END()

2
vm.h
View File

@ -25,7 +25,9 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
#include <fstream>
#include <cstdint>
#include <boost/test/unit_test.hpp>
#include <json_spirit/json_spirit.h>
#include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h>

View File

@ -19,7 +19,9 @@
* @date 2014
*/
#include <functional>
#include <boost/test/unit_test.hpp>
#include <libp2p/Host.h>
#include <libwhisper/WhisperPeer.h>
#include <libwhisper/WhisperHost.h>