Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/jsontests
Submodule jsontests updated 508 files
120 changes: 87 additions & 33 deletions test/tools/jsontests/BlockChainTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Comment thread
gumb0 marked this conversation as resolved.
BOOST_ERROR("Mined block expected to be valid! " + testName);

blArray.push_back(blObj); //json data
}//each blocks

Expand Down Expand Up @@ -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();

Expand All @@ -1024,6 +1054,20 @@ class bcTestFixture {
}
};

class bcInvalidTestFixture

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.
Thats for the future. for now just separate tests with invalid blocks that we have.

{
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()
Expand Down Expand Up @@ -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()

Expand Down
14 changes: 11 additions & 3 deletions test/tools/jsontests/BlockChainTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ namespace dev
{
namespace test
{
class BlockchainInvalidTestSuite : public TestSuite
{
public:
json_spirit::mValue doTests(json_spirit::mValue const& _input, bool _fillin) const override;
boost::filesystem::path suiteFolder() const override;
boost::filesystem::path suiteFillerFolder() const override;
};

class BlockchainTestSuite: public TestSuite
class BlockchainValidTestSuite : public TestSuite
{
public:
json_spirit::mValue doTests(json_spirit::mValue const& _input, bool _fillin) const override;
boost::filesystem::path suiteFolder() const override;
boost::filesystem::path suiteFillerFolder() const override;
};

class BCGeneralStateTestsSuite: public BlockchainTestSuite
class BCGeneralStateTestsSuite : public BlockchainValidTestSuite
{
boost::filesystem::path suiteFolder() const override;
boost::filesystem::path suiteFillerFolder() const override;
Expand Down Expand Up @@ -79,7 +86,8 @@ void checkJsonSectionForInvalidBlock(mObject& _blObj);
void checkExpectedException(mObject& _blObj, Exception const& _e);
void checkBlocks(TestBlock const& _blockFromFields, TestBlock const& _blockFromRlp, string const& _testname);
bigint calculateMiningReward(u256 const& _blNumber, u256 const& _unNumber1, u256 const& _unNumber2, SealEngineFace const& _sealEngine);
json_spirit::mObject fillBCTest(json_spirit::mObject const& _input);
json_spirit::mObject fillBCTest(
json_spirit::mObject const& _input, bool _allowInvalidBlocks = false);
void testBCTest(json_spirit::mObject const& _o);

} } // Namespace Close
2 changes: 1 addition & 1 deletion test/tools/libtesteth/boostTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void customTestSuite()
}
else if (opt.rCurrentTestSuite.find("BlockchainTests") != std::string::npos)
{
dev::test::BlockchainTestSuite suite;
dev::test::BlockchainValidTestSuite suite;
suite.runTestWithoutFiller(file);
}
else if (opt.rCurrentTestSuite.find("TransitionTests") != std::string::npos)
Expand Down
31 changes: 17 additions & 14 deletions test/unittests/libethereum/GasPricer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ using namespace dev::eth;
using namespace dev::test;
namespace fs = boost::filesystem;

const string c_pathToValidBlocks = "/BlockchainTests/ValidBlocks/";
const string c_pathToInValidBlocks = "/BlockchainTests/InvalidBlocks/";

namespace dev { namespace test {

void executeGasPricerTest(string const& name, double _etherPrice, double _blockFee, fs::path const& _bcTestPath, TransactionPriority _txPrio, u256 _expectedAsk, u256 _expectedBid, eth::Network _sealEngineNetwork = eth::Network::TransitionnetTest)
Expand Down Expand Up @@ -95,95 +98,95 @@ BOOST_AUTO_TEST_CASE(basicGasPricer_RPC_API_Test_Frontier)
{
u256 _expectedAsk = 16056883295;
u256 _expectedBid = 1;
dev::test::executeGasPricerTest("RPC_API_Test_Frontier", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/RPC_API_Test.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("RPC_API_Test_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/RPC_API_Test.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_RPC_API_Test_Homestead)
{
u256 _expectedAsk = 16056864311;
u256 _expectedBid = 1;
dev::test::executeGasPricerTest("RPC_API_Test_Homestead", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/RPC_API_Test.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
dev::test::executeGasPricerTest("RPC_API_Test_Homestead", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/RPC_API_Test.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_bcValidBlockTest)
{
dev::test::executeGasPricerTest("SimpleTx_Frontier", 30.679, 15.0, "/BlockchainTests/bcValidBlockTest/SimpleTx.json", TransactionPriority::Medium, 155632494086, 10);
dev::test::executeGasPricerTest("SimpleTx_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcValidBlockTest/SimpleTx.json", TransactionPriority::Medium, 155632494086, 10);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_bcUncleTest_Frontier)
{
u256 _expectedAsk = 155632494086;
u256 _expectedBid = 1;
dev::test::executeGasPricerTest("twoUncle_Frontier", 30.679, 15.0, "/BlockchainTests/bcUncleTest/twoUncle.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("twoUncle_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcUncleTest/twoUncle.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_bcUncleTest_Homestead)
{
u256 _expectedAsk = 155632494086;
u256 _expectedBid = 1;
dev::test::executeGasPricerTest("twoUncle_Homestead", 30.679, 15.0, "/BlockchainTests/bcUncleTest/twoUncle.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
dev::test::executeGasPricerTest("twoUncle_Homestead", 30.679, 15.0, c_pathToValidBlocks + "bcUncleTest/twoUncle.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_bcUncleHeaderValidity_Frontier)
{
u256 _expectedAsk = 155632494086;
u256 _expectedBid = 1;
dev::test::executeGasPricerTest("correct_Frontier", 30.679, 15.0, "/BlockchainTests/bcUncleHeaderValidity/correct.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("correct_Frontier", 30.679, 15.0, c_pathToInValidBlocks + "bcUncleHeaderValidity/correct.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_bcUncleHeaderValidity_Homestead)
{
u256 _expectedAsk = 155633980282;
u256 _expectedBid = 1;
dev::test::executeGasPricerTest("correct_Homestead", 30.679, 15.0, "/BlockchainTests/bcUncleHeaderValidity/correct.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
dev::test::executeGasPricerTest("correct_Homestead", 30.679, 15.0, c_pathToInValidBlocks + "bcUncleHeaderValidity/correct.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_notxs_frontier)
{
u256 _expectedAsk = 155632494086;
u256 _expectedBid = 155632494086;
dev::test::executeGasPricerTest("notxs_Frontier", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/notxs.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("notxs_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/notxs.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_notxs_homestead)
{
u256 _expectedAsk = 155632494086;
u256 _expectedBid = 155632494086;
dev::test::executeGasPricerTest("notxs_Homestead", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/notxs.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
dev::test::executeGasPricerTest("notxs_Homestead", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/notxs.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::HomesteadTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_LowestPrio)
{
u256 _expectedAsk = 15731408053;
u256 _expectedBid = 10000000000000;
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/highGasUsage.json", TransactionPriority::Lowest, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/highGasUsage.json", TransactionPriority::Lowest, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_LowPrio)
{
u256 _expectedAsk = 15731408053;
u256 _expectedBid = 15734152261884;
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/highGasUsage.json", TransactionPriority::Low, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/highGasUsage.json", TransactionPriority::Low, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_MediumPrio)
{
u256 _expectedAsk = 15731408053;
u256 _expectedBid = 20000000000000;
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/highGasUsage.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/highGasUsage.json", TransactionPriority::Medium, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_HighPrio)
{
u256 _expectedAsk = 15731408053;
u256 _expectedBid = 24265847738115;
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/highGasUsage.json", TransactionPriority::High, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/highGasUsage.json", TransactionPriority::High, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}

BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_HighestPrio)
{
u256 _expectedAsk = 15731408053;
u256 _expectedBid = 30000000000000;
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, "/BlockchainTests/bcGasPricerTest/highGasUsage.json", TransactionPriority::Highest, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
dev::test::executeGasPricerTest("highGasUsage_Frontier", 30.679, 15.0, c_pathToValidBlocks + "bcGasPricerTest/highGasUsage.json", TransactionPriority::Highest, _expectedAsk, _expectedBid, eth::Network::FrontierTest);
}
BOOST_AUTO_TEST_SUITE_END()
Loading