This repository was archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
split BlockchainTests into Valid and Invalid #5648
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,8 @@ namespace test { | |
| eth::Network ChainBranch::s_tempBlockchainNetwork = eth::Network::MainNetwork; | ||
| eth::Network TestBlockChain::s_sealEngineNetwork = eth::Network::FrontierTest; | ||
|
|
||
| json_spirit::mValue BlockchainTestSuite::doTests(json_spirit::mValue const& _input, bool _fillin) const | ||
| json_spirit::mValue doBCTest( | ||
| json_spirit::mValue const& _input, bool _fillin, bool _allowInvalidBlocks) | ||
| { | ||
| json_spirit::mObject tests; | ||
| for (auto const& i : _input.get_obj()) | ||
|
|
@@ -122,7 +123,7 @@ json_spirit::mValue BlockchainTestSuite::doTests(json_spirit::mValue const& _inp | |
| std::cout << "Filling " << newtestname << std::endl; | ||
|
|
||
| TestOutputHelper::get().setCurrentTestName(newtestname); | ||
| jObjOutput = fillBCTest(jObjOutput); | ||
| jObjOutput = fillBCTest(jObjOutput, _allowInvalidBlocks); | ||
| jObjOutput["network"] = test::netIdToString(network); | ||
| if (inputTest.count("_info")) | ||
| jObjOutput["_info"] = inputTest.at("_info"); | ||
|
|
@@ -161,13 +162,34 @@ json_spirit::mValue BlockchainTestSuite::doTests(json_spirit::mValue const& _inp | |
|
|
||
| return tests; | ||
| } | ||
| fs::path BlockchainTestSuite::suiteFolder() const | ||
|
|
||
| json_spirit::mValue BlockchainValidTestSuite::doTests( | ||
| json_spirit::mValue const& _input, bool _fillin) const | ||
| { | ||
| return doBCTest(_input, _fillin, false); | ||
| } | ||
|
|
||
| json_spirit::mValue BlockchainInvalidTestSuite::doTests( | ||
| json_spirit::mValue const& _input, bool _fillin) const | ||
| { | ||
| return doBCTest(_input, _fillin, true); | ||
| } | ||
|
|
||
| fs::path BlockchainInvalidTestSuite::suiteFolder() const | ||
| { | ||
| return "BlockchainTests"; | ||
| return fs::path("BlockchainTests") / "InvalidBlocks"; | ||
| } | ||
| fs::path BlockchainTestSuite::suiteFillerFolder() const | ||
| fs::path BlockchainInvalidTestSuite::suiteFillerFolder() const | ||
| { | ||
| return "BlockchainTestsFiller"; | ||
| return fs::path("BlockchainTestsFiller") / "InvalidBlocks"; | ||
| } | ||
| fs::path BlockchainValidTestSuite::suiteFolder() const | ||
| { | ||
| return fs::path("BlockchainTests") / "ValidBlocks"; | ||
| } | ||
| fs::path BlockchainValidTestSuite::suiteFillerFolder() const | ||
| { | ||
| return fs::path("BlockchainTestsFiller") / "ValidBlocks"; | ||
| } | ||
| fs::path BCGeneralStateTestsSuite::suiteFolder() const | ||
| { | ||
|
|
@@ -253,7 +275,7 @@ void ChainBranch::resetBlockchain() | |
| dev::test::TestBlockChain::s_sealEngineNetwork = s_tempBlockchainNetwork; | ||
| } | ||
|
|
||
| json_spirit::mObject fillBCTest(json_spirit::mObject const& _input) | ||
| json_spirit::mObject fillBCTest(json_spirit::mObject const& _input, bool _allowInvalidBlocks) | ||
| { | ||
| json_spirit::mObject output; | ||
| string const& testName = TestOutputHelper::get().testName(); | ||
|
|
@@ -389,6 +411,7 @@ json_spirit::mObject fillBCTest(json_spirit::mObject const& _input) | |
| blObj["uncleHeaders"] = aUncleList; | ||
| blObj["transactions"] = writeTransactionsToJson(alterBlock.transactionQueue()); | ||
|
|
||
| bool blockImportExceptionHappen = false; | ||
| compareBlocks(block, alterBlock); | ||
| try | ||
| { | ||
|
|
@@ -416,19 +439,25 @@ json_spirit::mObject fillBCTest(json_spirit::mObject const& _input) | |
| cnote << testName + "block import throw an exception: " << diagnostic_information(_e); | ||
| checkExpectedException(blObj, _e); | ||
| eraseJsonSectionForInvalidBlock(blObj); | ||
| blockImportExceptionHappen = true; | ||
| } | ||
| catch (std::exception const& _e) | ||
| { | ||
| cnote << testName + "block import throw an exception: " << _e.what(); | ||
| cout << testName + "block import thrown std exeption\n"; | ||
| eraseJsonSectionForInvalidBlock(blObj); | ||
| blockImportExceptionHappen = true; | ||
| } | ||
| catch (...) | ||
| { | ||
| cout << testName + "block import thrown unknown exeption\n"; | ||
| eraseJsonSectionForInvalidBlock(blObj); | ||
| blockImportExceptionHappen = true; | ||
| } | ||
|
|
||
| if (!_allowInvalidBlocks && blockImportExceptionHappen) | ||
| BOOST_ERROR("Mined block expected to be valid! " + testName); | ||
|
|
||
| blArray.push_back(blObj); //json data | ||
| }//each blocks | ||
|
|
||
|
|
@@ -1003,11 +1032,12 @@ void checkBlocks(TestBlock const& _blockFromFields, TestBlock const& _blockFromR | |
| } | ||
| } | ||
|
|
||
| class bcTestFixture { | ||
| class bcValidTestFixture | ||
| { | ||
| public: | ||
| bcTestFixture() | ||
| bcValidTestFixture() | ||
| { | ||
| test::BlockchainTestSuite suite; | ||
| test::BlockchainValidTestSuite suite; | ||
| string const casename = boost::unit_test::framework::current_test_case().p_name; | ||
| boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path(); | ||
|
|
||
|
|
@@ -1024,6 +1054,20 @@ class bcTestFixture { | |
| } | ||
| }; | ||
|
|
||
| class bcInvalidTestFixture | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is almost identical to the one above, it looks like you could have a base class common for both to avoid code repetition. Just a suggestion.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a plan for malicious block blockchain testsing, when the test tool will produce invlid block rlps and try to import. |
||
| { | ||
| public: | ||
| bcInvalidTestFixture() | ||
| { | ||
| test::BlockchainInvalidTestSuite suite; | ||
| string const casename = boost::unit_test::framework::current_test_case().p_name; | ||
| boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path(); | ||
|
|
||
| suite.runAllTestsInFolder(casename); | ||
| test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename); | ||
| } | ||
| }; | ||
|
|
||
| class bcTransitionFixture { | ||
| public: | ||
| bcTransitionFixture() | ||
|
|
@@ -1057,34 +1101,44 @@ class bcGeneralTestsFixture | |
| } | ||
| }; | ||
|
|
||
| BOOST_FIXTURE_TEST_SUITE(BlockchainTests, bcTestFixture) | ||
|
|
||
| BOOST_AUTO_TEST_CASE(bcStateTests){} | ||
| BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest){} | ||
| BOOST_AUTO_TEST_CASE(bcGasPricerTest){} | ||
| BOOST_AUTO_TEST_CASE(bcInvalidHeaderTest){} | ||
| BOOST_AUTO_TEST_CASE(bcUncleHeaderValidity){} | ||
| BOOST_AUTO_TEST_CASE(bcUncleTest){} | ||
| BOOST_AUTO_TEST_CASE(bcValidBlockTest){} | ||
| BOOST_AUTO_TEST_CASE(bcWalletTest){} | ||
| BOOST_AUTO_TEST_CASE(bcTotalDifficultyTest){} | ||
| BOOST_AUTO_TEST_CASE(bcMultiChainTest){} | ||
| BOOST_AUTO_TEST_CASE(bcForkStressTest){} | ||
| BOOST_AUTO_TEST_CASE(bcForgedTest){} | ||
| BOOST_AUTO_TEST_CASE(bcRandomBlockhashTest){} | ||
| BOOST_AUTO_TEST_CASE(bcExploitTest){} | ||
| BOOST_AUTO_TEST_CASE(bcUncleSpecialTests){} | ||
|
|
||
| BOOST_AUTO_TEST_SUITE(BlockchainTests) | ||
|
|
||
| // Tests that contain only valid blocks and check that import is correct | ||
| BOOST_FIXTURE_TEST_SUITE(ValidBlocks, bcValidTestFixture) | ||
| BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcExploitTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcForkStressTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcGasPricerTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcMultiChainTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcRandomBlockhashTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcStateTests) {} | ||
| BOOST_AUTO_TEST_CASE(bcTotalDifficultyTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcUncleSpecialTests) {} | ||
| BOOST_AUTO_TEST_CASE(bcUncleTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcValidBlockTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcWalletTest) {} | ||
| BOOST_AUTO_TEST_SUITE_END() | ||
|
|
||
| //Transition from fork to fork tests | ||
| BOOST_FIXTURE_TEST_SUITE(TransitionTests, bcTransitionFixture) | ||
| // Tests that might have invalid blocks and check that those are rejected | ||
| BOOST_FIXTURE_TEST_SUITE(InvalidBlocks, bcInvalidTestFixture) | ||
| BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcForgedTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcInvalidHeaderTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcMultiChainTest) {} | ||
| BOOST_AUTO_TEST_CASE(bcUncleHeaderValidity) {} | ||
| BOOST_AUTO_TEST_CASE(bcUncleSpecialTests) {} | ||
| BOOST_AUTO_TEST_CASE(bcUncleTest) {} | ||
| BOOST_AUTO_TEST_SUITE_END() | ||
|
|
||
| BOOST_AUTO_TEST_CASE(bcFrontierToHomestead){} | ||
| BOOST_AUTO_TEST_CASE(bcHomesteadToDao){} | ||
| BOOST_AUTO_TEST_CASE(bcHomesteadToEIP150){} | ||
| BOOST_AUTO_TEST_CASE(bcEIP158ToByzantium){} | ||
| // Transition from fork to fork tests | ||
| BOOST_FIXTURE_TEST_SUITE(TransitionTests, bcTransitionFixture) | ||
| BOOST_AUTO_TEST_CASE(bcByzantiumToConstantinopleFix) {} | ||
| BOOST_AUTO_TEST_CASE(bcEIP158ToByzantium) {} | ||
| BOOST_AUTO_TEST_CASE(bcFrontierToHomestead) {} | ||
| BOOST_AUTO_TEST_CASE(bcHomesteadToDao) {} | ||
| BOOST_AUTO_TEST_CASE(bcHomesteadToEIP150) {} | ||
| BOOST_AUTO_TEST_SUITE_END() | ||
|
|
||
| BOOST_AUTO_TEST_SUITE_END() | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.