Fabcoin Core  0.16.2
P2P Digital Currency
dagger.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>
25 #include <libdevcore/CommonIO.h>
26 #include <libethashseal/Ethash.h>
28 #include <boost/test/unit_test.hpp>
30 
31 using namespace std;
32 using namespace dev;
33 using namespace dev::eth;
34 using namespace dev::test;
35 
36 namespace js = json_spirit;
37 
38 using dev::operator <<;
39 
41 
43 {
44  string testPath = test::getTestPath();
45 
46  testPath += "/PoWTests";
47 
48  cnote << "Testing Proof of Work...";
49  js::mValue v;
50  string s = contentsString(testPath + "/ethash_tests.json");
51  BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'ethash_tests.json' is empty. Have you cloned the 'tests' repo branch develop?");
52  js::read_string(s, v);
53  for (auto& i: v.get_obj())
54  {
55  cnote << i.first;
56  js::mObject& o = i.second.get_obj();
57  vector<pair<string, string>> ss;
58  BlockHeader header(fromHex(o["header"].get_str()), HeaderData);
59  h256 headerHash(o["header_hash"].get_str());
60  Nonce nonce(o["nonce"].get_str());
61  BOOST_REQUIRE_EQUAL(headerHash, header.hash(WithoutSeal));
62  BOOST_REQUIRE_EQUAL(nonce, Ethash::nonce(header));
63 
64  unsigned cacheSize(o["cache_size"].get_int());
65  h256 cacheHash(o["cache_hash"].get_str());
66  BOOST_REQUIRE_EQUAL(EthashAux::get()->light(Ethash::seedHash(header))->size, cacheSize);
67  BOOST_REQUIRE_EQUAL(sha3(EthashAux::get()->light(Ethash::seedHash(header))->data()), cacheHash);
68 
69 #if TEST_FULL
70  unsigned fullSize(o["full_size"].get_int());
71  h256 fullHash(o["full_hash"].get_str());
72  BOOST_REQUIRE_EQUAL(EthashAux::get()->full(Ethash::seedHash(header))->size(), fullSize);
73  BOOST_REQUIRE_EQUAL(sha3(EthashAux::get()->full(Ethash::seedHash(header))->data()), fullHash);
74 #endif
75 
76  h256 result(o["result"].get_str());
77  EthashProofOfWork::Result r = EthashAux::eval(Ethash::seedHash(header), header.hash(WithoutSeal), Ethash::nonce(header));
78  BOOST_REQUIRE_EQUAL(r.value, result);
79  BOOST_REQUIRE_EQUAL(r.mixHash, Ethash::mixHash(header));
80  }
81 }
82 
const Object & get_obj() const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
h256 hash(IncludeSeal _i=WithSeal) const
Definition: BlockHeader.cpp:64
Encapsulation of a block header.
Definition: BlockHeader.h:95
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.
BOOST_AUTO_TEST_CASE(basic_test)
Definition: dagger.cpp:42
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
mConfig::Object_type mObject
#define cnote
Definition: Log.h:303
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
uint8_t const size_t const size
Definition: sha3.h:20
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
Definition: SHA3.cpp:214
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
uint8_t const * data
Definition: sha3.h:19
Helper functions to work with json::spirit and test files.