diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-14 23:42:05 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-14 23:42:05 +0800 |
commit | 95711bc2dd0af71c741871007cecad12be8076ad (patch) | |
tree | 1d59ced40b3823608710716edef523399336d88a /Godeps/_workspace/src/github.com/ethereum/ethash/test/c/test.cpp | |
parent | 387f6bba3e221dac6f9884b3f9aba98d6b8591cf (diff) | |
download | go-tangerine-95711bc2dd0af71c741871007cecad12be8076ad.tar.gz go-tangerine-95711bc2dd0af71c741871007cecad12be8076ad.tar.zst go-tangerine-95711bc2dd0af71c741871007cecad12be8076ad.zip |
Updated ethash
Diffstat (limited to 'Godeps/_workspace/src/github.com/ethereum/ethash/test/c/test.cpp')
-rw-r--r-- | Godeps/_workspace/src/github.com/ethereum/ethash/test/c/test.cpp | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/Godeps/_workspace/src/github.com/ethereum/ethash/test/c/test.cpp b/Godeps/_workspace/src/github.com/ethereum/ethash/test/c/test.cpp index 336713cb7..21cb251fc 100644 --- a/Godeps/_workspace/src/github.com/ethereum/ethash/test/c/test.cpp +++ b/Godeps/_workspace/src/github.com/ethereum/ethash/test/c/test.cpp @@ -4,7 +4,9 @@ #include <libethash/internal.h> #ifdef WITH_CRYPTOPP + #include <libethash/sha3_cryptopp.h> + #else #include <libethash/sha3.h> #endif // WITH_CRYPTOPP @@ -28,7 +30,7 @@ BOOST_AUTO_TEST_CASE(fnv_hash_check) { uint32_t x = 1235U; const uint32_t y = 9999999U, - expected = (FNV_PRIME * x) ^ y; + expected = (FNV_PRIME * x) ^y; x = fnv_hash(x, y); @@ -65,43 +67,50 @@ BOOST_AUTO_TEST_CASE(SHA512_check) { BOOST_AUTO_TEST_CASE(ethash_params_init_genesis_check) { ethash_params params; ethash_params_init(¶ms, 0); - BOOST_REQUIRE_MESSAGE(params.full_size < DAGSIZE_BYTES_INIT, + BOOST_REQUIRE_MESSAGE(params.full_size < DATASET_BYTES_INIT, "\nfull size: " << params.full_size << "\n" - << "should be less than or equal to: " << DAGSIZE_BYTES_INIT << "\n"); - BOOST_REQUIRE_MESSAGE(params.full_size + 20*MIX_BYTES >= DAGSIZE_BYTES_INIT, - "\nfull size + 20*MIX_BYTES: " << params.full_size + 20*MIX_BYTES << "\n" - << "should be greater than or equal to: " << DAGSIZE_BYTES_INIT << "\n"); - BOOST_REQUIRE_MESSAGE(params.cache_size < DAGSIZE_BYTES_INIT / 32, + << "should be less than or equal to: " << DATASET_BYTES_INIT << "\n"); + BOOST_REQUIRE_MESSAGE(params.full_size + 20 * MIX_BYTES >= DATASET_BYTES_INIT, + "\nfull size + 20*MIX_BYTES: " << params.full_size + 20 * MIX_BYTES << "\n" + << "should be greater than or equal to: " << DATASET_BYTES_INIT << "\n"); + BOOST_REQUIRE_MESSAGE(params.cache_size < DATASET_BYTES_INIT / 32, "\ncache size: " << params.cache_size << "\n" - << "should be less than or equal to: " << DAGSIZE_BYTES_INIT / 32 << "\n"); + << "should be less than or equal to: " << DATASET_BYTES_INIT / 32 << "\n"); } BOOST_AUTO_TEST_CASE(ethash_params_init_genesis_calcifide_check) { ethash_params params; ethash_params_init(¶ms, 0); const uint32_t expected_full_size = 1073739904; - const uint32_t expected_cache_size = 1048384; - BOOST_REQUIRE_MESSAGE(params.full_size == expected_full_size, + const uint32_t expected_cache_size = 16776896; + BOOST_REQUIRE_MESSAGE(params.full_size == expected_full_size, "\nexpected: " << expected_cache_size << "\n" << "actual: " << params.full_size << "\n"); - BOOST_REQUIRE_MESSAGE(params.cache_size == expected_cache_size, + BOOST_REQUIRE_MESSAGE(params.cache_size == expected_cache_size, "\nexpected: " << expected_cache_size << "\n" << "actual: " << params.cache_size << "\n"); } BOOST_AUTO_TEST_CASE(light_and_full_client_checks) { ethash_params params; - uint8_t seed[32], hash[32]; + uint8_t seed[32], hash[32], difficulty[32]; ethash_return_value light_out, full_out; memcpy(seed, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", 32); memcpy(hash, "~~~X~~~~~~~~~~~~~~~~~~~~~~~~~~~~", 32); + + // Set the difficulty + difficulty[0] = 197; + difficulty[1] = 90; + for (int i = 2; i < 32; i++) + difficulty[i] = (uint8_t) 255; + ethash_params_init(¶ms, 0); params.cache_size = 1024; params.full_size = 1024 * 32; ethash_cache cache; cache.mem = alloca(params.cache_size); ethash_mkcache(&cache, ¶ms, seed); - node * full_mem = (node *) alloca(params.full_size); + node *full_mem = (node *) alloca(params.full_size); ethash_compute_full_data(full_mem, ¶ms, &cache); { @@ -115,7 +124,6 @@ BOOST_AUTO_TEST_CASE(light_and_full_client_checks) { } - { node node; ethash_calculate_dag_item(&node, 0, ¶ms, &cache); @@ -128,7 +136,7 @@ BOOST_AUTO_TEST_CASE(light_and_full_client_checks) { } { - for (int i = 0 ; i < params.full_size / sizeof(node) ; ++i ) { + for (int i = 0; i < params.full_size / sizeof(node); ++i) { for (uint32_t j = 0; j < 32; ++j) { node expected_node; ethash_calculate_dag_item(&expected_node, j, ¶ms, &cache); @@ -187,6 +195,12 @@ BOOST_AUTO_TEST_CASE(light_and_full_client_checks) { BOOST_REQUIRE_MESSAGE(full_mix_hash_string == light_mix_hash_string, "\nlight mix hash: " << light_mix_hash_string.c_str() << "\n" << "full mix hash: " << full_mix_hash_string.c_str() << "\n"); + BOOST_REQUIRE_MESSAGE(ethash_check_difficulty(full_out.result, difficulty), + "ethash_check_difficulty failed" + ); + BOOST_REQUIRE_MESSAGE(ethash_quick_check_difficulty(hash, 5U, full_out.mix_hash, difficulty), + "ethash_quick_check_difficulty failed" + ); } } @@ -199,14 +213,14 @@ BOOST_AUTO_TEST_CASE(ethash_check_difficulty_check) { memcpy(target, "22222222222222222222222222222222", 32); BOOST_REQUIRE_MESSAGE( ethash_check_difficulty(hash, target), - "\nexpected \"" << hash << "\" to have less difficulty than \"" << target << "\"\n"); + "\nexpected \"" << std::string((char *) hash, 32).c_str() << "\" to have the same or less difficulty than \"" << std::string((char *) target, 32).c_str() << "\"\n"); BOOST_REQUIRE_MESSAGE( - !ethash_check_difficulty(hash, hash), - "\nexpected \"" << hash << "\" to have the same difficulty as \"" << hash << "\"\n"); + ethash_check_difficulty(hash, hash), + "\nexpected \"" << hash << "\" to have the same or less difficulty than \"" << hash << "\"\n"); memcpy(target, "11111111111111111111111111111112", 32); BOOST_REQUIRE_MESSAGE( ethash_check_difficulty(hash, target), - "\nexpected \"" << hash << "\" to have less difficulty than \"" << target << "\"\n"); + "\nexpected \"" << hash << "\" to have the same or less difficulty than \"" << target << "\"\n"); memcpy(target, "11111111111111111111111111111110", 32); BOOST_REQUIRE_MESSAGE( !ethash_check_difficulty(hash, target), |