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

Commit

Permalink
Unit test for block reward
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Sep 6, 2018
1 parent cbabea7 commit 246d5a5
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libethashseal/GenesisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ using namespace dev;
#include "genesis/ropsten.cpp"

//Test configurations
#include "genesis/test/byzantiumNoProofTest.cpp"
#include "genesis/test/byzantiumTest.cpp"
#include "genesis/test/byzantiumTransitionTest.cpp"
#include "genesis/test/constantinopleNoProofTest.cpp"
#include "genesis/test/constantinopleTest.cpp"
#include "genesis/test/eip150Test.cpp"
#include "genesis/test/eip158Test.cpp"
Expand Down Expand Up @@ -62,8 +64,13 @@ std::string const& dev::eth::genesisInfo(Network _n)
case Network::EIP150Test: return c_genesisInfoEIP150Test;
case Network::EIP158Test: return c_genesisInfoEIP158Test;
case Network::ByzantiumTest: return c_genesisInfoByzantiumTest;
case Network::ByzantiumNoProofTest:
return c_genesisInfoByzantiumNoProofTest;
case Network::ByzantiumTransitionTest: return c_genesisInfoByzantiumTransitionTest;
case Network::ConstantinopleTest: return c_genesisInfoConstantinopleTest;
case Network::ConstantinopleTest:
return c_genesisInfoConstantinopleTest;
case Network::ConstantinopleNoProofTest:
return c_genesisInfoConstantinopleNoProofTest;
case Network::ExperimentalTransitionTest:
return c_genesisInfoExperimentalTransitionTest;

Expand Down
4 changes: 4 additions & 0 deletions libethashseal/GenesisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ enum class Network
ExperimentalTransitionTest = 79,
/// MainNetwork rules without genesis accounts + NoProof seal engine
MainNetworkNoProofTest = 80,
/// Byzantium rules + NoProof seal engine
ByzantiumNoProofTest = 81,
/// Constantinople rules + NoProof seal engine
ConstantinopleNoProofTest = 82,

// TransitionTest networks
FrontierToHomesteadAt5 = 100,
Expand Down
62 changes: 62 additions & 0 deletions libethashseal/genesis/test/byzantiumNoProofTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
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/>.
*/
#include "../../GenesisInfo.h"

static std::string const c_genesisInfoByzantiumNoProofTest = R"E(
{
"sealEngine": "NoProof",
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"homesteadForkBlock": "0x00",
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "0x00",
"minGasLimit": "0x1388",
"maxGasLimit": "7fffffffffffffff",
"tieBreakingGas": false,
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"networkID" : "0x1",
"chainID": "0x01",
"allowFutureBlocks" : true
},
"genesis": {
"nonce": "0x0000000000000042",
"difficulty": "0x020000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
"0000000000000000000000000000000000000002": { "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
"0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp" } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } },
"0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product" } }
}
}
)E";
63 changes: 63 additions & 0 deletions libethashseal/genesis/test/constantinopleNoProofTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
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/>.
*/
#include "../../GenesisInfo.h"

static std::string const c_genesisInfoConstantinopleNoProofTest = R"E(
{
"sealEngine": "NoProof",
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"homesteadForkBlock": "0x00",
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "0x00",
"constantinopleForkBlock": "0x00",
"minGasLimit": "0x1388",
"maxGasLimit": "7fffffffffffffff",
"tieBreakingGas": false,
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"networkID" : "0x1",
"chainID": "0x01",
"allowFutureBlocks" : true
},
"genesis": {
"nonce": "0x0000000000000042",
"difficulty": "0x020000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
"0000000000000000000000000000000000000002": { "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
"0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp" } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } },
"0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product" } }
}
}
)E";
16 changes: 16 additions & 0 deletions test/tools/libtesteth/BlockChainHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,21 @@ class MainNetworkNoProofTestFixture : public TestOutputHelperFixture

NetworkSelector networkSelector;
};

class ByzantiumTestFixture : public TestOutputHelperFixture
{
public:
ByzantiumTestFixture() : networkSelector(Network::ByzantiumNoProofTest) {}

NetworkSelector networkSelector;
};

class ConstantinopleTestFixture : public TestOutputHelperFixture
{
public:
ConstantinopleTestFixture() : networkSelector(Network::ConstantinopleNoProofTest) {}

NetworkSelector networkSelector;
};
}
}
31 changes: 31 additions & 0 deletions test/unittests/libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,37 @@ BOOST_AUTO_TEST_CASE(bGetReceiptOverflow)
BOOST_CHECK_THROW(block.receipt(123), std::out_of_range);
}


BOOST_FIXTURE_TEST_SUITE(ByzantiumBlockSuite, ByzantiumTestFixture)

BOOST_AUTO_TEST_CASE(bByzantiumBlockReward)
{
TestBlockChain testBlockchain;
TestBlock testBlock;
testBlock.mine(testBlockchain);
testBlockchain.addBlock(testBlock);

TestBlock const& topBlock = testBlockchain.topBlock();
BOOST_REQUIRE_EQUAL(topBlock.state().balance(topBlock.beneficiary()), 3 * ether);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_FIXTURE_TEST_SUITE(ConstantinopleBlockSuite, ConstantinopleTestFixture)

BOOST_AUTO_TEST_CASE(bConstantinopleBlockReward)
{
TestBlockChain testBlockchain;
TestBlock testBlock;
testBlock.mine(testBlockchain);
testBlockchain.addBlock(testBlock);

TestBlock const& topBlock = testBlockchain.topBlock();
BOOST_REQUIRE_EQUAL(topBlock.state().balance(topBlock.beneficiary()), 2 * ether);
}

BOOST_AUTO_TEST_SUITE_END()

class ExperimentalTransitionTestFixture : public TestOutputHelperFixture
{
public:
Expand Down

0 comments on commit 246d5a5

Please sign in to comment.