Browse Source

Merge pull request #2239 from winsvega/fuzz

fuzzTests improvements
cl-refactor
Gav Wood 10 years ago
parent
commit
167e2edde3
  1. 55
      test/TestHelper.cpp
  2. 4
      test/TestHelper.h
  3. 67
      test/fuzzTesting/createRandomTest.cpp
  4. 2
      test/libethereum/state.cpp
  5. 4
      test/libethereum/transaction.cpp
  6. 6
      test/libevm/vm.cpp

55
test/TestHelper.cpp

@ -178,7 +178,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio
{ {
stateOptions.m_bHasBalance = true; stateOptions.m_bHasBalance = true;
if (bigint(o["balance"].get_str()) >= c_max256plus1) if (bigint(o["balance"].get_str()) >= c_max256plus1)
TBOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'balance' is equal or greater than 2**256") ); BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'balance' is equal or greater than 2**256") );
balance = toInt(o["balance"]); balance = toInt(o["balance"]);
} }
@ -186,7 +186,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio
{ {
stateOptions.m_bHasNonce = true; stateOptions.m_bHasNonce = true;
if (bigint(o["nonce"].get_str()) >= c_max256plus1) if (bigint(o["nonce"].get_str()) >= c_max256plus1)
TBOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'nonce' is equal or greater than 2**256") ); BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'nonce' is equal or greater than 2**256") );
nonce = toInt(o["nonce"]); nonce = toInt(o["nonce"]);
} }
@ -230,7 +230,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state)
{ {
//check that every parameter was declared in state object //check that every parameter was declared in state object
if (!stateOptionMap.second.isAllSet()) if (!stateOptionMap.second.isAllSet())
TBOOST_THROW_EXCEPTION(MissingFields() << errinfo_comment("Import State: Missing state fields!")); BOOST_THROW_EXCEPTION(MissingFields() << errinfo_comment("Import State: Missing state fields!"));
} }
} }
@ -246,13 +246,13 @@ void ImportTest::importTransaction(json_spirit::mObject& _o)
assert(_o.count("data") > 0); assert(_o.count("data") > 0);
if (bigint(_o["nonce"].get_str()) >= c_max256plus1) if (bigint(_o["nonce"].get_str()) >= c_max256plus1)
TBOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'nonce' is equal or greater than 2**256") ); BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'nonce' is equal or greater than 2**256") );
if (bigint(_o["gasPrice"].get_str()) >= c_max256plus1) if (bigint(_o["gasPrice"].get_str()) >= c_max256plus1)
TBOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasPrice' is equal or greater than 2**256") ); BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasPrice' is equal or greater than 2**256") );
if (bigint(_o["gasLimit"].get_str()) >= c_max256plus1) if (bigint(_o["gasLimit"].get_str()) >= c_max256plus1)
TBOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasLimit' is equal or greater than 2**256") ); BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasLimit' is equal or greater than 2**256") );
if (bigint(_o["value"].get_str()) >= c_max256plus1) if (bigint(_o["value"].get_str()) >= c_max256plus1)
TBOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'value' is equal or greater than 2**256") ); BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'value' is equal or greater than 2**256") );
m_transaction = _o["to"].get_str().empty() ? m_transaction = _o["to"].get_str().empty() ?
Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())) : Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())) :
@ -349,9 +349,9 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost)
{ {
std::string warning = "Check State: Error! Unexpected output: " + m_TestObject["out"].get_str() + " Expected: " + m_TestObject["expectOut"].get_str(); std::string warning = "Check State: Error! Unexpected output: " + m_TestObject["out"].get_str() + " Expected: " + m_TestObject["expectOut"].get_str();
if (Options::get().checkState) if (Options::get().checkState)
BOOST_CHECK_MESSAGE((m_TestObject["out"].get_str() == m_TestObject["expectOut"].get_str()), warning); {TBOOST_CHECK_MESSAGE((m_TestObject["out"].get_str() == m_TestObject["expectOut"].get_str()), warning);}
else else
BOOST_WARN_MESSAGE((m_TestObject["out"].get_str() == m_TestObject["expectOut"].get_str()), warning); TBOOST_WARN_MESSAGE((m_TestObject["out"].get_str() == m_TestObject["expectOut"].get_str()), warning);
m_TestObject.erase(m_TestObject.find("expectOut")); m_TestObject.erase(m_TestObject.find("expectOut"));
} }
@ -533,24 +533,25 @@ void checkOutput(bytes const& _output, json_spirit::mObject& _o)
void checkStorage(map<u256, u256> _expectedStore, map<u256, u256> _resultStore, Address _expectedAddr) void checkStorage(map<u256, u256> _expectedStore, map<u256, u256> _resultStore, Address _expectedAddr)
{ {
_expectedAddr = _expectedAddr; //unsed parametr when macro
for (auto&& expectedStorePair : _expectedStore) for (auto&& expectedStorePair : _expectedStore)
{ {
auto& expectedStoreKey = expectedStorePair.first; auto& expectedStoreKey = expectedStorePair.first;
auto resultStoreIt = _resultStore.find(expectedStoreKey); auto resultStoreIt = _resultStore.find(expectedStoreKey);
if (resultStoreIt == _resultStore.end()) if (resultStoreIt == _resultStore.end())
BOOST_ERROR(_expectedAddr << ": missing store key " << expectedStoreKey); {TBOOST_ERROR(_expectedAddr << ": missing store key " << expectedStoreKey);}
else else
{ {
auto& expectedStoreValue = expectedStorePair.second; auto& expectedStoreValue = expectedStorePair.second;
auto& resultStoreValue = resultStoreIt->second; auto& resultStoreValue = resultStoreIt->second;
BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue); TBOOST_CHECK_MESSAGE((expectedStoreValue == resultStoreValue), _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue);
} }
} }
BOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size()); TBOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size());
for (auto&& resultStorePair: _resultStore) for (auto&& resultStorePair: _resultStore)
{ {
if (!_expectedStore.count(resultStorePair.first)) if (!_expectedStore.count(resultStorePair.first))
BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first); TBOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first);
} }
} }
@ -568,14 +569,14 @@ void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs)
void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates) void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates)
{ {
BOOST_REQUIRE_EQUAL(_resultCallCreates.size(), _expectedCallCreates.size()); TBOOST_REQUIRE_EQUAL(_resultCallCreates.size(), _expectedCallCreates.size());
for (size_t i = 0; i < _resultCallCreates.size(); ++i) for (size_t i = 0; i < _resultCallCreates.size(); ++i)
{ {
BOOST_CHECK(_resultCallCreates[i].data() == _expectedCallCreates[i].data()); TBOOST_CHECK((_resultCallCreates[i].data() == _expectedCallCreates[i].data()));
BOOST_CHECK(_resultCallCreates[i].receiveAddress() == _expectedCallCreates[i].receiveAddress()); TBOOST_CHECK((_resultCallCreates[i].receiveAddress() == _expectedCallCreates[i].receiveAddress()));
BOOST_CHECK(_resultCallCreates[i].gas() == _expectedCallCreates[i].gas()); TBOOST_CHECK((_resultCallCreates[i].gas() == _expectedCallCreates[i].gas()));
BOOST_CHECK(_resultCallCreates[i].value() == _expectedCallCreates[i].value()); TBOOST_CHECK((_resultCallCreates[i].value() == _expectedCallCreates[i].value()));
} }
} }
@ -598,7 +599,7 @@ void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests)
cnote << "Testing user defined test: " << filename; cnote << "Testing user defined test: " << filename;
json_spirit::mValue v; json_spirit::mValue v;
string s = contentsString(filename); string s = contentsString(filename);
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. "); TBOOST_REQUIRE_MESSAGE((s.length() > 0), "Contents of " + filename + " is empty. ");
json_spirit::read_string(s, v); json_spirit::read_string(s, v);
json_spirit::mObject oSingleTest; json_spirit::mObject oSingleTest;
@ -616,11 +617,11 @@ void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests)
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {
BOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e)); TBOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e));
} }
catch (std::exception const& _e) catch (std::exception const& _e)
{ {
BOOST_ERROR("Failed Test with Exception: " << _e.what()); TBOOST_ERROR("Failed Test with Exception: " << _e.what());
} }
} }
@ -640,18 +641,18 @@ void executeTests(const string& _name, const string& _testPathAppendix, const bo
json_spirit::mValue v; json_spirit::mValue v;
boost::filesystem::path p(__FILE__); boost::filesystem::path p(__FILE__);
string s = asString(dev::contents(_pathToFiller.string() + "/" + _name + "Filler.json")); string s = asString(dev::contents(_pathToFiller.string() + "/" + _name + "Filler.json"));
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + _pathToFiller.string() + "/" + _name + "Filler.json is empty."); TBOOST_REQUIRE_MESSAGE((s.length() > 0), "Contents of " + _pathToFiller.string() + "/" + _name + "Filler.json is empty.");
json_spirit::read_string(s, v); json_spirit::read_string(s, v);
doTests(v, true); doTests(v, true);
writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true))); writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true)));
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {
BOOST_ERROR("Failed filling test with Exception: " << diagnostic_information(_e)); TBOOST_ERROR("Failed filling test with Exception: " << diagnostic_information(_e));
} }
catch (std::exception const& _e) catch (std::exception const& _e)
{ {
BOOST_ERROR("Failed filling test with Exception: " << _e.what()); TBOOST_ERROR("Failed filling test with Exception: " << _e.what());
} }
} }
@ -660,18 +661,18 @@ void executeTests(const string& _name, const string& _testPathAppendix, const bo
std::cout << "TEST " << _name << ":\n"; std::cout << "TEST " << _name << ":\n";
json_spirit::mValue v; json_spirit::mValue v;
string s = asString(dev::contents(testPath + "/" + _name + ".json")); string s = asString(dev::contents(testPath + "/" + _name + ".json"));
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?"); 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?");
json_spirit::read_string(s, v); json_spirit::read_string(s, v);
Listener::notifySuiteStarted(_name); Listener::notifySuiteStarted(_name);
doTests(v, false); doTests(v, false);
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {
BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e)); TBOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
} }
catch (std::exception const& _e) catch (std::exception const& _e)
{ {
BOOST_ERROR("Failed test with Exception: " << _e.what()); TBOOST_ERROR("Failed test with Exception: " << _e.what());
} }
} }

4
test/TestHelper.h

@ -32,21 +32,21 @@
#include <libtestutils/Common.h> #include <libtestutils/Common.h>
#ifdef NOBOOST #ifdef NOBOOST
#define TBOOST_THROW_EXCEPTION(arg) throw dev::Exception();
#define TBOOST_REQUIRE(arg) if(arg == false) throw dev::Exception(); #define TBOOST_REQUIRE(arg) if(arg == false) throw dev::Exception();
#define TBOOST_REQUIRE_EQUAL(arg1, arg2) if(arg1 != arg2) 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_EQUAL(arg1, arg2) if(arg1 != arg2) throw dev::Exception();
#define TBOOST_CHECK(arg) if(arg == false) 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_CHECK_MESSAGE(arg1, arg2) if(arg1 == false) throw dev::Exception();
#define TBOOST_WARN_MESSAGE(arg1, arg2) throw dev::Exception(); #define TBOOST_WARN_MESSAGE(arg1, arg2) throw dev::Exception();
#define TBOOST_ERROR(arg) throw dev::Exception(); #define TBOOST_ERROR(arg) throw dev::Exception();
#else #else
#define TBOOST_THROW_EXCEPTION(arg) BOOST_THROW_EXCEPTION(arg)
#define TBOOST_REQUIRE(arg) BOOST_REQUIRE(arg) #define TBOOST_REQUIRE(arg) BOOST_REQUIRE(arg)
#define TBOOST_REQUIRE_EQUAL(arg1, arg2) BOOST_REQUIRE_EQUAL(arg1, arg2) #define TBOOST_REQUIRE_EQUAL(arg1, arg2) BOOST_REQUIRE_EQUAL(arg1, arg2)
#define TBOOST_CHECK(arg) BOOST_CHECK(arg) #define TBOOST_CHECK(arg) BOOST_CHECK(arg)
#define TBOOST_CHECK_EQUAL(arg1, arg2) BOOST_CHECK_EQUAL(arg1, arg2) #define TBOOST_CHECK_EQUAL(arg1, arg2) BOOST_CHECK_EQUAL(arg1, arg2)
#define TBOOST_CHECK_MESSAGE(arg1, arg2) BOOST_CHECK_MESSAGE(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_WARN_MESSAGE(arg1, arg2) BOOST_WARN_MESSAGE(arg1, arg2)
#define TBOOST_ERROR(arg) BOOST_ERROR(arg) #define TBOOST_ERROR(arg) BOOST_ERROR(arg)
#endif #endif

67
test/fuzzTesting/createRandomTest.cpp

@ -36,8 +36,8 @@ extern std::string const c_testExampleVMTest;
extern std::string const c_testExampleBlockchainTest; extern std::string const c_testExampleBlockchainTest;
//Main Test functinos //Main Test functinos
void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std::string const& testString); void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, std::string const& _testString, bool _debug = false);
int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, json_spirit::mValue& value); int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, json_spirit::mValue& _value, bool _debug = false);
//Helper Functions //Helper Functions
std::vector<std::string> getTypes(); std::vector<std::string> getTypes();
@ -46,8 +46,12 @@ void parseTestWithTypes(std::string& test);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::string testSuite; std::string testSuite;
std::string testFillString;
json_spirit::mValue testmValue; json_spirit::mValue testmValue;
bool checktest = false; bool checktest = false;
bool filldebug = false;
bool debug = false;
bool filltest = false;
for (auto i = 0; i < argc; ++i) for (auto i = 0; i < argc; ++i)
{ {
auto arg = std::string{argv[i]}; auto arg = std::string{argv[i]};
@ -62,7 +66,7 @@ int main(int argc, char *argv[])
testSuite = ""; testSuite = "";
} }
else else
if (arg == "-checktest" && i + 1 < argc) if ((arg == "-checktest" || arg == "-filltest") && i + 1 < argc)
{ {
std::string s; std::string s;
for (int j = i+1; j < argc; ++j) for (int j = i+1; j < argc; ++j)
@ -72,10 +76,24 @@ int main(int argc, char *argv[])
std::cout << "Error! Content of argument is empty! (Usage -checktest textstream) \n"; std::cout << "Error! Content of argument is empty! (Usage -checktest textstream) \n";
return 1; return 1;
} }
if (arg == "-filltest")
{
testFillString = s;
filltest = true;
}
else
{
read_string(s, testmValue); read_string(s, testmValue);
checktest = true; checktest = true;
} }
} }
else
if (arg == "--debug")
debug = true;
else
if (arg == "--filldebug")
filldebug = true;
}
if (testSuite == "") if (testSuite == "")
{ {
@ -83,28 +101,32 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
else else
{
if (checktest)
std::cout << "Testing: " << testSuite.substr(0, testSuite.length() - 1) << std::endl;
if (testSuite == "BlockChainTests") if (testSuite == "BlockChainTests")
{ {
if (checktest) if (checktest)
return checkRandomTest(dev::test::doBlockchainTests, testmValue); return checkRandomTest(dev::test::doBlockchainTests, testmValue, debug);
else else
fillRandomTest(dev::test::doBlockchainTests, c_testExampleBlockchainTest); fillRandomTest(dev::test::doBlockchainTests, (filltest) ? testFillString : c_testExampleBlockchainTest, filldebug);
} }
else else
if (testSuite == "TransactionTests") if (testSuite == "TransactionTests")
{ {
if (checktest) if (checktest)
return checkRandomTest(dev::test::doTransactionTests, testmValue); return checkRandomTest(dev::test::doTransactionTests, testmValue, debug);
else else
fillRandomTest(dev::test::doTransactionTests, c_testExampleTransactionTest); fillRandomTest(dev::test::doTransactionTests, (filltest) ? testFillString : c_testExampleTransactionTest, filldebug);
} }
else else
if (testSuite == "StateTests") if (testSuite == "StateTests")
{ {
if (checktest) if (checktest)
return checkRandomTest(dev::test::doStateTests, testmValue); return checkRandomTest(dev::test::doStateTests, testmValue, debug);
else else
fillRandomTest(dev::test::doStateTests, c_testExampleStateTest); fillRandomTest(dev::test::doStateTests, (filltest) ? testFillString : c_testExampleStateTest, filldebug);
} }
else else
if (testSuite == "VMTests") if (testSuite == "VMTests")
@ -112,16 +134,17 @@ int main(int argc, char *argv[])
if (checktest) if (checktest)
{ {
dev::eth::VMFactory::setKind(dev::eth::VMKind::JIT); dev::eth::VMFactory::setKind(dev::eth::VMKind::JIT);
return checkRandomTest(dev::test::doVMTests, testmValue); return checkRandomTest(dev::test::doVMTests, testmValue, debug);
} }
else else
fillRandomTest(dev::test::doVMTests, c_testExampleVMTest); fillRandomTest(dev::test::doVMTests, (filltest) ? testFillString : c_testExampleVMTest, filldebug);
}
} }
return 0; return 0;
} }
int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, json_spirit::mValue& value) int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, json_spirit::mValue& _value, bool _debug)
{ {
bool ret = 0; bool ret = 0;
try try
@ -129,15 +152,21 @@ int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, jso
//redirect all output to the stream //redirect all output to the stream
std::ostringstream strCout; std::ostringstream strCout;
std::streambuf* oldCoutStreamBuf = std::cout.rdbuf(); std::streambuf* oldCoutStreamBuf = std::cout.rdbuf();
if (!_debug)
{
std::cout.rdbuf( strCout.rdbuf() ); std::cout.rdbuf( strCout.rdbuf() );
std::cerr.rdbuf( strCout.rdbuf() ); std::cerr.rdbuf( strCout.rdbuf() );
}
doTests(value, false); _doTests(_value, false);
//restroe output //restroe output
if (!_debug)
{
std::cout.rdbuf(oldCoutStreamBuf); std::cout.rdbuf(oldCoutStreamBuf);
std::cerr.rdbuf(oldCoutStreamBuf); std::cerr.rdbuf(oldCoutStreamBuf);
} }
}
catch (dev::Exception const& _e) catch (dev::Exception const& _e)
{ {
std::cout << "Failed test with Exception: " << diagnostic_information(_e) << std::endl; std::cout << "Failed test with Exception: " << diagnostic_information(_e) << std::endl;
@ -151,21 +180,24 @@ int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, jso
return ret; return ret;
} }
void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std::string const& testString) void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, std::string const& _testString, bool _debug)
{ {
//redirect all output to the stream //redirect all output to the stream
std::ostringstream strCout; std::ostringstream strCout;
std::streambuf* oldCoutStreamBuf = std::cout.rdbuf(); std::streambuf* oldCoutStreamBuf = std::cout.rdbuf();
if (!_debug)
{
std::cout.rdbuf( strCout.rdbuf() ); std::cout.rdbuf( strCout.rdbuf() );
std::cerr.rdbuf( strCout.rdbuf() ); std::cerr.rdbuf( strCout.rdbuf() );
}
json_spirit::mValue v; json_spirit::mValue v;
try try
{ {
std::string newTest = testString; std::string newTest = _testString;
parseTestWithTypes(newTest); parseTestWithTypes(newTest);
json_spirit::read_string(newTest, v); json_spirit::read_string(newTest, v);
doTests(v, true); _doTests(v, true);
} }
catch(...) catch(...)
{ {
@ -173,8 +205,11 @@ void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std
} }
//restroe output //restroe output
if (!_debug)
{
std::cout.rdbuf(oldCoutStreamBuf); std::cout.rdbuf(oldCoutStreamBuf);
std::cerr.rdbuf(oldCoutStreamBuf); std::cerr.rdbuf(oldCoutStreamBuf);
}
std::cout << json_spirit::write_string(v, true); std::cout << json_spirit::write_string(v, true);
} }

2
test/libethereum/state.cpp

@ -80,7 +80,7 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
#if ETH_FATDB #if ETH_FATDB
importer.exportTest(output, theState); importer.exportTest(output, theState);
#else #else
TBOOST_THROW_EXCEPTION(Exception() << errinfo_comment("You can not fill tests when FATDB is switched off")); BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("You can not fill tests when FATDB is switched off"));
#endif #endif
} }
else else

4
test/libethereum/transaction.cpp

@ -50,7 +50,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
{ {
Transaction txFromFields(rlpStream.out(), CheckTransaction::Everything); Transaction txFromFields(rlpStream.out(), CheckTransaction::Everything);
if (!txFromFields.signature().isValid()) if (!txFromFields.signature().isValid())
TBOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") ); BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") );
o["sender"] = toString(txFromFields.sender()); o["sender"] = toString(txFromFields.sender());
o["transaction"] = ImportTest::makeAllFieldsHex(tObj); o["transaction"] = ImportTest::makeAllFieldsHex(tObj);
@ -94,7 +94,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
RLP rlp(stream); RLP rlp(stream);
txFromRlp = Transaction(rlp.data(), CheckTransaction::Everything); txFromRlp = Transaction(rlp.data(), CheckTransaction::Everything);
if (!txFromRlp.signature().isValid()) if (!txFromRlp.signature().isValid())
TBOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") ); BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") );
} }
catch(Exception const& _e) catch(Exception const& _e)
{ {

6
test/libevm/vm.cpp

@ -395,9 +395,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(); std::string warning = "Check State: Error! Unexpected output: " + o["out"].get_str() + " Expected: " + o["expectOut"].get_str();
if (Options::get().checkState) if (Options::get().checkState)
BOOST_CHECK_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning); {TBOOST_CHECK_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning);}
else else
BOOST_WARN_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning); TBOOST_WARN_MESSAGE((o["out"].get_str() == o["expectOut"].get_str()), warning);
o.erase(o.find("expectOut")); o.erase(o.find("expectOut"));
} }
@ -440,7 +440,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
checkLog(fev.sub.logs, test.sub.logs); checkLog(fev.sub.logs, test.sub.logs);
} }
else // Exception expected else // Exception expected
BOOST_CHECK(vmExceptionOccured); TBOOST_CHECK(vmExceptionOccured);
} }
} }
} }

Loading…
Cancel
Save