difficulty test removed as outdated
This commit is contained in:
parent
3c68509745
commit
cbca150265
8 changed files with 3 additions and 201273 deletions
|
|
@ -18,7 +18,6 @@ add_subdirectory(db_tests)
|
||||||
|
|
||||||
add_executable(coretests ${CORE_TESTS})
|
add_executable(coretests ${CORE_TESTS})
|
||||||
add_executable(crypto-tests ${CRYPTO_TESTS})
|
add_executable(crypto-tests ${CRYPTO_TESTS})
|
||||||
add_executable(difficulty-tests difficulty/difficulty.cpp)
|
|
||||||
add_executable(hash-tests hash/main.cpp)
|
add_executable(hash-tests hash/main.cpp)
|
||||||
add_executable(hash-target-tests hash-target.cpp)
|
add_executable(hash-target-tests hash-target.cpp)
|
||||||
add_executable(functional_tests ${FUNC_TESTS})
|
add_executable(functional_tests ${FUNC_TESTS})
|
||||||
|
|
@ -30,7 +29,6 @@ add_executable(net_load_tests_srv net_load_tests/srv.cpp)
|
||||||
add_dependencies(coretests version)
|
add_dependencies(coretests version)
|
||||||
|
|
||||||
target_link_libraries(coretests currency_core common crypto wallet rpc zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
target_link_libraries(coretests currency_core common crypto wallet rpc zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
||||||
target_link_libraries(difficulty-tests currency_core ${CMAKE_THREAD_LIBS_INIT} ethash ${Boost_LIBRARIES})
|
|
||||||
target_link_libraries(functional_tests wallet currency_core crypto common rpc zlibstatic ethash upnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
target_link_libraries(functional_tests wallet currency_core crypto common rpc zlibstatic ethash upnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
||||||
target_link_libraries(hash-tests crypto ethash)
|
target_link_libraries(hash-tests crypto ethash)
|
||||||
target_link_libraries(hash-target-tests crypto currency_core ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
target_link_libraries(hash-target-tests crypto currency_core ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
|
||||||
|
|
@ -48,11 +46,10 @@ if(NOT MSVC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
add_custom_target(tests DEPENDS coretests difficulty hash performance_tests unit_tests)
|
add_custom_target(tests DEPENDS coretests hash performance_tests unit_tests)
|
||||||
set_property(TARGET db_tests coretests crypto-tests functional_tests difficulty-tests gtest gtest_main hash-tests hash-target-tests performance_tests unit_tests tests net_load_tests_clt net_load_tests_srv PROPERTY FOLDER "tests")
|
set_property(TARGET db_tests coretests crypto-tests functional_tests gtest gtest_main hash-tests hash-target-tests performance_tests unit_tests tests net_load_tests_clt net_load_tests_srv PROPERTY FOLDER "tests")
|
||||||
|
|
||||||
add_test(crypto crypto-tests ${CMAKE_CURRENT_SOURCE_DIR}/crypto/tests.txt)
|
add_test(crypto crypto-tests ${CMAKE_CURRENT_SOURCE_DIR}/crypto/tests.txt)
|
||||||
# TODO fix this test -> #add_test(difficulty difficulty-tests ${CMAKE_CURRENT_SOURCE_DIR}/difficulty/data.txt)
|
|
||||||
foreach(hash IN ITEMS fast tree)
|
foreach(hash IN ITEMS fast tree)
|
||||||
add_test(hash-${hash} hash-tests ${hash} ${CMAKE_CURRENT_SOURCE_DIR}/hash/tests-${hash}.txt)
|
add_test(hash-${hash} hash-tests ${hash} ${CMAKE_CURRENT_SOURCE_DIR}/hash/tests-${hash}.txt)
|
||||||
endforeach(hash)
|
endforeach(hash)
|
||||||
|
|
@ -65,6 +62,6 @@ add_test(coretests coretests)
|
||||||
if(MSVC AND USE_PCH)
|
if(MSVC AND USE_PCH)
|
||||||
set_property(TARGET coretests APPEND_STRING PROPERTY COMPILE_FLAGS " /Yuchaingen.h /Zm1000")
|
set_property(TARGET coretests APPEND_STRING PROPERTY COMPILE_FLAGS " /Yuchaingen.h /Zm1000")
|
||||||
set_property(SOURCE "core_tests/chaingen.cpp" APPEND_STRING PROPERTY COMPILE_FLAGS " /Ycchaingen.h /Zm1000")
|
set_property(SOURCE "core_tests/chaingen.cpp" APPEND_STRING PROPERTY COMPILE_FLAGS " /Ycchaingen.h /Zm1000")
|
||||||
set_property(TARGET coretests difficulty-tests functional_tests hash-target-tests performance_tests unit_tests APPEND_STRING PROPERTY LINK_FLAGS "$(MSBuildProjectDirectory)/../src/$(ConfigurationName)/stdafx.obj")
|
set_property(TARGET coretests functional_tests hash-target-tests performance_tests unit_tests APPEND_STRING PROPERTY LINK_FLAGS "$(MSBuildProjectDirectory)/../src/$(ConfigurationName)/stdafx.obj")
|
||||||
set_property(TARGET db_tests APPEND_STRING PROPERTY LINK_FLAGS "$(MSBuildProjectDirectory)/../../src/$(ConfigurationName)/stdafx.obj")
|
set_property(TARGET db_tests APPEND_STRING PROPERTY LINK_FLAGS "$(MSBuildProjectDirectory)/../../src/$(ConfigurationName)/stdafx.obj")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,121 +0,0 @@
|
||||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
|
||||||
// Distributed under the MIT/X11 software license, see the accompanying
|
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "currency_core/currency_config.h"
|
|
||||||
#include "currency_core/difficulty.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#define DEFAULT_TEST_DIFFICULTY_TARGET 120
|
|
||||||
|
|
||||||
int test_big_difficulties(const char* dataFile)
|
|
||||||
{
|
|
||||||
vector<uint64_t> timestamps;
|
|
||||||
vector<currency::wide_difficulty_type> cumulative_difficulties;
|
|
||||||
fstream data(dataFile, fstream::in);
|
|
||||||
data.exceptions(fstream::badbit);
|
|
||||||
data.clear(data.rdstate());
|
|
||||||
uint64_t timestamp;
|
|
||||||
currency::wide_difficulty_type difficulty, cumulative_difficulty = 0;
|
|
||||||
size_t n = 0;
|
|
||||||
while (data >> timestamp >> difficulty) {
|
|
||||||
size_t begin, end;
|
|
||||||
if (n < DIFFICULTY_WINDOW + DIFFICULTY_LAG) {
|
|
||||||
begin = 0;
|
|
||||||
end = min(n, (size_t) DIFFICULTY_WINDOW);
|
|
||||||
} else {
|
|
||||||
end = n - DIFFICULTY_LAG;
|
|
||||||
begin = end - DIFFICULTY_WINDOW;
|
|
||||||
}
|
|
||||||
auto stamps = vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end);
|
|
||||||
auto cumulative_diffs = vector<currency::wide_difficulty_type>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end);
|
|
||||||
currency::wide_difficulty_type res = currency::next_difficulty(
|
|
||||||
stamps,
|
|
||||||
cumulative_diffs,
|
|
||||||
DEFAULT_TEST_DIFFICULTY_TARGET
|
|
||||||
);
|
|
||||||
if (res != difficulty) {
|
|
||||||
cerr << "Wrong wide difficulty for block " << n << endl
|
|
||||||
<< "Expected: " << difficulty << endl
|
|
||||||
<< "Found: " << res << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
timestamps.push_back(timestamp);
|
|
||||||
cumulative_difficulties.push_back(cumulative_difficulty += difficulty);
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
if (!data.eof()) {
|
|
||||||
data.clear(fstream::badbit);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
if (argc < 2) {
|
|
||||||
cerr << "Wrong arguments" << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if(argc == 3 && strcmp(argv[1], "/b") == 0)
|
|
||||||
{
|
|
||||||
return test_big_difficulties(argv[2]);
|
|
||||||
}
|
|
||||||
vector<uint64_t> timestamps, cumulative_difficulties;
|
|
||||||
vector<currency::wide_difficulty_type> wide_cumulative_difficulties;
|
|
||||||
fstream data(argv[1], fstream::in);
|
|
||||||
data.exceptions(fstream::badbit);
|
|
||||||
data.clear(data.rdstate());
|
|
||||||
uint64_t timestamp, difficulty, cumulative_difficulty = 0;
|
|
||||||
currency::wide_difficulty_type wide_cumulative_difficulty = 0;
|
|
||||||
size_t n = 0;
|
|
||||||
while (data >> timestamp >> difficulty) {
|
|
||||||
size_t begin, end;
|
|
||||||
if (n < DIFFICULTY_WINDOW + DIFFICULTY_LAG) {
|
|
||||||
begin = 0;
|
|
||||||
end = min(n, (size_t) DIFFICULTY_WINDOW);
|
|
||||||
} else {
|
|
||||||
end = n - DIFFICULTY_LAG;
|
|
||||||
begin = end - DIFFICULTY_WINDOW;
|
|
||||||
}
|
|
||||||
uint64_t res = currency::next_difficulty_old(
|
|
||||||
vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
|
|
||||||
vector<uint64_t>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
|
|
||||||
if (res != difficulty) {
|
|
||||||
cerr << "Wrong difficulty for block " << n << endl
|
|
||||||
<< "Expected: " << difficulty << endl
|
|
||||||
<< "Found: " << res << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
auto stamps = vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end);
|
|
||||||
auto cumulative_diffs = vector<currency::wide_difficulty_type>(wide_cumulative_difficulties.begin() + begin, wide_cumulative_difficulties.begin() + end);
|
|
||||||
currency::wide_difficulty_type wide_res = currency::next_difficulty(
|
|
||||||
stamps,
|
|
||||||
cumulative_diffs,
|
|
||||||
DEFAULT_TEST_DIFFICULTY_TARGET
|
|
||||||
);
|
|
||||||
if (wide_res.convert_to<uint64_t>() != res) {
|
|
||||||
cerr << "Wrong wide difficulty for block " << n << endl
|
|
||||||
<< "Expected: " << res << endl
|
|
||||||
<< "Found: " << wide_res << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
timestamps.push_back(timestamp);
|
|
||||||
cumulative_difficulties.push_back(cumulative_difficulty += difficulty);
|
|
||||||
wide_cumulative_difficulties.push_back(wide_cumulative_difficulty += difficulty);
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
if (!data.eof()) {
|
|
||||||
data.clear(fstream::badbit);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
from random import randint
|
|
||||||
|
|
||||||
DIFFICULTY_TARGET = 120
|
|
||||||
DIFFICULTY_WINDOW = 720
|
|
||||||
DIFFICULTY_LAG = 15
|
|
||||||
DIFFICULTY_CUT = 60
|
|
||||||
|
|
||||||
def difficulty():
|
|
||||||
times = []
|
|
||||||
diffs = []
|
|
||||||
while True:
|
|
||||||
if len(times) <= 1:
|
|
||||||
diff = 1
|
|
||||||
else:
|
|
||||||
begin = max(len(times) - DIFFICULTY_WINDOW - DIFFICULTY_LAG, 0)
|
|
||||||
end = min(begin + DIFFICULTY_WINDOW, len(times))
|
|
||||||
length = end - begin
|
|
||||||
assert length >= 2
|
|
||||||
if length <= DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT:
|
|
||||||
cut_begin = 0
|
|
||||||
cut_end = length
|
|
||||||
else:
|
|
||||||
excess = length - (DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT)
|
|
||||||
cut_begin = (excess + 1) // 2
|
|
||||||
cut_end = length - excess // 2
|
|
||||||
assert cut_begin + 2 <= cut_end
|
|
||||||
wnd = times[begin:end]
|
|
||||||
wnd.sort()
|
|
||||||
dtime = wnd[cut_end - 1] - wnd[cut_begin]
|
|
||||||
dtime = max(dtime, 1)
|
|
||||||
ddiff = sum(diffs[begin + cut_begin + 1:begin + cut_end])
|
|
||||||
diff = (ddiff * DIFFICULTY_TARGET + dtime - 1) // dtime
|
|
||||||
times.append((yield diff))
|
|
||||||
diffs.append(diff)
|
|
||||||
|
|
||||||
time = 1000
|
|
||||||
gen = difficulty()
|
|
||||||
diff = next(gen)
|
|
||||||
for i in range(100000):
|
|
||||||
power = 100 if i < 10000 else 100000000 if i < 500 else 1000000000000 if i < 1000 else 1000000000000000 if i < 2000 else 10000000000000000000 if i < 4000 else 1000000000000000000000000
|
|
||||||
time += randint(-diff // power - 10, 3 * diff // power + 10)
|
|
||||||
print(time, diff)
|
|
||||||
diff = gen.send(time)
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
from random import randint
|
|
||||||
|
|
||||||
DIFFICULTY_TARGET = 120
|
|
||||||
DIFFICULTY_WINDOW = 720
|
|
||||||
DIFFICULTY_LAG = 15
|
|
||||||
DIFFICULTY_CUT = 60
|
|
||||||
|
|
||||||
def difficulty():
|
|
||||||
times = []
|
|
||||||
diffs = []
|
|
||||||
while True:
|
|
||||||
if len(times) <= 1:
|
|
||||||
diff = 1
|
|
||||||
else:
|
|
||||||
begin = max(len(times) - DIFFICULTY_WINDOW - DIFFICULTY_LAG, 0)
|
|
||||||
end = min(begin + DIFFICULTY_WINDOW, len(times))
|
|
||||||
length = end - begin
|
|
||||||
assert length >= 2
|
|
||||||
if length <= DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT:
|
|
||||||
cut_begin = 0
|
|
||||||
cut_end = length
|
|
||||||
else:
|
|
||||||
excess = length - (DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT)
|
|
||||||
cut_begin = (excess + 1) // 2
|
|
||||||
cut_end = length - excess // 2
|
|
||||||
assert cut_begin + 2 <= cut_end
|
|
||||||
wnd = times[begin:end]
|
|
||||||
wnd.sort()
|
|
||||||
dtime = wnd[cut_end - 1] - wnd[cut_begin]
|
|
||||||
dtime = max(dtime, 1)
|
|
||||||
ddiff = sum(diffs[begin + cut_begin + 1:begin + cut_end])
|
|
||||||
diff = (ddiff * DIFFICULTY_TARGET + dtime - 1) // dtime
|
|
||||||
times.append((yield diff))
|
|
||||||
diffs.append(diff)
|
|
||||||
|
|
||||||
time = 1000
|
|
||||||
gen = difficulty()
|
|
||||||
diff = next(gen)
|
|
||||||
for i in range(100000):
|
|
||||||
power = 100 if i < 10000 else 100000000 if i < 500 else 1000000000000 if i < 1000 else 1000000000000000 if i < 2000 else 10000000000000000000 if i < 4000 else 1000000000000000000000000
|
|
||||||
time += randint(-diff // power - 10, 3 * diff // power + 10)
|
|
||||||
if(time < 0):
|
|
||||||
time = -time
|
|
||||||
if(i // 2 * 2 == i):
|
|
||||||
time = time // 3 + 1
|
|
||||||
print(time, diff)
|
|
||||||
diff = gen.send(time)
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
from random import randint
|
|
||||||
|
|
||||||
DIFFICULTY_TARGET = 120
|
|
||||||
DIFFICULTY_WINDOW = 720
|
|
||||||
DIFFICULTY_LAG = 15
|
|
||||||
DIFFICULTY_CUT = 60
|
|
||||||
|
|
||||||
UINT_MAX = (1 << 64) - 1
|
|
||||||
|
|
||||||
def difficulty():
|
|
||||||
times = []
|
|
||||||
diffs = []
|
|
||||||
while True:
|
|
||||||
if len(times) <= 1:
|
|
||||||
diff = 1
|
|
||||||
else:
|
|
||||||
begin = max(len(times) - DIFFICULTY_WINDOW - DIFFICULTY_LAG, 0)
|
|
||||||
end = min(begin + DIFFICULTY_WINDOW, len(times))
|
|
||||||
length = end - begin
|
|
||||||
assert length >= 2
|
|
||||||
if length <= DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT:
|
|
||||||
cut_begin = 0
|
|
||||||
cut_end = length
|
|
||||||
else:
|
|
||||||
excess = length - (DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT)
|
|
||||||
cut_begin = (excess + 1) // 2
|
|
||||||
cut_end = length - excess // 2
|
|
||||||
assert cut_begin + 2 <= cut_end
|
|
||||||
wnd = times[begin:end]
|
|
||||||
wnd.sort()
|
|
||||||
dtime = wnd[cut_end - 1] - wnd[cut_begin]
|
|
||||||
assert 0 <= dtime <= UINT_MAX
|
|
||||||
dtime = max(dtime, 1)
|
|
||||||
ddiff = sum(diffs[begin + cut_begin + 1:begin + cut_end])
|
|
||||||
assert 0 < ddiff <= UINT_MAX
|
|
||||||
assert dtime <= ddiff * DIFFICULTY_TARGET + dtime - 1 <= UINT_MAX
|
|
||||||
diff = (ddiff * DIFFICULTY_TARGET + dtime - 1) // dtime
|
|
||||||
assert 0 < diff <= UINT_MAX
|
|
||||||
times.append((yield diff))
|
|
||||||
diffs.append(diff)
|
|
||||||
|
|
||||||
time = 1000
|
|
||||||
gen = difficulty()
|
|
||||||
diff = next(gen)
|
|
||||||
for i in range(1000):
|
|
||||||
power = 10 if i < 100 else 10000 if i < 500 else 1000000
|
|
||||||
time += randint(-diff // power - 10, 3 * diff // power + 10)
|
|
||||||
assert 0 <= time <= UINT_MAX
|
|
||||||
print(time, diff)
|
|
||||||
diff = gen.send(time)
|
|
||||||
Loading…
Add table
Reference in a new issue