Fabcoin Core  0.16.2
P2P Digital Currency
Genesis.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
23 #include <fstream>
24 #include <random>
25 
26 #include <boost/test/unit_test.hpp>
28 #include <libdevcore/CommonIO.h>
29 #include <libethereum/BlockChain.h>
32 
33 using namespace std;
34 using namespace dev;
35 using namespace dev::eth;
36 using namespace dev::test;
37 
38 namespace js = json_spirit;
39 
41 
42 BOOST_AUTO_TEST_CASE(emptySHA3Types)
43 {
44  h256 emptyListSHA3(fromHex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"));
45  BOOST_REQUIRE_EQUAL(emptyListSHA3, EmptyListSHA3);
46 
47  h256 emptySHA3(fromHex("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
48  BOOST_REQUIRE_EQUAL(emptySHA3, EmptySHA3);
49 }
50 
51 BOOST_AUTO_TEST_CASE(genesis_tests)
52 {
53  string testPath = test::getTestPath();
54  testPath += "/BasicTests";
55 
56  cnote << "Testing Genesis block...";
57  js::mValue v;
58  string s = contentsString(testPath + "/genesishashestest.json");
59  BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'genesishashestest.json' is empty. Have you cloned the 'tests' repo branch develop?");
60  js::read_string(s, v);
61 
62  js::mObject o = v.get_obj();
63 
64  ChainParams p(genesisInfo(eth::Network::MainNetwork), genesisStateRoot(Network::MainNetwork));
65  BOOST_CHECK_EQUAL(p.calculateStateRoot(), h256(o["genesis_state_root"].get_str()));
66  BOOST_CHECK_EQUAL(toHex(p.genesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str())));
67  BOOST_CHECK_EQUAL(BlockHeader(p.genesisBlock()).hash(), h256(o["genesis_hash"].get_str()));
68 }
69 
const Object & get_obj() const
h256 EmptySHA3
Definition: SHA3.cpp:35
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
Definition: CommonData.h:54
h256 calculateStateRoot(bool _force=false) const
BOOST_AUTO_TEST_CASE(emptySHA3Types)
Definition: Genesis.cpp:42
h256 EmptyListSHA3
Definition: SHA3.cpp:36
bytes genesisBlock() const
Genesis block info.
Encapsulation of a block header.
Definition: BlockHeader.h:95
h256 const & genesisStateRoot(Network _n)
Definition: GenesisInfo.cpp:57
std::hash for asio::adress
Definition: Common.h:323
std::string contentsString(std::string const &_file)
Retrieve and returns the contents of the given file as a std::string.
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
bool read_string(const String_type &s, Value_type &value)
std::string getTestPath()
Definition: Common.cpp:35
FixedHash< 32 > h256
Definition: FixedHash.h:340
mConfig::Object_type mObject
std::string const & genesisInfo(Network _n)
Definition: GenesisInfo.cpp:37
#define cnote
Definition: Log.h:303
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Helper functions to work with json::spirit and test files.