2014-01-19 14:42:02 +00:00
|
|
|
/*
|
|
|
|
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
|
2014-02-06 18:53:46 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
2014-01-19 14:42:02 +00:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2014-02-16 10:20:55 +00:00
|
|
|
cpp-ethereum is distributed in the hope that it will be useful,
|
2014-01-19 14:42:02 +00:00
|
|
|
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
|
2014-02-16 10:41:15 +00:00
|
|
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2014-01-19 14:42:02 +00:00
|
|
|
*/
|
|
|
|
/** @file dagger.cpp
|
|
|
|
* @author Gav Wood <i@gavwood.com>
|
|
|
|
* @date 2014
|
2015-03-05 14:58:20 +00:00
|
|
|
* Dashimoto test functions.
|
2014-01-19 14:42:02 +00:00
|
|
|
*/
|
|
|
|
|
2015-03-05 14:58:20 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <random>
|
|
|
|
#include "JsonSpiritHeaders.h"
|
|
|
|
#include <libdevcore/CommonIO.h>
|
2014-10-12 18:57:25 +00:00
|
|
|
#include <libethcore/ProofOfWork.h>
|
2015-04-13 16:12:05 +00:00
|
|
|
#include <libethcore/EthashAux.h>
|
2015-03-05 14:58:20 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include "TestHelper.h"
|
|
|
|
|
2014-01-19 14:42:02 +00:00
|
|
|
using namespace std;
|
2014-09-05 15:09:58 +00:00
|
|
|
using namespace dev;
|
|
|
|
using namespace dev::eth;
|
2014-01-19 14:42:02 +00:00
|
|
|
|
2015-03-05 14:58:20 +00:00
|
|
|
namespace js = json_spirit;
|
|
|
|
|
|
|
|
using dev::operator <<;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(DashimotoTests)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(basic_test)
|
2014-01-19 14:42:02 +00:00
|
|
|
{
|
2015-03-05 14:58:20 +00:00
|
|
|
string testPath = test::getTestPath();
|
|
|
|
|
|
|
|
testPath += "/PoWTests";
|
|
|
|
|
2015-03-18 21:10:32 +00:00
|
|
|
cnote << "Testing Proof of Work...";
|
2015-03-05 14:58:20 +00:00
|
|
|
js::mValue v;
|
|
|
|
string s = asString(contents(testPath + "/ethash_tests.json"));
|
|
|
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'ethash_tests.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
|
|
|
js::read_string(s, v);
|
|
|
|
for (auto& i: v.get_obj())
|
2014-01-19 14:42:02 +00:00
|
|
|
{
|
2015-03-05 14:58:20 +00:00
|
|
|
cnote << i.first;
|
|
|
|
js::mObject& o = i.second.get_obj();
|
|
|
|
vector<pair<string, string>> ss;
|
2015-03-06 21:53:49 +00:00
|
|
|
BlockInfo header = BlockInfo::fromHeader(fromHex(o["header"].get_str()), CheckNothing);
|
2015-03-05 14:58:20 +00:00
|
|
|
h256 headerHash(o["header_hash"].get_str());
|
|
|
|
Nonce nonce(o["nonce"].get_str());
|
|
|
|
BOOST_REQUIRE_EQUAL(headerHash, header.headerHash(WithoutNonce));
|
|
|
|
BOOST_REQUIRE_EQUAL(nonce, header.nonce);
|
|
|
|
|
|
|
|
unsigned cacheSize(o["cache_size"].get_int());
|
|
|
|
h256 cacheHash(o["cache_hash"].get_str());
|
2015-04-13 16:12:05 +00:00
|
|
|
BOOST_REQUIRE_EQUAL(EthashAux::get()->params(header).cache_size, cacheSize);
|
2015-04-15 15:24:57 +00:00
|
|
|
BOOST_REQUIRE_EQUAL(sha3(EthashAux::get()->light(header)->data()), cacheHash);
|
2015-03-05 14:58:20 +00:00
|
|
|
|
|
|
|
#if TEST_FULL
|
|
|
|
unsigned fullSize(o["full_size"].get_int());
|
|
|
|
h256 fullHash(o["full_hash"].get_str());
|
2015-04-13 16:12:05 +00:00
|
|
|
BOOST_REQUIRE_EQUAL(EthashAux::get()->full(header).size(), fullSize);
|
|
|
|
BOOST_REQUIRE_EQUAL(sha3(EthashAux::get()->full(header)), fullHash);
|
2015-03-04 10:55:22 +00:00
|
|
|
#endif
|
2015-03-05 14:58:20 +00:00
|
|
|
|
|
|
|
h256 result(o["result"].get_str());
|
2015-04-13 16:12:05 +00:00
|
|
|
Ethash::Result r = EthashAux::eval(header);
|
2015-03-05 14:58:20 +00:00
|
|
|
BOOST_REQUIRE_EQUAL(r.value, result);
|
|
|
|
BOOST_REQUIRE_EQUAL(r.mixHash, header.mixHash);
|
|
|
|
}
|
2014-01-19 14:42:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-05 14:58:20 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
|
|
|
|
|