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

Commit 1373260

Browse files
author
Dimitry
committed
split BlockchainTests into Valid and Invalid
1 parent 1ef5785 commit 1373260

File tree

6 files changed

+104
-41
lines changed

6 files changed

+104
-41
lines changed

test/jsontests

Submodule jsontests updated 513 files

test/tools/jsontests/BlockChainTests.cpp

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ namespace test {
5959
eth::Network ChainBranch::s_tempBlockchainNetwork = eth::Network::MainNetwork;
6060
eth::Network TestBlockChain::s_sealEngineNetwork = eth::Network::FrontierTest;
6161

62-
json_spirit::mValue BlockchainTestSuite::doTests(json_spirit::mValue const& _input, bool _fillin) const
62+
json_spirit::mValue doBCTest(
63+
json_spirit::mValue const& _input, bool _fillin, bool _allowInvalidBlocks)
6364
{
6465
json_spirit::mObject tests;
6566
for (auto const& i : _input.get_obj())
@@ -122,7 +123,7 @@ json_spirit::mValue BlockchainTestSuite::doTests(json_spirit::mValue const& _inp
122123
std::cout << "Filling " << newtestname << std::endl;
123124

124125
TestOutputHelper::get().setCurrentTestName(newtestname);
125-
jObjOutput = fillBCTest(jObjOutput);
126+
jObjOutput = fillBCTest(jObjOutput, _allowInvalidBlocks);
126127
jObjOutput["network"] = test::netIdToString(network);
127128
if (inputTest.count("_info"))
128129
jObjOutput["_info"] = inputTest.at("_info");
@@ -161,13 +162,34 @@ json_spirit::mValue BlockchainTestSuite::doTests(json_spirit::mValue const& _inp
161162

162163
return tests;
163164
}
164-
fs::path BlockchainTestSuite::suiteFolder() const
165+
166+
json_spirit::mValue BlockchainValidTestSuite::doTests(
167+
json_spirit::mValue const& _input, bool _fillin) const
168+
{
169+
return doBCTest(_input, _fillin, false);
170+
}
171+
172+
json_spirit::mValue BlockchainInvalidTestSuite::doTests(
173+
json_spirit::mValue const& _input, bool _fillin) const
174+
{
175+
return doBCTest(_input, _fillin, true);
176+
}
177+
178+
fs::path BlockchainInvalidTestSuite::suiteFolder() const
165179
{
166-
return "BlockchainTests";
180+
return fs::path("BlockchainTests") / "InvalidBlocks";
167181
}
168-
fs::path BlockchainTestSuite::suiteFillerFolder() const
182+
fs::path BlockchainInvalidTestSuite::suiteFillerFolder() const
169183
{
170-
return "BlockchainTestsFiller";
184+
return fs::path("BlockchainTestsFiller") / "InvalidBlocks";
185+
}
186+
fs::path BlockchainValidTestSuite::suiteFolder() const
187+
{
188+
return fs::path("BlockchainTests") / "ValidBlocks";
189+
}
190+
fs::path BlockchainValidTestSuite::suiteFillerFolder() const
191+
{
192+
return fs::path("BlockchainTestsFiller") / "ValidBlocks";
171193
}
172194
fs::path BCGeneralStateTestsSuite::suiteFolder() const
173195
{
@@ -253,7 +275,7 @@ void ChainBranch::resetBlockchain()
253275
dev::test::TestBlockChain::s_sealEngineNetwork = s_tempBlockchainNetwork;
254276
}
255277

256-
json_spirit::mObject fillBCTest(json_spirit::mObject const& _input)
278+
json_spirit::mObject fillBCTest(json_spirit::mObject const& _input, bool _allowInvalidBlocks)
257279
{
258280
json_spirit::mObject output;
259281
string const& testName = TestOutputHelper::get().testName();
@@ -389,6 +411,7 @@ json_spirit::mObject fillBCTest(json_spirit::mObject const& _input)
389411
blObj["uncleHeaders"] = aUncleList;
390412
blObj["transactions"] = writeTransactionsToJson(alterBlock.transactionQueue());
391413

414+
bool blockImportExceptionHappen = false;
392415
compareBlocks(block, alterBlock);
393416
try
394417
{
@@ -416,19 +439,25 @@ json_spirit::mObject fillBCTest(json_spirit::mObject const& _input)
416439
cnote << testName + "block import throw an exception: " << diagnostic_information(_e);
417440
checkExpectedException(blObj, _e);
418441
eraseJsonSectionForInvalidBlock(blObj);
442+
blockImportExceptionHappen = true;
419443
}
420444
catch (std::exception const& _e)
421445
{
422446
cnote << testName + "block import throw an exception: " << _e.what();
423447
cout << testName + "block import thrown std exeption\n";
424448
eraseJsonSectionForInvalidBlock(blObj);
449+
blockImportExceptionHappen = true;
425450
}
426451
catch (...)
427452
{
428453
cout << testName + "block import thrown unknown exeption\n";
429454
eraseJsonSectionForInvalidBlock(blObj);
455+
blockImportExceptionHappen = true;
430456
}
431457

458+
if (!_allowInvalidBlocks && blockImportExceptionHappen)
459+
BOOST_ERROR("Mined block expected to be valid! " + testName);
460+
432461
blArray.push_back(blObj); //json data
433462
}//each blocks
434463

@@ -1003,11 +1032,12 @@ void checkBlocks(TestBlock const& _blockFromFields, TestBlock const& _blockFromR
10031032
}
10041033
}
10051034

1006-
class bcTestFixture {
1035+
class bcValidTestFixture
1036+
{
10071037
public:
1008-
bcTestFixture()
1038+
bcValidTestFixture()
10091039
{
1010-
test::BlockchainTestSuite suite;
1040+
test::BlockchainValidTestSuite suite;
10111041
string const casename = boost::unit_test::framework::current_test_case().p_name;
10121042
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
10131043

@@ -1024,6 +1054,20 @@ class bcTestFixture {
10241054
}
10251055
};
10261056

1057+
class bcInvalidTestFixture
1058+
{
1059+
public:
1060+
bcInvalidTestFixture()
1061+
{
1062+
test::BlockchainInvalidTestSuite suite;
1063+
string const casename = boost::unit_test::framework::current_test_case().p_name;
1064+
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
1065+
1066+
suite.runAllTestsInFolder(casename);
1067+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
1068+
}
1069+
};
1070+
10271071
class bcTransitionFixture {
10281072
public:
10291073
bcTransitionFixture()
@@ -1057,34 +1101,44 @@ class bcGeneralTestsFixture
10571101
}
10581102
};
10591103

1060-
BOOST_FIXTURE_TEST_SUITE(BlockchainTests, bcTestFixture)
1061-
1062-
BOOST_AUTO_TEST_CASE(bcStateTests){}
1063-
BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest){}
1064-
BOOST_AUTO_TEST_CASE(bcGasPricerTest){}
1065-
BOOST_AUTO_TEST_CASE(bcInvalidHeaderTest){}
1066-
BOOST_AUTO_TEST_CASE(bcUncleHeaderValidity){}
1067-
BOOST_AUTO_TEST_CASE(bcUncleTest){}
1068-
BOOST_AUTO_TEST_CASE(bcValidBlockTest){}
1069-
BOOST_AUTO_TEST_CASE(bcWalletTest){}
1070-
BOOST_AUTO_TEST_CASE(bcTotalDifficultyTest){}
1071-
BOOST_AUTO_TEST_CASE(bcMultiChainTest){}
1072-
BOOST_AUTO_TEST_CASE(bcForkStressTest){}
1073-
BOOST_AUTO_TEST_CASE(bcForgedTest){}
1074-
BOOST_AUTO_TEST_CASE(bcRandomBlockhashTest){}
1075-
BOOST_AUTO_TEST_CASE(bcExploitTest){}
1076-
BOOST_AUTO_TEST_CASE(bcUncleSpecialTests){}
10771104

1105+
BOOST_AUTO_TEST_SUITE(BlockchainTests)
1106+
1107+
// Tests that contain only valid blocks and check that import is correct
1108+
BOOST_FIXTURE_TEST_SUITE(ValidBlocks, bcValidTestFixture)
1109+
BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest) {}
1110+
BOOST_AUTO_TEST_CASE(bcExploitTest) {}
1111+
BOOST_AUTO_TEST_CASE(bcForkStressTest) {}
1112+
BOOST_AUTO_TEST_CASE(bcGasPricerTest) {}
1113+
BOOST_AUTO_TEST_CASE(bcMultiChainTest) {}
1114+
BOOST_AUTO_TEST_CASE(bcRandomBlockhashTest) {}
1115+
BOOST_AUTO_TEST_CASE(bcStateTests) {}
1116+
BOOST_AUTO_TEST_CASE(bcTotalDifficultyTest) {}
1117+
BOOST_AUTO_TEST_CASE(bcUncleSpecialTests) {}
1118+
BOOST_AUTO_TEST_CASE(bcUncleTest) {}
1119+
BOOST_AUTO_TEST_CASE(bcValidBlockTest) {}
1120+
BOOST_AUTO_TEST_CASE(bcWalletTest) {}
10781121
BOOST_AUTO_TEST_SUITE_END()
10791122

1080-
//Transition from fork to fork tests
1081-
BOOST_FIXTURE_TEST_SUITE(TransitionTests, bcTransitionFixture)
1123+
// Tests that might have invalid blocks and check that those are rejected
1124+
BOOST_FIXTURE_TEST_SUITE(InvalidBlocks, bcInvalidTestFixture)
1125+
BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest) {}
1126+
BOOST_AUTO_TEST_CASE(bcForgedTest) {}
1127+
BOOST_AUTO_TEST_CASE(bcInvalidHeaderTest) {}
1128+
BOOST_AUTO_TEST_CASE(bcMultiChainTest) {}
1129+
BOOST_AUTO_TEST_CASE(bcUncleHeaderValidity) {}
1130+
BOOST_AUTO_TEST_CASE(bcUncleSpecialTests) {}
1131+
BOOST_AUTO_TEST_CASE(bcUncleTest) {}
1132+
BOOST_AUTO_TEST_SUITE_END()
10821133

1083-
BOOST_AUTO_TEST_CASE(bcFrontierToHomestead){}
1084-
BOOST_AUTO_TEST_CASE(bcHomesteadToDao){}
1085-
BOOST_AUTO_TEST_CASE(bcHomesteadToEIP150){}
1086-
BOOST_AUTO_TEST_CASE(bcEIP158ToByzantium){}
1134+
// Transition from fork to fork tests
1135+
BOOST_FIXTURE_TEST_SUITE(TransitionTests, bcTransitionFixture)
10871136
BOOST_AUTO_TEST_CASE(bcByzantiumToConstantinopleFix) {}
1137+
BOOST_AUTO_TEST_CASE(bcEIP158ToByzantium) {}
1138+
BOOST_AUTO_TEST_CASE(bcFrontierToHomestead) {}
1139+
BOOST_AUTO_TEST_CASE(bcHomesteadToDao) {}
1140+
BOOST_AUTO_TEST_CASE(bcHomesteadToEIP150) {}
1141+
BOOST_AUTO_TEST_SUITE_END()
10881142

10891143
BOOST_AUTO_TEST_SUITE_END()
10901144

test/tools/jsontests/BlockChainTests.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@ namespace dev
3131
{
3232
namespace test
3333
{
34+
class BlockchainInvalidTestSuite : public TestSuite
35+
{
36+
public:
37+
json_spirit::mValue doTests(json_spirit::mValue const& _input, bool _fillin) const override;
38+
boost::filesystem::path suiteFolder() const override;
39+
boost::filesystem::path suiteFillerFolder() const override;
40+
};
3441

35-
class BlockchainTestSuite: public TestSuite
42+
class BlockchainValidTestSuite : public TestSuite
3643
{
3744
public:
3845
json_spirit::mValue doTests(json_spirit::mValue const& _input, bool _fillin) const override;
3946
boost::filesystem::path suiteFolder() const override;
4047
boost::filesystem::path suiteFillerFolder() const override;
4148
};
4249

43-
class BCGeneralStateTestsSuite: public BlockchainTestSuite
50+
class BCGeneralStateTestsSuite : public BlockchainValidTestSuite
4451
{
4552
boost::filesystem::path suiteFolder() const override;
4653
boost::filesystem::path suiteFillerFolder() const override;
@@ -79,7 +86,8 @@ void checkJsonSectionForInvalidBlock(mObject& _blObj);
7986
void checkExpectedException(mObject& _blObj, Exception const& _e);
8087
void checkBlocks(TestBlock const& _blockFromFields, TestBlock const& _blockFromRlp, string const& _testname);
8188
bigint calculateMiningReward(u256 const& _blNumber, u256 const& _unNumber1, u256 const& _unNumber2, SealEngineFace const& _sealEngine);
82-
json_spirit::mObject fillBCTest(json_spirit::mObject const& _input);
89+
json_spirit::mObject fillBCTest(
90+
json_spirit::mObject const& _input, bool _allowInvalidBlocks = false);
8391
void testBCTest(json_spirit::mObject const& _o);
8492

8593
} } // Namespace Close

test/tools/libtesteth/TestOutputHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class TestOutputHelper
6060
TestOutputHelper() {}
6161
void checkUnfinishedTestFolders(); // Checkup that all test folders are active during the test
6262
// run
63+
std::string detectFilterForMinusTArgument();
6364
Timer m_timer;
6465
size_t m_currTest;
6566
size_t m_maxTests;

test/tools/libtesteth/boostTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void customTestSuite()
5656
}
5757
else if (opt.rCurrentTestSuite.find("BlockchainTests") != std::string::npos)
5858
{
59-
dev::test::BlockchainTestSuite suite;
59+
dev::test::BlockchainValidTestSuite suite;
6060
suite.runTestWithoutFiller(file);
6161
}
6262
else if (opt.rCurrentTestSuite.find("TransitionTests") != std::string::npos)

test/unittests/libtesteth/blockchainTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(fillingExpectationOnMultipleNetworks)
8484
)";
8585
json_spirit::mValue input;
8686
json_spirit::read_string(s, input);
87-
BlockchainTestSuite suite;
87+
BlockchainValidTestSuite suite;
8888
json_spirit::mValue output = suite.doTests(input, true);
8989
BOOST_CHECK_MESSAGE(output.get_obj().size() == 2, "A wrong number of tests were generated.");
9090
}
@@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(fillingExpectationOnSingleNetwork)
171171
)";
172172
json_spirit::mValue input;
173173
json_spirit::read_string(s, input);
174-
BlockchainTestSuite suite;
174+
BlockchainValidTestSuite suite;
175175
json_spirit::mValue output = suite.doTests(input, true);
176176
const string testname = "fillingExpectationOnSingleNetwork_EIP150";
177177
BOOST_CHECK_MESSAGE(output.get_obj().size() == 1, "A wrong number of tests were generated.");
@@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE(fillingWithWrongExpectation)
250250
json_spirit::mValue input;
251251
json_spirit::read_string(s, input);
252252

253-
BlockchainTestSuite suite;
253+
BlockchainValidTestSuite suite;
254254
json_spirit::mValue output = suite.doTests(input, true);
255255
BOOST_CHECK_MESSAGE(output.get_obj().size() == 1, "A wrong number of tests were generated.");
256256
}

0 commit comments

Comments
 (0)