This repository has been 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.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4017 from ethereum/eip100
EIP100 - Difficulty adjustment including uncles
- Loading branch information
Showing
3 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
This file is part of cpp-ethereum. | ||
cpp-ethereum is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
cpp-ethereum is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/** @file ethash.cpp | ||
* Ethash class testing. | ||
*/ | ||
|
||
#include <boost/test/unit_test.hpp> | ||
#include <test/tools/libtesteth/TestHelper.h> | ||
#include <libethashseal/Ethash.h> | ||
|
||
using namespace std; | ||
using namespace dev; | ||
using namespace dev::eth; | ||
using namespace dev::test; | ||
|
||
BOOST_FIXTURE_TEST_SUITE(EthashTests, TestOutputHelper) | ||
|
||
BOOST_AUTO_TEST_CASE(calculateDifficultyMetropolisWithoutUncles) | ||
{ | ||
ChainOperationParams params; | ||
params.otherParams["metropolisForkBlock"] = "0x1000"; | ||
|
||
Ethash ethash; | ||
ethash.setChainParams(params); | ||
|
||
BlockHeader parentHeader; | ||
parentHeader.clear(); | ||
parentHeader.setNumber(0x2000); | ||
parentHeader.setTimestamp(100); | ||
parentHeader.setDifficulty(1000000); | ||
|
||
BlockHeader header; | ||
header.clear(); | ||
header.setNumber(0x2001); | ||
header.setTimestamp(130); | ||
|
||
BOOST_REQUIRE_EQUAL(ethash.calculateDifficulty(header, parentHeader), 999024); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(calculateDifficultyMetropolisWithUncles) | ||
{ | ||
ChainOperationParams params; | ||
params.otherParams["metropolisForkBlock"] = "0x1000"; | ||
|
||
Ethash ethash; | ||
ethash.setChainParams(params); | ||
|
||
BlockHeader parentHeader; | ||
parentHeader.clear(); | ||
parentHeader.setNumber(0x2000); | ||
parentHeader.setTimestamp(100); | ||
parentHeader.setDifficulty(1000000); | ||
parentHeader.setSha3Uncles(h256("0x949d991d685738352398dff73219ab19c62c06e6f8ce899fbae755d5127ed1ef")); | ||
|
||
BlockHeader header; | ||
header.clear(); | ||
header.setNumber(0x2001); | ||
header.setTimestamp(130); | ||
|
||
BOOST_REQUIRE_EQUAL(ethash.calculateDifficulty(header, parentHeader), 999512); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(calculateDifficultyMetropolisMaxAdjustment) | ||
{ | ||
ChainOperationParams params; | ||
params.otherParams["metropolisForkBlock"] = "0x1000"; | ||
|
||
Ethash ethash; | ||
ethash.setChainParams(params); | ||
|
||
BlockHeader parentHeader; | ||
parentHeader.clear(); | ||
parentHeader.setNumber(0x2000); | ||
parentHeader.setTimestamp(100); | ||
parentHeader.setDifficulty(1000000); | ||
|
||
BlockHeader header; | ||
header.clear(); | ||
header.setNumber(0x2001); | ||
header.setTimestamp(1100); | ||
|
||
BOOST_REQUIRE_EQUAL(ethash.calculateDifficulty(header, parentHeader), 951688); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |