Browse Source

Remove NOBOOST, move createRandomTest to testeth --createRandomTest

cl-refactor
Dimitry 10 years ago
parent
commit
9512a38832
  1. 7
      CMakeLists.txt
  2. 66
      test/TestHelper.cpp
  3. 35
      test/TestHelper.h
  4. 40
      test/boostTest.cpp
  5. 16
      test/fuzzTesting/CMakeLists.txt
  6. 228
      test/fuzzTesting/checkRandomStateTest.cpp
  7. 298
      test/fuzzTesting/checkRandomVMTest.cpp
  8. 258
      test/fuzzTesting/createRandomStateTest.cpp
  9. 10
      test/fuzzTesting/createRandomTest.cpp
  10. 206
      test/fuzzTesting/createRandomVMTest.cpp
  11. 59
      test/libdevcore/rlp.cpp
  12. 129
      test/libethereum/blockchain.cpp
  13. 12
      test/libethereum/state.cpp
  14. 38
      test/libethereum/transactionTests.cpp
  15. 30
      test/libevm/vm.cpp

7
CMakeLists.txt

@ -57,7 +57,6 @@ set(D_VMTRACE OFF)
set(D_PARANOID OFF)
set(D_PROFILING OFF)
set(D_ROCKSDB OFF)
set(D_NOBOOST OFF)
set(D_OLYMPIC OFF)
set(D_MINER ON)
set(D_ETHKEY ON)
@ -193,10 +192,6 @@ function(configureProject)
add_definitions(-DETH_CURL)
endif()
if (NOBOOST)
add_definitions(-DNOBOOST)
endif()
if (OLYMPIC)
add_definitions(-DETH_OLYMPIC)
else()
@ -307,7 +302,6 @@ eth_format_option(SOLIDITY)
eth_format_option(ROCKSDB)
eth_format_option(GUI)
eth_format_option(TESTS)
eth_format_option(NOBOOST)
eth_format_option(ROCKSDB)
eth_format_option(TOOLS)
eth_format_option(ETHKEY)
@ -349,7 +343,6 @@ message("-- Hardware identification support ${CPUID_FO
message("-- HTTP Request support ${CURL_FOUND}")
message("-- VMTRACE VM execution tracing ${VMTRACE}")
message("-- PROFILING Profiling support ${PROFILING}")
message("-- NOBOOST No BOOST macros in test functions ${NOBOOST}")
message("-- FATDB Full database exploring ${FATDB}")
message("-- JSONRPC JSON-RPC support ${JSONRPC}")
message("-- USENPM Javascript source building ${USENPM}")

66
test/TestHelper.cpp

@ -259,17 +259,17 @@ int ImportTest::compareStates(State const& _stateExpect, State const& _statePost
{ \
if (_throw == WhenError::Throw) \
{ \
TBOOST_CHECK_MESSAGE(a, b); \
BOOST_CHECK_MESSAGE(a, b); \
if (!a) \
return 1; \
} \
else \
{TBOOST_WARN_MESSAGE(a,b);} \
BOOST_WARN_MESSAGE(a,b); \
}
for (auto const& a: _stateExpect.addresses())
{
CHECK(_statePost.addressInUse(a.first), "Check State: " << a.first << " missing expected address!");
CHECK(_statePost.addressInUse(a.first), "Compare States: " << a.first << " missing expected address!");
if (_statePost.addressInUse(a.first))
{
AccountMask addressOptions(true);
@ -281,7 +281,7 @@ int ImportTest::compareStates(State const& _stateExpect, State const& _statePost
}
catch(std::out_of_range const&)
{
TBOOST_ERROR("expectedStateOptions map does not match expectedState in checkExpectedState!");
BOOST_ERROR("expectedStateOptions map does not match expectedState in checkExpectedState!");
break;
}
}
@ -329,12 +329,12 @@ int ImportTest::exportTest(bytes const& _output)
if (Options::get().checkState)
{
bool statement = (m_testObject["out"].get_str() == m_testObject["expectOut"].get_str());
TBOOST_CHECK_MESSAGE(statement, warning);
BOOST_CHECK_MESSAGE(statement, warning);
if (!statement)
err = 1;
}
else
TBOOST_WARN_MESSAGE((m_testObject["out"].get_str() == m_testObject["expectOut"].get_str()), warning);
BOOST_WARN_MESSAGE(m_testObject["out"].get_str() == m_testObject["expectOut"].get_str(), warning);
m_testObject.erase(m_testObject.find("expectOut"));
}
@ -502,17 +502,17 @@ void checkOutput(bytes const& _output, json_spirit::mObject& _o)
int j = 0;
if (_o["out"].get_str().find("#") == 0)
{TBOOST_CHECK(((u256)_output.size() == toInt(_o["out"].get_str().substr(1))));}
BOOST_CHECK((u256)_output.size() == toInt(_o["out"].get_str().substr(1)));
else if (_o["out"].type() == json_spirit::array_type)
for (auto const& d: _o["out"].get_array())
{
TBOOST_CHECK_MESSAGE((_output[j] == toInt(d)), "Output byte [" << j << "] different!");
BOOST_CHECK_MESSAGE(_output[j] == toInt(d), "Output byte [" << j << "] different!");
++j;
}
else if (_o["out"].get_str().find("0x") == 0)
{TBOOST_CHECK((_output == fromHex(_o["out"].get_str().substr(2))));}
BOOST_CHECK(_output == fromHex(_o["out"].get_str().substr(2)));
else
TBOOST_CHECK((_output == fromHex(_o["out"].get_str())));
BOOST_CHECK(_output == fromHex(_o["out"].get_str()));
}
void checkStorage(map<u256, u256> _expectedStore, map<u256, u256> _resultStore, Address _expectedAddr)
@ -523,44 +523,44 @@ void checkStorage(map<u256, u256> _expectedStore, map<u256, u256> _resultStore,
auto& expectedStoreKey = expectedStorePair.first;
auto resultStoreIt = _resultStore.find(expectedStoreKey);
if (resultStoreIt == _resultStore.end())
{TBOOST_ERROR(_expectedAddr << ": missing store key " << expectedStoreKey);}
BOOST_ERROR(_expectedAddr << ": missing store key " << expectedStoreKey);
else
{
auto& expectedStoreValue = expectedStorePair.second;
auto& resultStoreValue = resultStoreIt->second;
TBOOST_CHECK_MESSAGE((expectedStoreValue == resultStoreValue), _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue);
BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue);
}
}
TBOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size());
BOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size());
for (auto&& resultStorePair: _resultStore)
{
if (!_expectedStore.count(resultStorePair.first))
TBOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first);
BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first);
}
}
void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs)
{
TBOOST_REQUIRE_EQUAL(_resultLogs.size(), _expectedLogs.size());
BOOST_REQUIRE_EQUAL(_resultLogs.size(), _expectedLogs.size());
for (size_t i = 0; i < _resultLogs.size(); ++i)
{
TBOOST_CHECK_EQUAL(_resultLogs[i].address, _expectedLogs[i].address);
TBOOST_CHECK_EQUAL(_resultLogs[i].topics, _expectedLogs[i].topics);
TBOOST_CHECK((_resultLogs[i].data == _expectedLogs[i].data));
BOOST_CHECK_EQUAL(_resultLogs[i].address, _expectedLogs[i].address);
BOOST_CHECK_EQUAL(_resultLogs[i].topics, _expectedLogs[i].topics);
BOOST_CHECK(_resultLogs[i].data == _expectedLogs[i].data);
}
}
void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates)
{
TBOOST_REQUIRE_EQUAL(_resultCallCreates.size(), _expectedCallCreates.size());
BOOST_REQUIRE_EQUAL(_resultCallCreates.size(), _expectedCallCreates.size());
for (size_t i = 0; i < _resultCallCreates.size(); ++i)
{
TBOOST_CHECK((_resultCallCreates[i].data() == _expectedCallCreates[i].data()));
TBOOST_CHECK((_resultCallCreates[i].receiveAddress() == _expectedCallCreates[i].receiveAddress()));
TBOOST_CHECK((_resultCallCreates[i].gas() == _expectedCallCreates[i].gas()));
TBOOST_CHECK((_resultCallCreates[i].value() == _expectedCallCreates[i].value()));
BOOST_CHECK(_resultCallCreates[i].data() == _expectedCallCreates[i].data());
BOOST_CHECK(_resultCallCreates[i].receiveAddress() == _expectedCallCreates[i].receiveAddress());
BOOST_CHECK(_resultCallCreates[i].gas() == _expectedCallCreates[i].gas());
BOOST_CHECK(_resultCallCreates[i].value() == _expectedCallCreates[i].value());
}
}
@ -586,7 +586,7 @@ void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests)
cnote << "Testing user defined test: " << filename;
json_spirit::mValue v;
string s = contentsString(filename);
TBOOST_REQUIRE_MESSAGE((s.length() > 0), "Contents of " + filename + " is empty. ");
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
json_spirit::read_string(s, v);
json_spirit::mObject oSingleTest;
@ -604,11 +604,11 @@ void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests)
}
catch (Exception const& _e)
{
TBOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e));
BOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e));
}
catch (std::exception const& _e)
{
TBOOST_ERROR("Failed Test with Exception: " << _e.what());
BOOST_ERROR("Failed Test with Exception: " << _e.what());
}
}
@ -628,18 +628,18 @@ void executeTests(const string& _name, const string& _testPathAppendix, const bo
json_spirit::mValue v;
boost::filesystem::path p(__FILE__);
string s = asString(dev::contents(_pathToFiller.string() + "/" + _name + "Filler.json"));
TBOOST_REQUIRE_MESSAGE((s.length() > 0), "Contents of " + _pathToFiller.string() + "/" + _name + "Filler.json is empty.");
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + _pathToFiller.string() + "/" + _name + "Filler.json is empty.");
json_spirit::read_string(s, v);
doTests(v, true);
writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true)));
}
catch (Exception const& _e)
{
TBOOST_ERROR("Failed filling test with Exception: " << diagnostic_information(_e));
BOOST_ERROR("Failed filling test with Exception: " << diagnostic_information(_e));
}
catch (std::exception const& _e)
{
TBOOST_ERROR("Failed filling test with Exception: " << _e.what());
BOOST_ERROR("Failed filling test with Exception: " << _e.what());
}
}
@ -648,18 +648,18 @@ void executeTests(const string& _name, const string& _testPathAppendix, const bo
cnote << "TEST " << _name << ":";
json_spirit::mValue v;
string s = asString(dev::contents(testPath + "/" + _name + ".json"));
TBOOST_REQUIRE_MESSAGE((s.length() > 0), "Contents of " + testPath + "/" + _name + ".json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testPath + "/" + _name + ".json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
json_spirit::read_string(s, v);
Listener::notifySuiteStarted(_name);
doTests(v, false);
}
catch (Exception const& _e)
{
TBOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
}
catch (std::exception const& _e)
{
TBOOST_ERROR("Failed test with Exception: " << _e.what());
BOOST_ERROR("Failed test with Exception: " << _e.what());
}
}
@ -802,6 +802,8 @@ Options::Options()
else
logVerbosity = Verbosity::Full;
}
else if (arg == "--createRandomTest")
createRandomTest = true;
}
//Default option

35
test/TestHelper.h

@ -31,26 +31,6 @@
#include <libevm/ExtVMFace.h>
#include <libtestutils/Common.h>
#ifdef NOBOOST
#define TBOOST_REQUIRE(arg) if(arg == false) throw dev::Exception();
#define TBOOST_REQUIRE_EQUAL(arg1, arg2) if(arg1 != arg2) throw dev::Exception();
#define TBOOST_CHECK_EQUAL(arg1, arg2) if(arg1 != arg2) throw dev::Exception();
#define TBOOST_CHECK(arg) if(arg == false) throw dev::Exception();
#define TBOOST_REQUIRE_MESSAGE(arg1, arg2) if(arg1 == false) throw dev::Exception();
#define TBOOST_CHECK_MESSAGE(arg1, arg2) if(arg1 == false) throw dev::Exception();
#define TBOOST_WARN_MESSAGE(arg1, arg2) throw dev::Exception();
#define TBOOST_ERROR(arg) throw dev::Exception();
#else
#define TBOOST_REQUIRE(arg) BOOST_REQUIRE(arg)
#define TBOOST_REQUIRE_EQUAL(arg1, arg2) BOOST_REQUIRE_EQUAL(arg1, arg2)
#define TBOOST_CHECK(arg) BOOST_CHECK(arg)
#define TBOOST_CHECK_EQUAL(arg1, arg2) BOOST_CHECK_EQUAL(arg1, arg2)
#define TBOOST_CHECK_MESSAGE(arg1, arg2) BOOST_CHECK_MESSAGE(arg1, arg2)
#define TBOOST_REQUIRE_MESSAGE(arg1, arg2) BOOST_REQUIRE_MESSAGE(arg1, arg2)
#define TBOOST_WARN_MESSAGE(arg1, arg2) BOOST_WARN_MESSAGE(arg1, arg2)
#define TBOOST_ERROR(arg) BOOST_ERROR(arg)
#endif
namespace dev
{
namespace eth
@ -198,25 +178,13 @@ json_spirit::mObject fillJsonWithState(eth::State _state);
json_spirit::mObject fillJsonWithTransaction(eth::Transaction _txn);
//Fill Test Functions
int createRandomTest(int argc, char *argv[]);
void doTransactionTests(json_spirit::mValue& _v, bool _fillin);
void doStateTests(json_spirit::mValue& v, bool _fillin);
void doVMTests(json_spirit::mValue& v, bool _fillin);
void doBlockchainTests(json_spirit::mValue& _v, bool _fillin);
void doRlpTests(json_spirit::mValue& v, bool _fillin);
/*template<typename mapType>
void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)
{
for (auto& resultPair : _resultAddrs)
{
auto& resultAddr = resultPair.first;
auto expectedAddrIt = _expectedAddrs.find(resultAddr);
if (expectedAddrIt == _expectedAddrs.end())
TBOOST_ERROR("Missing result address " << resultAddr);
}
TBOOST_CHECK((_expectedAddrs == _resultAddrs));
}*/
enum class Verbosity
{
Full,
@ -233,6 +201,7 @@ public:
std::string statsOutFile; ///< Stats output file. "out" for standard output
bool checkState = false;///< Throw error when checking test states
bool fulloutput = false;///< Replace large output to just it's length
bool createRandomTest = false; ///< Generate random test
Verbosity logVerbosity = Verbosity::NiceReport;
/// Test selection

40
test/boostTest.cpp

@ -28,24 +28,54 @@
#define BOOST_TEST_NO_MAIN
#include <boost/test/included/unit_test.hpp>
#pragma GCC diagnostic pop
#include <test/TestHelper.h>
using namespace boost::unit_test;
char** originalArgv;
int originalArgc;
static std::ostringstream strCout;
std::streambuf* oldCoutStreamBuf;
//Custom Boost Initialization
test_suite* init_func( int argc, char* argv[] )
{
if (argc == 0)
argv[1]=(char*)"a";
dev::test::Options::get();
argv[0] = (char*)"a";
//restore output for creating test
std::cout.rdbuf(oldCoutStreamBuf);
std::cerr.rdbuf(oldCoutStreamBuf);
const dev::test::Options& opt = dev::test::Options::get();
if (opt.createRandomTest)
{
//For no reason BOOST tend to remove valuable arg -t "TestSuiteName", so using original parametrs instead
if (dev::test::createRandomTest(originalArgc, originalArgv))
throw framework::internal_error("Create Random Test Error!");
else
{
//disable post output so the test json would be clean
std::cout.rdbuf( strCout.rdbuf() );
std::cerr.rdbuf( strCout.rdbuf() );
throw framework::nothing_to_test();
}
}
return 0;
}
//Custom Boost Unit Test Main
int main( int argc, char* argv[] )
{
originalArgc = argc;
originalArgv = new char*[argc];
for (int i = 0; i < argc; i++)
originalArgv[i] = argv[i];
//disable initial output
oldCoutStreamBuf = std::cout.rdbuf();
std::cout.rdbuf( strCout.rdbuf() );
std::cerr.rdbuf( strCout.rdbuf() );
try
{
framework::init( init_func, argc, argv );
@ -87,6 +117,4 @@ int main( int argc, char* argv[] )
return boost::exit_exception_failure;
}
return 0;
}

16
test/fuzzTesting/CMakeLists.txt

@ -1,19 +1,5 @@
cmake_policy(SET CMP0015 NEW)
file(GLOB HEADERS "*.h")
include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS})
include_directories(BEFORE ..)
include_directories(BEFORE ../..)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${CRYPTOPP_INCLUDE_DIRS})
include_directories(${JSON_RPC_CPP_INCLUDE_DIRS})
aux_source_directory(. SRCS)
add_executable(createRandomTest "./createRandomTest.cpp" "../TestHelper.cpp" "../Stats.cpp" "fuzzHelper.cpp" "../libdevcore/rlp.cpp" "../libethereum/transactionTests.cpp" "../libethereum/state.cpp" "../libevm/vm.cpp" "../libethereum/blockchain.cpp")
list(APPEND SRCS "./fuzzHelper.cpp")
add_sources(${SRCS})
target_link_libraries(createRandomTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
target_link_libraries(createRandomTest ethereum)
target_link_libraries(createRandomTest ethcore)
target_link_libraries(createRandomTest testutils)

228
test/fuzzTesting/checkRandomStateTest.cpp

@ -1,228 +0,0 @@
/*
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 checkRandomStateTest.cpp
* @author Christoph Jentzsch <jentzsch.simulationsoftware@gmail.com>
* @date 2015
* Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation.
*/
#include <libdevcore/Common.h>
#include <libdevcore/Assertions.h>
#include <libdevcore/Exceptions.h>
#include <libdevcore/Log.h>
#include <libevm/VMFactory.h>
#include <test/libevm/vm.h>
#include <test/TestHelper.h>
#pragma GCC diagnostic ignored "-Wunused-parameter"
using namespace std;
using namespace json_spirit;
using namespace dev::test;
using namespace dev;
bool doStateTest(mValue& _v);
int main(int argc, char *argv[])
{
g_logVerbosity = 0;
bool ret = false;
try
{
mValue v;
string s;
for (int i = 1; i < argc; ++i)
s += argv[i];
if (asserts(s.length() > 0))
{
cout << "Content of argument is empty\n";
return 1;
}
read_string(s, v);
ret = doStateTest(v);
}
catch (Exception const& _e)
{
cout << "Failed test with Exception: " << diagnostic_information(_e) << endl;
ret = false;
}
catch (std::exception const& _e)
{
cout << "Failed test with Exception: " << _e.what() << endl;
ret = false;
}
return ret;
}
bool doStateTest(mValue& _v)
{
eth::VMFactory::setKind(eth::VMKind::JIT);
for (auto& i: _v.get_obj())
{
mObject& o = i.second.get_obj();
assert(o.count("env") > 0);
assert(o.count("pre") > 0);
assert(o.count("transaction") > 0);
ImportTest importer(o, false);
eth::State theState = importer.m_statePre;
bytes output;
try
{
output = theState.execute(lastHashes(importer.m_environment.currentBlock.number()), importer.m_transaction).output;
}
catch (Exception const& _e)
{
cnote << "state execution did throw an exception: " << diagnostic_information(_e);
theState.commit();
}
catch (std::exception const& _e)
{
cnote << "state execution did throw an exception: " << _e.what();
}
assert(o.count("post") > 0);
assert(o.count("out") > 0);
//checkOutput(output, o);
int j = 0;
if (o["out"].type() == array_type)
for (auto const& d: o["out"].get_array())
{
if (asserts(output[j] == toInt(d)))
{
cout << "Output byte [" << j << "] different!";
return 1;
}
++j;
}
else if (o["out"].get_str().find("0x") == 0)
{
if (asserts(output == fromHex(o["out"].get_str().substr(2))))
return 1;
}
else
{
if (asserts(output == fromHex(o["out"].get_str())))
return 1;
}
//checkLog(theState.pending().size() ? theState.log(0) : LogEntries(), importer.m_environment.sub.logs);
eth::LogEntries logs = theState.pending().size() ? theState.log(0) : eth::LogEntries();
if (assertsEqual(logs.size(), importer.m_environment.sub.logs.size()))
return 1;
for (size_t i = 0; i < logs.size(); ++i)
{
if (assertsEqual(logs[i].address, importer.m_environment.sub.logs[i].address))
return 1;
if (assertsEqual(logs[i].topics, importer.m_environment.sub.logs[i].topics))
return 1;
if (asserts(logs[i].data == importer.m_environment.sub.logs[i].data))
return 1;
}
// check addresses
#if ETH_FATDB
auto expectedAddrs = importer.m_statePost.addresses();
auto resultAddrs = theState.addresses();
for (auto& expectedPair : expectedAddrs)
{
auto& expectedAddr = expectedPair.first;
auto resultAddrIt = resultAddrs.find(expectedAddr);
if (resultAddrIt == resultAddrs.end())
{
cout << "Missing expected address " << expectedAddr;
return 1;
}
else
{
if (importer.m_statePost.balance(expectedAddr) != theState.balance(expectedAddr))
{
cout << expectedAddr << ": incorrect balance " << theState.balance(expectedAddr) << ", expected " << importer.m_statePost.balance(expectedAddr);
return 1;
}
if (importer.m_statePost.transactionsFrom(expectedAddr) != theState.transactionsFrom(expectedAddr))
{
cout << expectedAddr << ": incorrect txCount " << theState.transactionsFrom(expectedAddr) << ", expected " << importer.m_statePost.transactionsFrom(expectedAddr);
return 1;
}
if (importer.m_statePost.code(expectedAddr) != theState.code(expectedAddr))
{
cout << expectedAddr << ": incorrect code";
return 1;
}
//checkStorage(importer.m_statePost.storage(expectedAddr), theState.storage(expectedAddr), expectedAddr);
unordered_map<u256, u256> _resultStore = theState.storage(expectedAddr);
for (auto&& expectedStorePair : importer.m_statePost.storage(expectedAddr))
{
auto& expectedStoreKey = expectedStorePair.first;
auto resultStoreIt = _resultStore.find(expectedStoreKey);
if (resultStoreIt == _resultStore.end())
{
cout << expectedAddr << ": missing store key " << expectedStoreKey << endl;
return 1;
}
else
{
auto& expectedStoreValue = expectedStorePair.second;
auto& resultStoreValue = resultStoreIt->second;
if (asserts(expectedStoreValue == resultStoreValue))
{
cout << expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue << endl;
return 1;
}
}
}
if (assertsEqual(_resultStore.size(), importer.m_statePost.storage(expectedAddr).size()))
return 1;
for (auto&& resultStorePair: _resultStore)
{
if (!importer.m_statePost.storage(expectedAddr).count(resultStorePair.first))
{
cout << expectedAddr << ": unexpected store key " << resultStorePair.first << endl;
return 1;
}
}
}
}
//checkAddresses<map<Address, u256> >(expectedAddrs, resultAddrs);
for (auto& resultPair : resultAddrs)
{
auto& resultAddr = resultPair.first;
auto expectedAddrIt = expectedAddrs.find(resultAddr);
if (expectedAddrIt == expectedAddrs.end())
return 1;
}
if (expectedAddrs != resultAddrs)
return 1;
#endif
if (theState.rootHash() != h256(o["postStateRoot"].get_str()))
{
cout << "wrong post state root" << endl;
return 1;
}
}
return 0;
}

298
test/fuzzTesting/checkRandomVMTest.cpp

@ -1,298 +0,0 @@
/*
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 checkRandomTest.cpp
* @author Christoph Jentzsch <jentzsch.simulationsoftware@gmail.com>
* @date 2015
* Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation.
*/
#include <libdevcore/Common.h>
#include <libdevcore/Assertions.h>
#include <libdevcore/Exceptions.h>
#include <libdevcore/Log.h>
#include <libevm/VMFactory.h>
#include <test/libevm/vm.h>
#include <test/TestHelper.h>
#pragma GCC diagnostic ignored "-Wunused-parameter"
using namespace std;
using namespace json_spirit;
using namespace dev::test;
using namespace dev;
bool doVMTest(mValue& _v);
int main(int argc, char *argv[])
{
g_logVerbosity = 0;
bool ret = false;
try
{
mValue v;
string s;
for (int i = 1; i < argc; ++i)
s += argv[i];
if (asserts(s.length() > 0))
{
cout << "Content of argument is empty\n";
return 1;
}
read_string(s, v);
ret = doVMTest(v);
}
catch (Exception const& _e)
{
cout << "Failed test with Exception: " << diagnostic_information(_e) << endl;
ret = false;
}
catch (std::exception const& _e)
{
cout << "Failed test with Exception: " << _e.what() << endl;
ret = false;
}
return ret;
}
bool doVMTest(mValue& _v)
{
eth::VMFactory::setKind(eth::VMKind::JIT);
for (auto& i: _v.get_obj())
{
cnote << i.first;
mObject& o = i.second.get_obj();
assert(o.count("env") > 0);
assert(o.count("pre") > 0);
assert(o.count("exec") > 0);
FakeExtVM fev;
fev.importEnv(o["env"].get_obj());
fev.importState(o["pre"].get_obj());
fev.importExec(o["exec"].get_obj());
if (fev.code.empty())
{
fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
fev.code = fev.thisTxCode;
}
bytes output;
bool vmExceptionOccured = false;
try
{
auto vm = eth::VMFactory::create();
output = vm->exec(fev.gas, fev, fev.simpleTrace());
}
catch (eth::VMException const&)
{
cnote << "Safe VM Exception";
vmExceptionOccured = true;
}
catch (Exception const& _e)
{
cnote << "VM did throw an exception: " << diagnostic_information(_e);
cnote << "Failed VM Test with Exception: " << _e.what();
return 1;
}
catch (std::exception const& _e)
{
cnote << "VM did throw an exception: " << _e.what();
cnote << "Failed VM Test with Exception: " << _e.what();
return 1;
}
// delete null entries in storage for the sake of comparison
for (auto &a: fev.addresses)
{
vector<u256> keystoDelete;
for (auto &s: get<2>(a.second))
{
if (s.second == 0)
keystoDelete.push_back(s.first);
}
for (auto const key: keystoDelete )
{
get<2>(a.second).erase(key);
}
}
if (o.count("post") > 0) // No exceptions expected
{
if (asserts(!vmExceptionOccured) || asserts(o.count("post") > 0) || asserts(o.count("callcreates") > 0) || asserts(o.count("out") > 0) || asserts(o.count("gas") > 0) || asserts(o.count("logs") > 0))
return 1;
dev::test::FakeExtVM test;
test.importState(o["post"].get_obj());
test.importCallCreates(o["callcreates"].get_array());
test.sub.logs = importLog(o["logs"].get_array());
//checkOutput(output, o);
int j = 0;
if (o["out"].type() == array_type)
for (auto const& d: o["out"].get_array())
{
if (asserts(output[j] == toInt(d)))
{
cout << "Output byte [" << j << "] different!";
return 1;
}
++j;
}
else if (o["out"].get_str().find("0x") == 0)
{
if (asserts(output == fromHex(o["out"].get_str().substr(2))))
return 1;
}
else
{
if (asserts(output == fromHex(o["out"].get_str())))
return 1;
}
if (asserts(toInt(o["gas"]) == fev.gas))
return 1;
auto& expectedAddrs = test.addresses;
auto& resultAddrs = fev.addresses;
for (auto&& expectedPair : expectedAddrs)
{
auto& expectedAddr = expectedPair.first;
auto resultAddrIt = resultAddrs.find(expectedAddr);
if (resultAddrIt == resultAddrs.end())
{
cout << "Missing expected address " << expectedAddr;
return 1;
}
else
{
auto& expectedState = expectedPair.second;
auto& resultState = resultAddrIt->second;
if (asserts(std::get<0>(expectedState) == std::get<0>(resultState)))
{
cout << expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState);
return 1;
}
if (asserts(std::get<1>(expectedState) == std::get<1>(resultState)))
{
cout << expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState);
return 1;
}
if (asserts(std::get<3>(expectedState) == std::get<3>(resultState)))
{
cout << expectedAddr << ": incorrect code";
return 1;
}
//checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr);
for (auto&& expectedStorePair : std::get<2>(expectedState))
{
auto& expectedStoreKey = expectedStorePair.first;
auto resultStoreIt = std::get<2>(resultState).find(expectedStoreKey);
if (resultStoreIt == std::get<2>(resultState).end())
{
cout << expectedAddr << ": missing store key " << expectedStoreKey << endl;
return 1;
}
else
{
auto& expectedStoreValue = expectedStorePair.second;
auto& resultStoreValue = resultStoreIt->second;
if (asserts(expectedStoreValue == resultStoreValue))
{
cout << expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue << endl;
return 1;
}
}
}
if (assertsEqual(std::get<2>(resultState).size(), std::get<2>(expectedState).size()))
return 1;
for (auto&& resultStorePair: std::get<2>(resultState))
{
if (!std::get<2>(expectedState).count(resultStorePair.first))
{
cout << expectedAddr << ": unexpected store key " << resultStorePair.first << endl;
return 1;
}
}
}
}
//checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses);
for (auto& resultPair : fev.addresses)
{
auto& resultAddr = resultPair.first;
auto expectedAddrIt = test.addresses.find(resultAddr);
if (expectedAddrIt == test.addresses.end())
{
cout << "Missing result address " << resultAddr << endl;
return 1;
}
}
if (asserts(test.addresses == fev.addresses))
return 1;
if (asserts(test.callcreates == fev.callcreates))
return 1;
//checkCallCreates(fev.callcreates, test.callcreates);
{
if (assertsEqual(test.callcreates.size(), fev.callcreates.size()))
return 1;
for (size_t i = 0; i < test.callcreates.size(); ++i)
{
if (asserts(test.callcreates[i].data() == fev.callcreates[i].data()))
return 1;
if (asserts(test.callcreates[i].receiveAddress() == fev.callcreates[i].receiveAddress()))
return 1;
if (asserts(test.callcreates[i].gas() == fev.callcreates[i].gas()))
return 1;
if (asserts(test.callcreates[i].value() == fev.callcreates[i].value()))
return 1;
}
}
//checkLog(fev.sub.logs, test.sub.logs);
{
if (assertsEqual(fev.sub.logs.size(), test.sub.logs.size()))
return 1;
for (size_t i = 0; i < fev.sub.logs.size(); ++i)
{
if (assertsEqual(fev.sub.logs[i].address, test.sub.logs[i].address))
return 1;
if (assertsEqual(fev.sub.logs[i].topics, test.sub.logs[i].topics))
return 1;
if (asserts(fev.sub.logs[i].data == test.sub.logs[i].data))
return 1;
}
}
}
else // Exception expected
{
if (asserts(vmExceptionOccured))
return 1;
}
}
// test passed
return 0;
}

258
test/fuzzTesting/createRandomStateTest.cpp

@ -1,258 +0,0 @@
/*
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 createRandomStateTest.cpp
* @author Christoph Jentzsch <jentzsch.simulationsoftware@gmail.com>
* @date 2015
* Creating a random state test.
*/
#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>
#include <json_spirit/json_spirit_writer_template.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonData.h>
#include <libevmcore/Instruction.h>
#include <libevm/VMFactory.h>
#include <test/libevm/vm.h>
#include <test/TestHelper.h>
#include <test/fuzzTesting/fuzzHelper.h>
using namespace std;
using namespace json_spirit;
using namespace dev;
void doStateTests(json_spirit::mValue& _v);
void doChristophAlgo();
void doRandomCodeAlgo();
string const c_testExample = R"(
{
"randomStatetest" : {
"env" : {
"currentCoinbase" : "945304eb96065b2a98b57a48a06ae28d285a71b5",
"currentDifficulty" : "5623894562375",
"currentGasLimit" : "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "0",
"code" : "0x6001600101600055",
"nonce" : "0",
"storage" : {
}
},
"945304eb96065b2a98b57a48a06ae28d285a71b5" : {
"balance" : "46",
"code" : "0x6000355415600957005b60203560003555",
"nonce" : "0",
"storage" : {
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000000000000000000",
"code" : "0x",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" : {
"data" : "0x42",
"gasLimit" : "400000",
"gasPrice" : "1",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "100000"
}
}
}
)";
int main(int argc, char *argv[])
{
for (auto i = 0; i < argc; ++i)
{
auto arg = std::string{argv[i]};
dev::test::Options& options = const_cast<dev::test::Options&>(dev::test::Options::get());
if (arg == "--fulloutput")
options.fulloutput = true;
}
//doChristophAlgo();
doRandomCodeAlgo();
return 0;
}
void doChristophAlgo()
{
g_logVerbosity = 0;
// create random code
boost::random::mt19937 gen;
auto now = chrono::steady_clock::now().time_since_epoch();
auto timeSinceEpoch = chrono::duration_cast<chrono::nanoseconds>(now).count();
gen.seed(static_cast<unsigned int>(timeSinceEpoch));
// set min and max length of the random evm code
boost::random::uniform_int_distribution<> lengthOfCodeDist(8, 24);
boost::random::uniform_int_distribution<> reasonableInputValuesSize(0, 7);
boost::random::uniform_int_distribution<> opcodeDist(0, 255);
boost::random::uniform_int_distribution<> BlockInfoOpcodeDist(0x40, 0x45);
boost::random::uniform_int_distribution<> uniformInt(0, 0x7fffffff);
boost::random::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > randGenInputValue(gen, reasonableInputValuesSize);
boost::random::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > randGenUniformInt(gen, uniformInt);
boost::random::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > randGen(gen, opcodeDist);
boost::random::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > randGenBlockInfoOpcode(gen, BlockInfoOpcodeDist);
std::vector<u256> reasonableInputValues;
reasonableInputValues.push_back(0);
reasonableInputValues.push_back(1);
reasonableInputValues.push_back(50000);
reasonableInputValues.push_back(u256("0x10000000000000000000000000000000000000000"));
reasonableInputValues.push_back(u256("0xffffffffffffffffffffffffffffffffffffffff"));
reasonableInputValues.push_back(u256("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"));
reasonableInputValues.push_back(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
reasonableInputValues.push_back(u256("0x945304eb96065b2a98b57a48a06ae28d285a71b5"));
reasonableInputValues.push_back(randGenUniformInt());
int lengthOfCode = lengthOfCodeDist(gen);
string randomCode;
for (int i = 0; i < lengthOfCode; ++i)
{
// pre-fill stack to avoid that most of the test fail with a stackunderflow
if (i < 8 && (randGen() < 192))
{
randomCode += randGen() < 32 ? toHex(toCompactBigEndian((uint8_t)randGenBlockInfoOpcode())) : "7f" + toHex(reasonableInputValues[randGenInputValue()]);
continue;
}
uint8_t opcode = randGen();
// disregard all invalid commands, except of one (0x0c)
if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (randGen() > 250)))
randomCode += toHex(toCompactBigEndian(opcode));
else
i--;
}
mValue v;
read_string(c_testExample, v);
// insert new random code
v.get_obj().find("randomStatetest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode + (randGen() > 128 ? "55" : "") + (randGen() > 128 ? "60005155" : "");
// insert new data in tx
v.get_obj().find("randomStatetest")->second.get_obj().find("transaction")->second.get_obj()["data"] = "0x" + randomCode;
// insert new value in tx
v.get_obj().find("randomStatetest")->second.get_obj().find("transaction")->second.get_obj()["value"] = toString(randGenUniformInt());
// insert new gasLimit in tx
v.get_obj().find("randomStatetest")->second.get_obj().find("transaction")->second.get_obj()["gasLimit"] = "0x" + toHex(toCompactBigEndian((int)randGenUniformInt()));
// fill test
doStateTests(v);
// stream to output for further handling by the bash script
cout << json_spirit::write_string(v, true);
}
void doRandomCodeAlgo()
{
g_logVerbosity = 0;
dev::test::RandomCodeOptions options;
options.setWeight(dev::eth::Instruction::STOP, 10); //default 50
options.setWeight(dev::eth::Instruction::SSTORE, 70);
options.setWeight(dev::eth::Instruction::CALL, 75);
options.addAddress(Address("0xffffffffffffffffffffffffffffffffffffffff"));
options.addAddress(Address("0x1000000000000000000000000000000000000000"));
options.addAddress(Address("0x095e7baea6a6c7c4c2dfeb977efac326af552d87")); //coinbase
options.addAddress(Address("0x945304eb96065b2a98b57a48a06ae28d285a71b5"));
options.addAddress(Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"));
options.smartCodeProbability = 35;
string randomCode = dev::test::RandomCode::generate(10, options);
string randomData = dev::test::RandomCode::generate(10, options);
mValue v;
read_string(c_testExample, v);
// insert new random code
v.get_obj().find("randomStatetest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode;
// insert new data in tx
v.get_obj().find("randomStatetest")->second.get_obj().find("transaction")->second.get_obj()["data"] = "0x" + randomData;
// insert new value in tx
v.get_obj().find("randomStatetest")->second.get_obj().find("transaction")->second.get_obj()["value"] = dev::test::RandomCode::randomUniIntHex();
// insert new gasLimit in tx
v.get_obj().find("randomStatetest")->second.get_obj().find("transaction")->second.get_obj()["gasLimit"] = dev::test::RandomCode::randomUniIntHex();
// fill test
doStateTests(v);
// stream to output for further handling by the bash script
cout << json_spirit::write_string(v, true);
}
void doStateTests(json_spirit::mValue& _v)
{
eth::VMFactory::setKind(eth::VMKind::Interpreter);
for (auto& i: _v.get_obj())
{
//cerr << i.first << endl;
mObject& o = i.second.get_obj();
assert(o.count("env") > 0);
assert(o.count("pre") > 0);
assert(o.count("transaction") > 0);
bytes output;
try
{
test::ImportTest importer(o, true);
eth::State theState = importer.m_statePre;
try
{
output = theState.execute(test::lastHashes(importer.m_environment.currentBlock.number()), importer.m_transaction).output;
}
catch (Exception const& _e)
{
cnote << "state execution did throw an exception: " << diagnostic_information(_e);
theState.commit();
}
catch (std::exception const& _e)
{
cnote << "state execution did throw an exception: " << _e.what();
}
#if ETH_FATDB
importer.exportTest(output, theState);
#else
cout << "You can not fill tests when FATDB is switched off";
#endif
}
catch(...)
{
cnote << "Error filling test, probably...";
}
}
}

10
test/fuzzTesting/createRandomTest.cpp

@ -19,8 +19,6 @@
* @date 2015
*/
///This file require #define DONTUSE_BOOST_MACROS compile flag to run!
#include <string>
#include <iostream>
@ -44,7 +42,8 @@ int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, js
std::vector<std::string> getTypes();
void parseTestWithTypes(std::string& test);
int main(int argc, char *argv[])
namespace dev { namespace test {
int createRandomTest(int argc, char *argv[])
{
std::string testSuite;
std::string testFillString;
@ -75,7 +74,7 @@ int main(int argc, char *argv[])
s += argv[j];
if (asserts(s.length() > 0))
{
std::cout << "Error! Content of argument is empty! (Usage -checktest textstream) \n";
std::cout << "Error! Content of argument is empty! (Usage -checktest textstream)" << std::endl;
return 1;
}
if (arg == "-filltest")
@ -99,7 +98,7 @@ int main(int argc, char *argv[])
if (testSuite == "")
{
std::cout << "Error! Test suite not supported! (Usage -t TestSuite)";
std::cout << "Error! Test suite not supported! (Usage -t TestSuite)" << std::endl;
return 1;
}
else
@ -153,6 +152,7 @@ int main(int argc, char *argv[])
return 0;
}
}} //namesapces
int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, json_spirit::mValue& _value, bool _debug)
{

206
test/fuzzTesting/createRandomVMTest.cpp

@ -1,206 +0,0 @@
/*
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 createRandomTest.cpp
* @author Christoph Jentzsch <jentzsch.simulationsoftware@gmail.com>
* @date 2014
* Creating a random virtual machine test.
*/
#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>
#include <json_spirit/json_spirit_writer_template.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonData.h>
#include <libevmcore/Instruction.h>
#include <libevm/VMFactory.h>
#include <test/libevm/vm.h>
#include <test/TestHelper.h>
using namespace std;
using namespace json_spirit;
using namespace dev;
void doMyTests(json_spirit::mValue& _v);
int main(int argc, char *argv[])
{
g_logVerbosity = 0;
// create random code
boost::random::mt19937 gen;
auto now = chrono::steady_clock::now().time_since_epoch();
auto timeSinceEpoch = chrono::duration_cast<chrono::nanoseconds>(now).count();
gen.seed(static_cast<unsigned int>(timeSinceEpoch));
boost::random::uniform_int_distribution<> lengthOfCodeDist(2, 16);
boost::random::uniform_int_distribution<> opcodeDist(0, 255);
boost::random::uniform_int_distribution<> BlockInfoOpcodeDist(0x40, 0x45);
boost::random::variate_generator<boost::mt19937&,
boost::random::uniform_int_distribution<> > randGen(gen, opcodeDist);
boost::random::variate_generator<boost::mt19937&,
boost::random::uniform_int_distribution<> > randGenBlockInfoOpcode(gen, BlockInfoOpcodeDist);
int lengthOfCode = lengthOfCodeDist(gen);
string randomCode;
for (int i = 0; i < lengthOfCode; ++i)
{
if (i < 8 && (randGen() < 192))
{
randomCode += toHex(toCompactBigEndian((uint8_t)randGenBlockInfoOpcode()));
continue;
}
uint8_t opcode = randGen();
// disregard all invalid commands, except of one (0x0c)
if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (randGen() > 250)))
randomCode += toHex(toCompactBigEndian(opcode));
else
i--;
}
const string s =\
"{\n\
\"randomVMtest\": {\n\
\"env\" : {\n\
\"previousHash\" : \"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6\",\n\
\"currentNumber\" : \"300\",\n\
\"currentGasLimit\" : \"1000000\",\n\
\"currentDifficulty\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\
\"currentTimestamp\" : 2,\n\
\"currentCoinbase\" : \"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba\"\n\
},\n\
\"pre\" : {\n\
\"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6\" : {\n\
\"balance\" : \"1000000000000000000\",\n\
\"nonce\" : 0,\n\
\"code\" : \"random\",\n\
\"storage\": {}\n\
}\n\
},\n\
\"exec\" : {\n\
\"address\" : \"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6\",\n\
\"origin\" : \"cd1722f3947def4cf144679da39c4c32bdc35681\",\n\
\"caller\" : \"cd1722f3947def4cf144679da39c4c32bdc35681\",\n\
\"value\" : \"1000000000000000000\",\n\
\"data\" : \"\",\n\
\"gasPrice\" : \"100000000000000\",\n\
\"gas\" : \"10000\"\n\
}\n\
}\n\
}";
mValue v;
read_string(s, v);
// insert new random code
v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode + (randGen() > 128 ? "55" : "");
// execute code in vm
doMyTests(v);
// stream to output for further handling by the bash script
cout << json_spirit::write_string(v, true);
return 0;
}
void doMyTests(json_spirit::mValue& _v)
{
eth::VMFactory::setKind(eth::VMKind::Interpreter);
for (auto& i: _v.get_obj())
{
cnote << i.first;
mObject& o = i.second.get_obj();
assert(o.count("env") > 0);
assert(o.count("pre") > 0);
assert(o.count("exec") > 0);
dev::test::FakeExtVM fev;
fev.importEnv(o["env"].get_obj());
fev.importState(o["pre"].get_obj());
o["pre"] = mValue(fev.exportState());
fev.importExec(o["exec"].get_obj());
if (fev.code.empty())
{
fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
fev.code = fev.thisTxCode;
}
bytes output;
auto vm = eth::VMFactory::create();
bool vmExceptionOccured = false;
try
{
output = vm->exec(fev.gas, fev, fev.simpleTrace());
}
catch (eth::VMException const& _e)
{
cnote << "VM did throw an exception: " << diagnostic_information(_e);
vmExceptionOccured = true;
}
catch (Exception const& _e)
{
cnote << "VM did throw an exception: " << diagnostic_information(_e);
}
catch (std::exception const& _e)
{
cnote << "VM did throw an exception: " << _e.what();
}
// delete null entries in storage for the sake of comparison
for (auto &a: fev.addresses)
{
vector<u256> keystoDelete;
for (auto &s: get<2>(a.second))
{
if (s.second == 0)
keystoDelete.push_back(s.first);
}
for (auto const key: keystoDelete )
{
get<2>(a.second).erase(key);
}
}
o["env"] = mValue(fev.exportEnv());
o["exec"] = mValue(fev.exportExec());
if (!vmExceptionOccured)
{
o["post"] = mValue(fev.exportState());
o["callcreates"] = fev.exportCallCreates();
o["out"] = toHex(output, 2, HexPrefix::Add);
o["gas"] = toCompactHex(fev.gas, HexPrefix::Add, 1);
o["logs"] = test::exportLog(fev.sub.logs);
}
}
}

59
test/libdevcore/rlp.cpp

@ -65,8 +65,8 @@ namespace dev
cnote << " " << i.first;
testname = "(" + i.first + ") ";
TBOOST_REQUIRE_MESSAGE((o.count("out") > 0), testname + "out not set!");
TBOOST_REQUIRE_MESSAGE((!o["out"].is_null()), testname + "out is set to null!");
BOOST_REQUIRE_MESSAGE(o.count("out") > 0, testname + "out not set!");
BOOST_REQUIRE_MESSAGE(!o["out"].is_null(), testname + "out is set to null!");
if (_fillin)
{
@ -91,7 +91,7 @@ namespace dev
else
{
//Check Encode
TBOOST_REQUIRE_MESSAGE((o.count("in") > 0), testname + "in not set!");
BOOST_REQUIRE_MESSAGE(o.count("in") > 0, testname + "in not set!");
RlpType rlpType = RlpType::Test;
if (o["in"].type() == js::str_type)
{
@ -113,10 +113,7 @@ namespace dev
stringstream msg;
msg << "Encoding Failed: expected: " << expectedText << std::endl;
msg << " But Computed: " << computedText;
TBOOST_CHECK_MESSAGE(
(expectedText == computedText),
testname + msg.str()
);
BOOST_CHECK_MESSAGE(expectedText == computedText, testname + msg.str());
}
//Check Decode
@ -158,11 +155,11 @@ namespace dev
//Check that there was an exception as input is INVALID
if (rlpType == RlpType::Invalid && !was_exception)
TBOOST_ERROR(testname + "Expected RLP Exception as rlp should be invalid!");
BOOST_ERROR(testname + "Expected RLP Exception as rlp should be invalid!");
//input is VALID check that there was no exceptions
if (was_exception)
TBOOST_ERROR(testname + "Unexpected RLP Exception!");
BOOST_ERROR(testname + "Unexpected RLP Exception!");
}
}
}
@ -200,34 +197,34 @@ namespace dev
stringstream bintStream(bigIntStr);
bigint val;
bintStream >> val;
TBOOST_CHECK(( !u.isList() ));
TBOOST_CHECK(( !u.isNull() ));
TBOOST_CHECK(( u == val ));
BOOST_CHECK( !u.isList() );
BOOST_CHECK( !u.isNull() );
BOOST_CHECK( u == val );
}
else
{
TBOOST_CHECK(( !u.isList() ));
TBOOST_CHECK(( !u.isNull() ));
TBOOST_CHECK(( u.isData() ));
TBOOST_CHECK(( u.size() == expectedText.length() ));
TBOOST_CHECK(( u == expectedText ));
BOOST_CHECK( !u.isList() );
BOOST_CHECK( !u.isNull() );
BOOST_CHECK( u.isData() );
BOOST_CHECK( u.size() == expectedText.length() );
BOOST_CHECK( u == expectedText );
}
}
else if ( v.type() == js::int_type )
{
const int expectedValue = v.get_int();
TBOOST_CHECK(( u.isInt() ));
TBOOST_CHECK(( !u.isList() ));
TBOOST_CHECK(( !u.isNull() ));
TBOOST_CHECK(( u == expectedValue ));
BOOST_CHECK( u.isInt() );
BOOST_CHECK( !u.isList() );
BOOST_CHECK( !u.isNull() );
BOOST_CHECK( u == expectedValue );
}
else if ( v.type() == js::array_type )
{
TBOOST_CHECK(( u.isList() ));
TBOOST_CHECK(( !u.isInt() ));
TBOOST_CHECK(( !u.isData() ));
BOOST_CHECK( u.isList() );
BOOST_CHECK( !u.isInt() );
BOOST_CHECK( !u.isData() );
js::mArray& arr = v.get_array();
TBOOST_CHECK(( u.itemCount() == arr.size() ));
BOOST_CHECK( u.itemCount() == arr.size() );
unsigned i;
for( i = 0; i < arr.size(); i++ )
{
@ -237,7 +234,7 @@ namespace dev
}
else
{
TBOOST_ERROR("Invalid Javascript object!");
BOOST_ERROR("Invalid Javascript object!");
}
}
}
@ -259,11 +256,11 @@ BOOST_AUTO_TEST_CASE(EmptyArrayList)
}
catch (Exception const& _e)
{
TBOOST_ERROR("(EmptyArrayList) Failed test with Exception: " << _e.what());
BOOST_ERROR("(EmptyArrayList) Failed test with Exception: " << _e.what());
}
catch (exception const& _e)
{
TBOOST_ERROR("(EmptyArrayList) Failed test with Exception: " << _e.what());
BOOST_ERROR("(EmptyArrayList) Failed test with Exception: " << _e.what());
}
}
@ -297,7 +294,7 @@ BOOST_AUTO_TEST_CASE(rlpRandom)
cnote << "Testing ..." << path.filename();
json_spirit::mValue v;
string s = asString(dev::contents(path.string()));
TBOOST_REQUIRE_MESSAGE((s.length() > 0), "Content of " + path.string() + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + path.string() + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
json_spirit::read_string(s, v);
test::Listener::notifySuiteStarted(path.filename().string());
dev::test::doRlpTests(v, false);
@ -305,11 +302,11 @@ BOOST_AUTO_TEST_CASE(rlpRandom)
catch (Exception const& _e)
{
TBOOST_ERROR(path.filename().string() + "Failed test with Exception: " << diagnostic_information(_e));
BOOST_ERROR(path.filename().string() + "Failed test with Exception: " << diagnostic_information(_e));
}
catch (std::exception const& _e)
{
TBOOST_ERROR(path.filename().string() + "Failed test with Exception: " << _e.what());
BOOST_ERROR(path.filename().string() + "Failed test with Exception: " << _e.what());
}
}
}

129
test/libethereum/blockchain.cpp

@ -65,8 +65,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
cnote << i.first;
testname = "(" + i.first + ") ";
TBOOST_REQUIRE(o.count("genesisBlockHeader"));
TBOOST_REQUIRE(o.count("pre"));
BOOST_REQUIRE(o.count("genesisBlockHeader"));
BOOST_REQUIRE(o.count("pre"));
ImportTest importer(o, _fillin, testType::BlockChainTests);
TransientDirectory tdStateDB;
@ -83,7 +83,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
if (_fillin)
biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj(), trueState.rootHash());
else
TBOOST_CHECK_MESSAGE((biGenesisBlock.stateRoot() == trueState.rootHash()), testname + "root hash does not match");
BOOST_CHECK_MESSAGE(biGenesisBlock.stateRoot() == trueState.rootHash(), testname + "root hash does not match");
if (_fillin)
{
@ -105,7 +105,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
if (_fillin)
{
TBOOST_REQUIRE(o.count("blocks"));
BOOST_REQUIRE(o.count("blocks"));
mArray blArray;
blockSet genesis;
@ -155,7 +155,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
// get txs
TransactionQueue txs;
ZeroGasPricer gp;
TBOOST_REQUIRE(blObj.count("transactions"));
BOOST_REQUIRE(blObj.count("transactions"));
for (auto const& txObj: blObj["transactions"].get_array())
{
mObject tx = txObj.get_obj();
@ -349,29 +349,29 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
catch (Exception const& _e)
{
cnote << "state sync or block import did throw an exception: " << diagnostic_information(_e);
TBOOST_CHECK((blObj.count("blockHeader") == 0));
TBOOST_CHECK((blObj.count("transactions") == 0));
TBOOST_CHECK((blObj.count("uncleHeaders") == 0));
BOOST_CHECK(blObj.count("blockHeader") == 0);
BOOST_CHECK(blObj.count("transactions") == 0);
BOOST_CHECK(blObj.count("uncleHeaders") == 0);
continue;
}
catch (std::exception const& _e)
{
cnote << "state sync or block import did throw an exception: " << _e.what();
TBOOST_CHECK((blObj.count("blockHeader") == 0));
TBOOST_CHECK((blObj.count("transactions") == 0));
TBOOST_CHECK((blObj.count("uncleHeaders") == 0));
BOOST_CHECK(blObj.count("blockHeader") == 0);
BOOST_CHECK(blObj.count("transactions") == 0);
BOOST_CHECK(blObj.count("uncleHeaders") == 0);
continue;
}
catch (...)
{
cnote << "state sync or block import did throw an exception\n";
TBOOST_CHECK((blObj.count("blockHeader") == 0));
TBOOST_CHECK((blObj.count("transactions") == 0));
TBOOST_CHECK((blObj.count("uncleHeaders") == 0));
BOOST_CHECK(blObj.count("blockHeader") == 0);
BOOST_CHECK(blObj.count("transactions") == 0);
BOOST_CHECK(blObj.count("uncleHeaders") == 0);
continue;
}
TBOOST_REQUIRE(blObj.count("blockHeader"));
BOOST_REQUIRE(blObj.count("blockHeader"));
mObject tObj = blObj["blockHeader"].get_obj();
BlockHeader blockHeaderFromFields;
@ -384,42 +384,41 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
if (importedAndBest)
{
//Check the fields restored from RLP to original fields
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.headerHash(WithProof) == blockFromRlp.headerHash(WithProof)), testname + "hash in given RLP not matching the block hash!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.parentHash() == blockFromRlp.parentHash()), testname + "parentHash in given RLP not matching the block parentHash!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.sha3Uncles() == blockFromRlp.sha3Uncles()), testname + "sha3Uncles in given RLP not matching the block sha3Uncles!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.beneficiary() == blockFromRlp.beneficiary()), testname + "beneficiary in given RLP not matching the block beneficiary!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.stateRoot() == blockFromRlp.stateRoot()), testname + "stateRoot in given RLP not matching the block stateRoot!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.transactionsRoot() == blockFromRlp.transactionsRoot()), testname + "transactionsRoot in given RLP not matching the block transactionsRoot!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.receiptsRoot() == blockFromRlp.receiptsRoot()), testname + "receiptsRoot in given RLP not matching the block receiptsRoot!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.logBloom() == blockFromRlp.logBloom()), testname + "logBloom in given RLP not matching the block logBloom!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.difficulty() == blockFromRlp.difficulty()), testname + "difficulty in given RLP not matching the block difficulty!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.number() == blockFromRlp.number()), testname + "number in given RLP not matching the block number!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.gasLimit() == blockFromRlp.gasLimit()),"testname + gasLimit in given RLP not matching the block gasLimit!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.gasUsed() == blockFromRlp.gasUsed()), testname + "gasUsed in given RLP not matching the block gasUsed!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.timestamp() == blockFromRlp.timestamp()), testname + "timestamp in given RLP not matching the block timestamp!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.extraData() == blockFromRlp.extraData()), testname + "extraData in given RLP not matching the block extraData!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.mixHash() == blockFromRlp.mixHash()), testname + "mixHash in given RLP not matching the block mixHash!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields.nonce() == blockFromRlp.nonce()), testname + "nonce in given RLP not matching the block nonce!");
TBOOST_CHECK_MESSAGE((blockHeaderFromFields == blockFromRlp), testname + "However, blockHeaderFromFields != blockFromRlp!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash(WithProof) == blockFromRlp.headerHash(WithProof), testname + "hash in given RLP not matching the block hash!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.parentHash() == blockFromRlp.parentHash(), testname + "parentHash in given RLP not matching the block parentHash!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.sha3Uncles() == blockFromRlp.sha3Uncles(), testname + "sha3Uncles in given RLP not matching the block sha3Uncles!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.beneficiary() == blockFromRlp.beneficiary(), testname + "beneficiary in given RLP not matching the block beneficiary!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.stateRoot() == blockFromRlp.stateRoot(), testname + "stateRoot in given RLP not matching the block stateRoot!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.transactionsRoot() == blockFromRlp.transactionsRoot(), testname + "transactionsRoot in given RLP not matching the block transactionsRoot!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.receiptsRoot() == blockFromRlp.receiptsRoot(), testname + "receiptsRoot in given RLP not matching the block receiptsRoot!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom() == blockFromRlp.logBloom(), testname + "logBloom in given RLP not matching the block logBloom!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.difficulty() == blockFromRlp.difficulty(), testname + "difficulty in given RLP not matching the block difficulty!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.number() == blockFromRlp.number(), testname + "number in given RLP not matching the block number!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasLimit() == blockFromRlp.gasLimit(),"testname + gasLimit in given RLP not matching the block gasLimit!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasUsed() == blockFromRlp.gasUsed(), testname + "gasUsed in given RLP not matching the block gasUsed!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.timestamp() == blockFromRlp.timestamp(), testname + "timestamp in given RLP not matching the block timestamp!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.extraData() == blockFromRlp.extraData(), testname + "extraData in given RLP not matching the block extraData!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.mixHash() == blockFromRlp.mixHash(), testname + "mixHash in given RLP not matching the block mixHash!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields.nonce() == blockFromRlp.nonce(), testname + "nonce in given RLP not matching the block nonce!");
BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, testname + "However, blockHeaderFromFields != blockFromRlp!");
//Check transaction list
Transactions txsFromField;
for (auto const& txObj: blObj["transactions"].get_array())
{
mObject tx = txObj.get_obj();
TBOOST_REQUIRE(tx.count("nonce"));
TBOOST_REQUIRE(tx.count("gasPrice"));
TBOOST_REQUIRE(tx.count("gasLimit"));
TBOOST_REQUIRE(tx.count("to"));
TBOOST_REQUIRE(tx.count("value"));
TBOOST_REQUIRE(tx.count("v"));
TBOOST_REQUIRE(tx.count("r"));
TBOOST_REQUIRE(tx.count("s"));
TBOOST_REQUIRE(tx.count("data"));
BOOST_REQUIRE(tx.count("nonce"));
BOOST_REQUIRE(tx.count("gasPrice"));
BOOST_REQUIRE(tx.count("gasLimit"));
BOOST_REQUIRE(tx.count("to"));
BOOST_REQUIRE(tx.count("value"));
BOOST_REQUIRE(tx.count("v"));
BOOST_REQUIRE(tx.count("r"));
BOOST_REQUIRE(tx.count("s"));
BOOST_REQUIRE(tx.count("data"));
try
{
@ -428,7 +427,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
}
catch (Exception const& _e)
{
TBOOST_ERROR("Failed transaction constructor with Exception: " << diagnostic_information(_e));
BOOST_ERROR("Failed transaction constructor with Exception: " << diagnostic_information(_e));
}
catch (exception const& _e)
{
@ -444,22 +443,22 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
txsFromRlp.push_back(tx);
}
TBOOST_CHECK_MESSAGE((txsFromRlp.size() == txsFromField.size()), "transaction list size does not match");
BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match");
for (size_t i = 0; i < txsFromField.size(); ++i)
{
TBOOST_CHECK_MESSAGE((txsFromField[i].data() == txsFromRlp[i].data()), testname + "transaction data in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].gas() == txsFromRlp[i].gas()), testname + "transaction gasLimit in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice()), testname + "transaction gasPrice in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].nonce() == txsFromRlp[i].nonce()), testname + "transaction nonce in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].signature().r == txsFromRlp[i].signature().r), testname + "transaction r in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].signature().s == txsFromRlp[i].signature().s), testname + "transaction s in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].signature().v == txsFromRlp[i].signature().v), testname + "transaction v in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress()), testname + "transaction receiveAddress in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].value() == txsFromRlp[i].value()), testname + "transaction receiveAddress in rlp and in field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i] == txsFromRlp[i]), testname + "transactions from rlp and transaction from field do not match");
TBOOST_CHECK_MESSAGE((txsFromField[i].rlp() == txsFromRlp[i].rlp()), testname + "transactions rlp do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].data() == txsFromRlp[i].data(), testname + "transaction data in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].gas() == txsFromRlp[i].gas(), testname + "transaction gasLimit in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice(), testname + "transaction gasPrice in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].nonce() == txsFromRlp[i].nonce(), testname + "transaction nonce in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].signature().r == txsFromRlp[i].signature().r, testname + "transaction r in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].signature().s == txsFromRlp[i].signature().s, testname + "transaction s in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].signature().v == txsFromRlp[i].signature().v, testname + "transaction v in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), testname + "transaction receiveAddress in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), testname + "transaction receiveAddress in rlp and in field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], testname + "transactions from rlp and transaction from field do not match");
BOOST_CHECK_MESSAGE(txsFromField[i].rlp() == txsFromRlp[i].rlp(), testname + "transactions rlp do not match");
}
// check uncle list
@ -470,7 +469,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
for (auto const& uBlHeaderObj: blObj["uncleHeaders"].get_array())
{
mObject uBlH = uBlHeaderObj.get_obj();
TBOOST_REQUIRE((uBlH.size() == 16));
BOOST_REQUIRE(uBlH.size() == 16);
bytes uncleRLP = createBlockRLPFromFields(uBlH);
const RLP c_uRLP(uncleRLP);
BlockHeader uncleBlockHeader;
@ -480,7 +479,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
}
catch(...)
{
TBOOST_ERROR(testname + "invalid uncle header");
BOOST_ERROR(testname + "invalid uncle header");
}
uBlHsFromField.push_back(uncleBlockHeader);
}
@ -494,15 +493,15 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
uBlHsFromRlp.push_back(uBl);
}
TBOOST_REQUIRE_EQUAL(uBlHsFromField.size(), uBlHsFromRlp.size());
BOOST_REQUIRE_EQUAL(uBlHsFromField.size(), uBlHsFromRlp.size());
for (size_t i = 0; i < uBlHsFromField.size(); ++i)
TBOOST_CHECK_MESSAGE((uBlHsFromField[i] == uBlHsFromRlp[i]), testname + "block header in rlp and in field do not match");
BOOST_CHECK_MESSAGE(uBlHsFromField[i] == uBlHsFromRlp[i], testname + "block header in rlp and in field do not match");
}//importedAndBest
}//all blocks
TBOOST_REQUIRE((o.count("lastblockhash") > 0));
TBOOST_CHECK_MESSAGE((toString(trueBc.info().hash()) == o["lastblockhash"].get_str()),
BOOST_REQUIRE(o.count("lastblockhash") > 0);
BOOST_CHECK_MESSAGE(toString(trueBc.info().hash()) == o["lastblockhash"].get_str(),
testname + "Boost check: " + i.first + " lastblockhash does not match " + toString(trueBc.info().hash()) + " expected: " + o["lastblockhash"].get_str());
}
}
@ -732,11 +731,11 @@ BlockHeader constructBlock(mObject& _o, h256 const& _stateRoot)
}
catch (std::exception const& _e)
{
TBOOST_ERROR("Failed block population with Exception: " << _e.what());
BOOST_ERROR("Failed block population with Exception: " << _e.what());
}
catch(...)
{
TBOOST_ERROR("block population did throw an unknown exception\n");
BOOST_ERROR("block population did throw an unknown exception\n");
}
return ret;
}

12
test/libethereum/state.cpp

@ -54,9 +54,9 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
cnote << i.first;
testname = "(" + i.first + ") ";
TBOOST_REQUIRE_MESSAGE((o.count("env") > 0), testname + "env not set!");
TBOOST_REQUIRE_MESSAGE((o.count("pre") > 0), testname + "pre not set!");
TBOOST_REQUIRE_MESSAGE((o.count("transaction") > 0), testname + "transaction not set!");
BOOST_REQUIRE_MESSAGE(o.count("env") > 0, testname + "env not set!");
BOOST_REQUIRE_MESSAGE(o.count("pre") > 0, testname + "pre not set!");
BOOST_REQUIRE_MESSAGE(o.count("transaction") > 0, testname + "transaction not set!");
ImportTest importer(o, _fillin);
const State importedStatePost = importer.m_statePost;
@ -76,8 +76,8 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
}
else
{
TBOOST_REQUIRE((o.count("post") > 0));
TBOOST_REQUIRE((o.count("out") > 0));
BOOST_REQUIRE(o.count("post") > 0);
BOOST_REQUIRE(o.count("out") > 0);
// check output
checkOutput(output, o);
@ -89,7 +89,7 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
#if ETH_FATDB
ImportTest::compareStates(importer.m_statePost, importedStatePost);
#endif
TBOOST_CHECK_MESSAGE((importer.m_statePost.rootHash() == h256(o["postStateRoot"].get_str())), testname + "wrong post state root");
BOOST_CHECK_MESSAGE(importer.m_statePost.rootHash() == h256(o["postStateRoot"].get_str()), testname + "wrong post state root");
}
}
}

38
test/libethereum/transactionTests.cpp

@ -46,7 +46,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
cnote << testname;
if (_fillin)
{
TBOOST_REQUIRE((o.count("transaction") > 0));
BOOST_REQUIRE(o.count("transaction") > 0);
mObject tObj = o["transaction"].get_obj();
//Construct Rlp of the given transaction
@ -71,9 +71,9 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
{
bool expectInValid = (o["expect"].get_str() == "invalid");
if (Options::get().checkState)
{TBOOST_CHECK_MESSAGE(expectInValid, testname + "Check state: Transaction '" << i.first << "' is expected to be valid!");}
BOOST_CHECK_MESSAGE(expectInValid, testname + "Check state: Transaction '" << i.first << "' is expected to be valid!");
else
{TBOOST_WARN_MESSAGE(expectInValid, testname + "Check state: Transaction '" << i.first << "' is expected to be valid!");}
BOOST_WARN_MESSAGE(expectInValid, testname + "Check state: Transaction '" << i.first << "' is expected to be valid!");
o.erase(o.find("expect"));
}
@ -84,16 +84,16 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
{
bool expectValid = (o["expect"].get_str() == "valid");
if (Options::get().checkState)
{TBOOST_CHECK_MESSAGE(expectValid, testname + "Check state: Transaction '" << i.first << "' is expected to be invalid!");}
BOOST_CHECK_MESSAGE(expectValid, testname + "Check state: Transaction '" << i.first << "' is expected to be invalid!");
else
{TBOOST_WARN_MESSAGE(expectValid, testname + "Check state: Transaction '" << i.first << "' is expected to be invalid!");}
BOOST_WARN_MESSAGE(expectValid, testname + "Check state: Transaction '" << i.first << "' is expected to be invalid!");
o.erase(o.find("expect"));
}
}
else
{
TBOOST_REQUIRE((o.count("rlp") > 0));
BOOST_REQUIRE(o.count("rlp") > 0);
Transaction txFromRlp;
try
{
@ -107,33 +107,33 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
{
cnote << i.first;
cnote << "Transaction Exception: " << diagnostic_information(_e);
TBOOST_CHECK_MESSAGE((o.count("transaction") == 0), testname + "A transaction object should not be defined because the RLP is invalid!");
BOOST_CHECK_MESSAGE(o.count("transaction") == 0, testname + "A transaction object should not be defined because the RLP is invalid!");
continue;
}
catch(...)
{
TBOOST_CHECK_MESSAGE((o.count("transaction") == 0), testname + "A transaction object should not be defined because the RLP is invalid!");
BOOST_CHECK_MESSAGE(o.count("transaction") == 0, testname + "A transaction object should not be defined because the RLP is invalid!");
continue;
}
TBOOST_REQUIRE_MESSAGE((o.count("transaction") > 0), testname + "Expected a valid transaction!");
BOOST_REQUIRE_MESSAGE(o.count("transaction") > 0, testname + "Expected a valid transaction!");
mObject tObj = o["transaction"].get_obj();
Transaction txFromFields(createRLPStreamFromTransactionFields(tObj).out(), CheckTransaction::Everything);
//Check the fields restored from RLP to original fields
TBOOST_CHECK_MESSAGE((txFromFields.data() == txFromRlp.data()), testname + "Data in given RLP not matching the Transaction data!");
TBOOST_CHECK_MESSAGE((txFromFields.value() == txFromRlp.value()), testname + "Value in given RLP not matching the Transaction value!");
TBOOST_CHECK_MESSAGE((txFromFields.gasPrice() == txFromRlp.gasPrice()), testname + "GasPrice in given RLP not matching the Transaction gasPrice!");
TBOOST_CHECK_MESSAGE((txFromFields.gas() == txFromRlp.gas()), testname + "Gas in given RLP not matching the Transaction gas!");
TBOOST_CHECK_MESSAGE((txFromFields.nonce() == txFromRlp.nonce()), testname + "Nonce in given RLP not matching the Transaction nonce!");
TBOOST_CHECK_MESSAGE((txFromFields.receiveAddress() == txFromRlp.receiveAddress()), testname + "Receive address in given RLP not matching the Transaction 'to' address!");
TBOOST_CHECK_MESSAGE((txFromFields.sender() == txFromRlp.sender()), testname + "Transaction sender address in given RLP not matching the Transaction 'vrs' signature!");
TBOOST_CHECK_MESSAGE((txFromFields == txFromRlp), testname + "However, txFromFields != txFromRlp!");
TBOOST_REQUIRE ((o.count("sender") > 0));
BOOST_CHECK_MESSAGE(txFromFields.data() == txFromRlp.data(), testname + "Data in given RLP not matching the Transaction data!");
BOOST_CHECK_MESSAGE(txFromFields.value() == txFromRlp.value(), testname + "Value in given RLP not matching the Transaction value!");
BOOST_CHECK_MESSAGE(txFromFields.gasPrice() == txFromRlp.gasPrice(), testname + "GasPrice in given RLP not matching the Transaction gasPrice!");
BOOST_CHECK_MESSAGE(txFromFields.gas() == txFromRlp.gas(), testname + "Gas in given RLP not matching the Transaction gas!");
BOOST_CHECK_MESSAGE(txFromFields.nonce() == txFromRlp.nonce(), testname + "Nonce in given RLP not matching the Transaction nonce!");
BOOST_CHECK_MESSAGE(txFromFields.receiveAddress() == txFromRlp.receiveAddress(), testname + "Receive address in given RLP not matching the Transaction 'to' address!");
BOOST_CHECK_MESSAGE(txFromFields.sender() == txFromRlp.sender(), testname + "Transaction sender address in given RLP not matching the Transaction 'vrs' signature!");
BOOST_CHECK_MESSAGE(txFromFields == txFromRlp, testname + "However, txFromFields != txFromRlp!");
BOOST_REQUIRE (o.count("sender") > 0);
Address addressReaded = Address(o["sender"].get_str());
TBOOST_CHECK_MESSAGE((txFromFields.sender() == addressReaded || txFromRlp.sender() == addressReaded), testname + "Signature address of sender does not match given sender address!");
BOOST_CHECK_MESSAGE(txFromFields.sender() == addressReaded || txFromRlp.sender() == addressReaded, testname + "Signature address of sender does not match given sender address!");
}
}//for
}//doTransactionTests

30
test/libevm/vm.cpp

@ -309,9 +309,9 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
cnote << i.first;
testname = "(" + i.first + ") ";
TBOOST_REQUIRE_MESSAGE((o.count("env") > 0), testname + "env not set!");
TBOOST_REQUIRE_MESSAGE((o.count("pre") > 0), testname + "pre not set!");
TBOOST_REQUIRE_MESSAGE((o.count("exec") > 0), testname + "exec not set!");
BOOST_REQUIRE_MESSAGE(o.count("env") > 0, testname + "env not set!");
BOOST_REQUIRE_MESSAGE(o.count("pre") > 0, testname + "pre not set!");
BOOST_REQUIRE_MESSAGE(o.count("exec") > 0, testname + "exec not set!");
FakeExtVM fev(eth::EnvInfo{});
fev.importEnv(o["env"].get_obj());
@ -347,12 +347,12 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
catch (Exception const& _e)
{
cnote << "VM did throw an exception: " << diagnostic_information(_e);
TBOOST_ERROR("Failed VM Test with Exception: " << _e.what());
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
}
catch (std::exception const& _e)
{
cnote << "VM did throw an exception: " << _e.what();
TBOOST_ERROR("Failed VM Test with Exception: " << _e.what());
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
}
// delete null entries in storage for the sake of comparison
@ -398,9 +398,9 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
{
std::string warning = "Check State: Error! Unexpected output: " + o["out"].get_str() + " Expected: " + o["expectOut"].get_str();
if (Options::get().checkState)
{TBOOST_CHECK_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning);}
BOOST_CHECK_MESSAGE(o["out"].get_str() == o["expectOut"].get_str(), warning);
else
TBOOST_WARN_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning);
BOOST_WARN_MESSAGE(o["out"].get_str() == o["expectOut"].get_str(), warning);
o.erase(o.find("expectOut"));
}
@ -413,13 +413,13 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
{
if (o.count("post") > 0) // No exceptions expected
{
TBOOST_CHECK(!vmExceptionOccured);
BOOST_CHECK(!vmExceptionOccured);
TBOOST_REQUIRE((o.count("post") > 0));
TBOOST_REQUIRE((o.count("callcreates") > 0));
TBOOST_REQUIRE((o.count("out") > 0));
TBOOST_REQUIRE((o.count("gas") > 0));
TBOOST_REQUIRE((o.count("logs") > 0));
BOOST_REQUIRE(o.count("post") > 0);
BOOST_REQUIRE(o.count("callcreates") > 0);
BOOST_REQUIRE(o.count("out") > 0);
BOOST_REQUIRE(o.count("gas") > 0);
BOOST_REQUIRE(o.count("logs") > 0);
dev::test::FakeExtVM test(eth::EnvInfo{});
test.importState(o["post"].get_obj());
@ -429,7 +429,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
checkOutput(output, o);
TBOOST_CHECK_EQUAL(toInt(o["gas"]), fev.gas);
BOOST_CHECK_EQUAL(toInt(o["gas"]), fev.gas);
State postState, expectState;
mObject mPostState = fev.exportState();
@ -444,7 +444,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
checkLog(fev.sub.logs, test.sub.logs);
}
else // Exception expected
TBOOST_CHECK(vmExceptionOccured);
BOOST_CHECK(vmExceptionOccured);
}
}
}

Loading…
Cancel
Save