Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Separate input and output in doTest functions #4341

Merged
merged 1 commit into from Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions test/tools/jsontests/BlockChainTests.cpp
Expand Up @@ -106,16 +106,18 @@ void fillBCTest(json_spirit::mObject& _o);
void testBCTest(json_spirit::mObject& _o);

//percent output for many tests in one file
void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
json_spirit::mValue doBlockchainTests(json_spirit::mValue const& _v, bool _fillin)
{
TestOutputHelper::initTest(_v); //Count how many tests in the json object (read from .json file)
doBlockchainTestNoLog(_v, _fillin); //Do the test / test generation
json_spirit::mValue ret = doBlockchainTestNoLog(_v, _fillin); //Do the test / test generation
TestOutputHelper::finishTest(); //Calculate the time of test execution and add it to the log
return ret;
}

void doTransitionTest(json_spirit::mValue& _v, bool _fillin)
json_spirit::mValue doTransitionTest(json_spirit::mValue const& _input, bool _fillin)
{
for (auto& i: _v.get_obj())
json_spirit::mValue output = _input;
for (auto& i: output.get_obj())
{
string testname = i.first;
json_spirit::mObject& o = i.second.get_obj();
Expand All @@ -139,15 +141,17 @@ void doTransitionTest(json_spirit::mValue& _v, bool _fillin)
else
testBCTest(o);
}
return output;
}

void doBlockchainTestNoLog(json_spirit::mValue& _v, bool _fillin)
json_spirit::mValue doBlockchainTestNoLog(json_spirit::mValue const& _input, bool _fillin)
{
json_spirit::mValue v = _input; // TODO: avoid copying and add only valid fields to the new object.
map<string, json_spirit::mObject> tests;
vector<decltype(_v.get_obj().begin())> erase_list;
vector<decltype(v.get_obj().begin())> erase_list;

// range-for is not used because iterators are necessary for removing elements later.
for (auto i = _v.get_obj().begin(); i != _v.get_obj().end(); i++)
for (auto i = v.get_obj().begin(); i != v.get_obj().end(); i++)
{
string testname = i->first;
json_spirit::mObject& o = i->second.get_obj();
Expand Down Expand Up @@ -227,16 +231,17 @@ void doBlockchainTestNoLog(json_spirit::mValue& _v, bool _fillin)

//Delete source test from the json
for (auto i: erase_list)
_v.get_obj().erase(i);
v.get_obj().erase(i);

//Add generated tests to the result file
if (_fillin)
{
BOOST_CHECK_MESSAGE(_v.get_obj().size() == 0, " Test Filler is incorrect. Still having the test source when generating from filler " + TestOutputHelper::testName());
json_spirit::mObject& obj = _v.get_obj();
BOOST_CHECK_MESSAGE(v.get_obj().size() == 0, " Test Filler is incorrect. Still having the test source when generating from filler " + TestOutputHelper::testName());
json_spirit::mObject& obj = v.get_obj();
for (auto& test : tests)
obj[test.first] = test.second;
}
return v;
}

void fillBCTest(json_spirit::mObject& _o)
Expand Down
8 changes: 5 additions & 3 deletions test/tools/jsontests/StateTests.cpp
Expand Up @@ -39,12 +39,13 @@ using namespace dev::eth;

namespace dev { namespace test {

void doStateTests(json_spirit::mValue& _v, bool _fillin)
json_spirit::mValue doStateTests(json_spirit::mValue const& _input, bool _fillin)
{
BOOST_REQUIRE_MESSAGE(!_fillin || _v.get_obj().size() == 1,
BOOST_REQUIRE_MESSAGE(!_fillin || _input.get_obj().size() == 1,
TestOutputHelper::testFileName() + " A GeneralStateTest filler should contain only one test.");
json_spirit::mValue v = _input; // TODO: avoid copying and only add valid fields into the new object.

for (auto& i: _v.get_obj())
for (auto& i: v.get_obj())
{
string testname = i.first;
json_spirit::mObject& o = i.second.get_obj();
Expand Down Expand Up @@ -103,6 +104,7 @@ void doStateTests(json_spirit::mValue& _v, bool _fillin)
importer.traceStateDiff();
}
}
return v;
}
} }// Namespace Close

Expand Down
8 changes: 5 additions & 3 deletions test/tools/jsontests/TransactionTests.cpp
Expand Up @@ -34,11 +34,12 @@ using namespace dev::eth;

namespace dev { namespace test {

void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
json_spirit::mValue doTransactionTests(json_spirit::mValue const& _input, bool _fillin)
{
TestOutputHelper::initTest(_v);
json_spirit::mValue v = _input; // TODO: avoid copying and only add valid fields into the new object.
TestOutputHelper::initTest(v);
unique_ptr<SealEngineFace> se(ChainParams(genesisInfo(eth::Network::MainNetworkTest)).createSealEngine());
for (auto& i: _v.get_obj())
for (auto& i: v.get_obj())
{
string testname = i.first;
json_spirit::mObject& o = i.second.get_obj();
Expand Down Expand Up @@ -159,6 +160,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
}
}//for
dev::test::TestOutputHelper::finishTest();
return v;
}//doTransactionTests

} }// Namespace Close
Expand Down
8 changes: 5 additions & 3 deletions test/tools/jsontests/vm.cpp
Expand Up @@ -292,12 +292,13 @@ eth::OnOpFunc FakeExtVM::simpleTrace() const

namespace dev { namespace test {

void doVMTests(json_spirit::mValue& _v, bool _fillin)
json_spirit::mValue doVMTests(json_spirit::mValue const& _input, bool _fillin)
{
json_spirit::mValue v = _input; // TODO: avoid copying and only add valid fields into the new object.
if (string(boost::unit_test::framework::current_test_case().p_name) != "vmRandom")
TestOutputHelper::initTest(_v);
TestOutputHelper::initTest(v);

for (auto& i: _v.get_obj())
for (auto& i: v.get_obj())
{
string testname = i.first;
json_spirit::mObject& o = i.second.get_obj();
Expand Down Expand Up @@ -470,6 +471,7 @@ void doVMTests(json_spirit::mValue& _v, bool _fillin)
}

TestOutputHelper::finishTest();
return v;
}

} } // namespace close
Expand Down
10 changes: 5 additions & 5 deletions test/tools/libtesteth/TestHelper.cpp
Expand Up @@ -421,7 +421,7 @@ void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _e
}
}

void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests)
void userDefinedTest(std::function<json_spirit::mValue(json_spirit::mValue const&, bool)> doTests)
{
if (!Options::get().singleTest)
return;
Expand Down Expand Up @@ -469,7 +469,7 @@ void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests)
}
}

void executeTests(const string& _name, const string& _testPathAppendix, const string& _fillerPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests, bool _addFillerSuffix)
void executeTests(const string& _name, const string& _testPathAppendix, const string& _fillerPathAppendix, std::function<json_spirit::mValue(json_spirit::mValue const&, bool)> doTests, bool _addFillerSuffix)
{
string testPath = getTestPath() + _testPathAppendix;
string testFillerPath = getTestPath() + "/src" + _fillerPathAppendix;
Expand Down Expand Up @@ -500,9 +500,9 @@ void executeTests(const string& _name, const string& _testPathAppendix, const st

json_spirit::read_string(s, v);
removeComments(v);
doTests(v, true);
addClientInfo(v, testfilename);
writeFile(testPath + "/" + name + ".json", asBytes(json_spirit::write_string(v, true)));
json_spirit::mValue output = doTests(v, true);
addClientInfo(output, testfilename);
writeFile(testPath + "/" + name + ".json", asBytes(json_spirit::write_string(output, true)));
}
catch (Exception const& _e)
{
Expand Down
18 changes: 10 additions & 8 deletions test/tools/libtesteth/TestHelper.h
Expand Up @@ -157,8 +157,8 @@ dev::eth::BlockHeader constructHeader(
u256 const& _timestamp,
bytes const& _extraData);
void updateEthashSeal(dev::eth::BlockHeader& _header, h256 const& _mixHash, dev::eth::Nonce const& _nonce);
void executeTests(const std::string& _name, const std::string& _testPathAppendix, const std::string& _fillerPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests, bool _addFillerSuffix = true);
void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests);
void executeTests(const std::string& _name, const std::string& _testPathAppendix, const std::string& _fillerPathAppendix, std::function<json_spirit::mValue(json_spirit::mValue const&, bool)> doTests, bool _addFillerSuffix = true);
void userDefinedTest(std::function<json_spirit::mValue(json_spirit::mValue const&, bool)> doTests);
RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject const& _tObj);
json_spirit::mObject fillJsonWithStateChange(eth::State const& _stateOrig, eth::State const& _statePost, eth::ChangeLog const& _changeLog);
json_spirit::mObject fillJsonWithState(eth::State const& _state);
Expand All @@ -167,12 +167,14 @@ json_spirit::mObject fillJsonWithTransaction(eth::Transaction const& _txn);

//Fill Test Functions
int createRandomTest(std::vector<char*> const& _parameters);
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 doBlockchainTestNoLog(json_spirit::mValue& _v, bool _fillin);
void doTransitionTest(json_spirit::mValue& _v, bool _fillin);
//do*Tests(_input, _fillin) always return a filled test.
//When _fillin is true, _input is supposed to contain a filler. Otherwise, _input is also a filled test.
json_spirit::mValue doTransactionTests(json_spirit::mValue const& _input, bool _fillin);
json_spirit::mValue doStateTests(json_spirit::mValue const& _input, bool _fillin);
json_spirit::mValue doVMTests(json_spirit::mValue const& _input, bool _fillin);
json_spirit::mValue doBlockchainTests(json_spirit::mValue const& _input, bool _fillin);
json_spirit::mValue doBlockchainTestNoLog(json_spirit::mValue const& _input, bool _fillin);
json_spirit::mValue doTransitionTest(json_spirit::mValue const& _input, bool _fillin);
void doRlpTests(json_spirit::mValue& v, bool _fillin);
void addClientInfo(json_spirit::mValue& v, std::string const& _testSource);
void removeComments(json_spirit::mValue& _obj);
Expand Down
2 changes: 1 addition & 1 deletion test/tools/libtesteth/TestOutputHelper.cpp
Expand Up @@ -49,7 +49,7 @@ void TestOutputHelper::initTest(int _maxTests)
m_currTest = 0;
}

void TestOutputHelper::initTest(json_spirit::mValue& _v)
void TestOutputHelper::initTest(json_spirit::mValue const& _v)
{
Ethash::init();
BasicAuthority::init();
Expand Down
2 changes: 1 addition & 1 deletion test/tools/libtesteth/TestOutputHelper.h
Expand Up @@ -32,7 +32,7 @@ class TestOutputHelper
public:
TestOutputHelper() { TestOutputHelper::initTest(); }
static void initTest(int _maxTests = 1);
static void initTest(json_spirit::mValue& _v);
static void initTest(json_spirit::mValue const& _v);
static bool passTest(std::string const& _testName);
static void setMaxTests(int _count) { m_maxTests = _count; }
static void setCurrentTestFileName(std::string const& _name) { m_currentTestFileName = _name; }
Expand Down