@@ -59,7 +59,8 @@ namespace test {
5959eth::Network ChainBranch::s_tempBlockchainNetwork = eth::Network::MainNetwork;
6060eth::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}
172194fs::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+ {
10071037public:
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+
10271071class bcTransitionFixture {
10281072public:
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) {}
10781121BOOST_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)
10871136BOOST_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
10891143BOOST_AUTO_TEST_SUITE_END()
10901144
0 commit comments