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

Commit a58dae6

Browse files
author
winsvega
authored
Merge pull request #4114 from ethereum/bcRandom
random blockchain tests. Parse all files in bcRandom folder.
2 parents 0c12f9d + 578932c commit a58dae6

File tree

12 files changed

+77
-49
lines changed

12 files changed

+77
-49
lines changed

test/jsontests

Submodule jsontests updated 90 files

test/tools/jsontests/BlockChainTests.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,24 @@ void checkBlocks(TestBlock const& _blockFromFields, TestBlock const& _blockFromR
102102

103103
void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
104104
{
105-
if (!Options::get().fillchain) //fill blockchain through state tests
106-
TestOutputHelper::initTest(_v);
105+
TestOutputHelper::initTest(_v); //Count how many tests in the json object (read from .json file)
106+
doBlockchainTestNoLog(_v, _fillin); //Do the test / test generation
107+
TestOutputHelper::finishTest(); //Calculate the time of test execution and add it to the log
108+
}
109+
110+
void doBlockchainTestNoLog(json_spirit::mValue& _v, bool _fillin)
111+
{
107112
for (auto& i: _v.get_obj())
108113
{
109114
string testname = i.first;
110115
json_spirit::mObject& o = i.second.get_obj();
111116

112-
if (!Options::get().fillchain)
113-
if (!TestOutputHelper::passTest(o, testname))
117+
//Select test by name if --singletest is set and not filling state tests as blockchain
118+
if (!TestOutputHelper::passTest(testname) && !Options::get().fillchain)
119+
{
120+
o.clear(); //don't add irrelevant tests to the final file when filling
114121
continue;
122+
}
115123

116124
BOOST_REQUIRE(o.count("genesisBlockHeader"));
117125
BOOST_REQUIRE(o.count("pre"));
@@ -407,7 +415,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
407415
ImportTest::compareStates(postState, blockchain.topBlock().state());
408416
}
409417
}//for tests
410-
TestOutputHelper::finishTest();
411418
}
412419

413420
//TestFunction

test/tools/jsontests/BlockChainTestsBoost.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* BlockChain boost test cases.
2121
*/
2222

23-
#include <boost/filesystem/operations.hpp>
2423
#include <boost/test/unit_test.hpp>
2524
#include <boost/filesystem.hpp>
2625
#include <test/tools/libtesteth/TestHelper.h>
@@ -173,4 +172,26 @@ BOOST_AUTO_TEST_CASE(userDefinedFile)
173172
dev::test::userDefinedTest(dev::test::doBlockchainTests);
174173
}
175174
BOOST_AUTO_TEST_SUITE_END()
175+
176+
//BlockChainTests
177+
BOOST_AUTO_TEST_SUITE(BlockChainTestsRandom)
178+
179+
BOOST_AUTO_TEST_CASE(bcRandom)
180+
{
181+
std::string fillersPath = dev::test::getTestPath() + "/src/BlockchainTestsFiller/RandomTests";
182+
183+
std::vector<boost::filesystem::path> files = test::getJsonFiles(fillersPath);
184+
int fileCount = files.size();
185+
186+
//bcRandom tests are generated from random state tests and have 1 test case * 5 forks in each file
187+
dev::test::TestOutputHelper::initTest(fileCount * 5);
188+
189+
for (auto const& file: files)
190+
dev::test::executeTests(file.filename().string(), "/BlockchainTests/RandomTests", "/BlockchainTestsFiller/RandomTests", dev::test::doBlockchainTestNoLog);
191+
192+
//calculate the total time on bcRandom test cases
193+
dev::test::TestOutputHelper::finishTest();
194+
}
195+
BOOST_AUTO_TEST_SUITE_END()
196+
176197
BOOST_AUTO_TEST_SUITE_END()

test/tools/jsontests/StateTests.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ void doStateTests(json_spirit::mValue& _v, bool _fillin)
4646
string testname = i.first;
4747
json_spirit::mObject& o = i.second.get_obj();
4848

49-
if (!TestOutputHelper::passTest(o, testname))
49+
if (!TestOutputHelper::passTest(testname))
5050
continue;
5151

52-
//For 100% at the log output
52+
//For 100% at the log output when making blockchain tests out of state tests
5353
if (_fillin == false && Options::get().fillchain)
5454
continue;
5555

@@ -115,25 +115,19 @@ class generaltestfixture
115115

116116
void fillAllFilesInFolder(string _folder)
117117
{
118-
std::string fillersPath = dev::test::getTestPath() + "/src/GeneralStateTestsFiller/" + _folder;
119-
120-
boost::filesystem::directory_iterator iterator_tmp(fillersPath);
121-
int fileCount = 0;
122-
for(; iterator_tmp != boost::filesystem::directory_iterator(); ++iterator_tmp)
123-
if (boost::filesystem::is_regular_file(iterator_tmp->path()) && iterator_tmp->path().extension() == ".json")
124-
fileCount++;
125-
if (dev::test::Options::get().filltests)
118+
std::string fillersPath = test::getTestPath() + "/src/GeneralStateTestsFiller/" + _folder;
119+
120+
std::vector<boost::filesystem::path> files = test::getJsonFiles(fillersPath);
121+
int fileCount = files.size();
122+
123+
if (test::Options::get().filltests)
126124
fileCount *= 2; //tests are checked when filled and after they been filled
127-
dev::test::TestOutputHelper::initTest(fileCount);
125+
test::TestOutputHelper::initTest(fileCount);
128126

129-
boost::filesystem::directory_iterator iterator(fillersPath);
130-
for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
131-
if (boost::filesystem::is_regular_file(iterator->path()) && iterator->path().extension() == ".json")
132-
{
133-
string fileboost = iterator->path().filename().string();
134-
dev::test::executeTests(fileboost, "/GeneralStateTests/"+_folder, "/GeneralStateTestsFiller/"+_folder, dev::test::doStateTests);
135-
}
136-
dev::test::TestOutputHelper::finishTest();
127+
for (auto const& file: files)
128+
test::executeTests(file.filename().string(), "/GeneralStateTests/"+_folder, "/GeneralStateTestsFiller/"+_folder, dev::test::doStateTests);
129+
130+
test::TestOutputHelper::finishTest();
137131
}
138132
};
139133

test/tools/jsontests/TransactionTests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
4343
string testname = i.first;
4444
json_spirit::mObject& o = i.second.get_obj();
4545

46-
if (!TestOutputHelper::passTest(o, testname))
46+
if (!TestOutputHelper::passTest(testname))
47+
{
48+
o.clear(); //don't add irrelevant tests to the final file when filling
4749
continue;
50+
}
4851

4952
BOOST_REQUIRE(o.count("blocknumber") > 0);
5053
u256 transactionBlock = toInt(o["blocknumber"].get_str());

test/tools/jsontests/vm.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ void doVMTests(json_spirit::mValue& _v, bool _fillin)
301301
string testname = i.first;
302302
json_spirit::mObject& o = i.second.get_obj();
303303

304-
if (!TestOutputHelper::passTest(o, testname))
304+
if (!TestOutputHelper::passTest(testname))
305+
{
306+
o.clear(); //don't add irrelevant tests to the final file when filling
305307
continue;
308+
}
306309

307310
BOOST_REQUIRE_MESSAGE(o.count("env") > 0, testname + "env not set!");
308311
BOOST_REQUIRE_MESSAGE(o.count("pre") > 0, testname + "pre not set!");
@@ -529,11 +532,7 @@ BOOST_AUTO_TEST_CASE(vmRandom)
529532
string testPath = getTestPath();
530533
testPath += "/VMTests/RandomTests";
531534

532-
vector<boost::filesystem::path> testFiles;
533-
boost::filesystem::directory_iterator iterator(testPath);
534-
for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
535-
if (boost::filesystem::is_regular_file(iterator->path()) && iterator->path().extension() == ".json")
536-
testFiles.push_back(iterator->path());
535+
std::vector<boost::filesystem::path> testFiles = test::getJsonFiles(testPath);
537536

538537
test::TestOutputHelper::initTest();
539538
test::TestOutputHelper::setMaxTests(testFiles.size());

test/tools/libtesteth/TestHelper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ void replaceLLLinState(json_spirit::mObject& _o)
198198
}
199199
}
200200

201+
std::vector<boost::filesystem::path> getJsonFiles(std::string const& _dirPath)
202+
{
203+
vector<boost::filesystem::path> jsonFiles;
204+
using Bdit = boost::filesystem::directory_iterator;
205+
for (Bdit it(_dirPath); it != Bdit(); ++it)
206+
if (boost::filesystem::is_regular_file(it->path()) && it->path().extension() == ".json")
207+
jsonFiles.push_back(it->path());
208+
return jsonFiles;
209+
}
210+
201211
string compileLLL(string const& _code)
202212
{
203213
if (_code == "")

test/tools/libtesteth/TestHelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class ZeroGasPricer: public eth::GasPricer
121121
};
122122

123123
// helping functions
124+
std::vector<boost::filesystem::path> getJsonFiles(std::string const& _dirPath);
124125
std::string netIdToString(eth::Network _netId);
125126
eth::Network stringToNetId(std::string const& _netname);
126127
u256 toInt(json_spirit::mValue const& _v);
@@ -166,6 +167,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin);
166167
void doStateTests(json_spirit::mValue& v, bool _fillin);
167168
void doVMTests(json_spirit::mValue& v, bool _fillin);
168169
void doBlockchainTests(json_spirit::mValue& _v, bool _fillin);
170+
void doBlockchainTestNoLog(json_spirit::mValue& _v, bool _fillin);
169171
void doRlpTests(json_spirit::mValue& v, bool _fillin);
170172

171173

test/tools/libtesteth/TestOutputHelper.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void TestOutputHelper::initTest(json_spirit::mValue& _v)
6161
m_currTest = 0;
6262
}
6363

64-
bool TestOutputHelper::passTest(json_spirit::mObject& _o, std::string& _testName)
64+
bool TestOutputHelper::passTest(std::string const& _testName)
6565
{
6666
m_currTest++;
6767
int m_testsPerProgs = std::max(1, (int)(m_maxTests / 4));
@@ -75,14 +75,9 @@ bool TestOutputHelper::passTest(json_spirit::mObject& _o, std::string& _testName
7575
}
7676

7777
if (test::Options::get().singleTest && test::Options::get().singleTestName != _testName)
78-
{
79-
_o.clear();
8078
return false;
81-
}
8279

8380
cnote << _testName;
84-
//Test name for old State Tests
85-
//_testName = (m_currentTestFileName == "n/a") ? "(" + _testName + ") " : "(" + m_currentTestFileName + "/" + _testName + ") ";
8681
m_currentTestName = _testName;
8782
return true;
8883
}

test/tools/libtesteth/TestOutputHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestOutputHelper
3333
TestOutputHelper() { TestOutputHelper::initTest(); }
3434
static void initTest(int _maxTests = 1);
3535
static void initTest(json_spirit::mValue& _v);
36-
static bool passTest(json_spirit::mObject& _o, std::string& _testName);
36+
static bool passTest(std::string const& _testName);
3737
static void setMaxTests(int _count) { m_maxTests = _count; }
3838
static void setCurrentTestFileName(std::string _name) { m_currentTestFileName = _name; }
3939
static std::string const& testName() { return m_currentTestName; }

0 commit comments

Comments
 (0)