aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt14
-rw-r--r--tests/core_proxy/core_proxy.h1
-rw-r--r--tests/core_tests/chaingen_main.cpp12
-rw-r--r--tests/performance_tests/cn_slow_hash.h45
-rw-r--r--tests/performance_tests/main.cpp3
-rw-r--r--tests/unit_tests/checkpoints.cpp140
6 files changed, 202 insertions, 13 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 855b4d808..1d0c91dc9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -31,16 +31,16 @@ add_executable(unit_tests ${UNIT_TESTS})
add_executable(net_load_tests_clt net_load_tests/clt.cpp)
add_executable(net_load_tests_srv net_load_tests/srv.cpp)
-target_link_libraries(core_proxy cryptonote_core common crypto upnpc-static ${Boost_LIBRARIES})
-target_link_libraries(coretests cryptonote_core common crypto ${Boost_LIBRARIES})
+target_link_libraries(core_proxy cryptonote_core common crypto upnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+target_link_libraries(coretests cryptonote_core common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
target_link_libraries(difficulty-tests cryptonote_core)
-target_link_libraries(functional_tests cryptonote_core wallet common crypto ${Boost_LIBRARIES})
+target_link_libraries(functional_tests cryptonote_core wallet common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
target_link_libraries(hash-tests crypto)
target_link_libraries(hash-target-tests crypto cryptonote_core)
-target_link_libraries(performance_tests cryptonote_core common crypto ${Boost_LIBRARIES})
-target_link_libraries(unit_tests cryptonote_core common crypto gtest_main ${Boost_LIBRARIES})
-target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${Boost_LIBRARIES})
-target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${Boost_LIBRARIES})
+target_link_libraries(performance_tests cryptonote_core common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+target_link_libraries(unit_tests cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
if(NOT MSVC)
set_property(TARGET gtest gtest_main unit_tests net_load_tests_clt net_load_tests_srv APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-sign-compare")
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index d5be53f1d..60f0b3c2d 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -41,6 +41,7 @@ namespace tests
public:
void on_synchronized(){}
uint64_t get_current_blockchain_height(){return 1;}
+ void set_target_blockchain_height(uint64_t) {}
bool init(const boost::program_options::variables_map& vm);
bool deinit(){return true;}
bool get_short_chain_history(std::list<crypto::hash>& ids);
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index c575f9272..e6f287d74 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -21,15 +21,15 @@ namespace
int main(int argc, char* argv[])
{
TRY_ENTRY();
- string_tools::set_module_name_and_folder(argv[0]);
+ epee::string_tools::set_module_name_and_folder(argv[0]);
//set up logging options
- log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3);
- log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
+ epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3);
+ epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
- log_space::log_singletone::add_logger(LOGGER_FILE,
- log_space::log_singletone::get_default_log_file().c_str(),
- log_space::log_singletone::get_default_log_folder().c_str());
+ epee::log_space::log_singletone::add_logger(LOGGER_FILE,
+ epee::log_space::log_singletone::get_default_log_file().c_str(),
+ epee::log_space::log_singletone::get_default_log_folder().c_str());
po::options_description desc_options("Allowed options");
command_line::add_arg(desc_options, command_line::arg_help);
diff --git a/tests/performance_tests/cn_slow_hash.h b/tests/performance_tests/cn_slow_hash.h
new file mode 100644
index 000000000..ec001326e
--- /dev/null
+++ b/tests/performance_tests/cn_slow_hash.h
@@ -0,0 +1,45 @@
+// 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.
+
+#pragma once
+
+#include "crypto/crypto.h"
+#include "cryptonote_core/cryptonote_basic.h"
+
+class test_cn_slow_hash
+{
+public:
+ static const size_t loop_count = 10;
+
+#pragma pack(push, 1)
+ struct data_t
+ {
+ char data[13];
+ };
+#pragma pack(pop)
+
+ static_assert(13 == sizeof(data_t), "Invalid structure size");
+
+ bool init()
+ {
+ if (!epee::string_tools::hex_to_pod("63617665617420656d70746f72", m_data))
+ return false;
+
+ if (!epee::string_tools::hex_to_pod("bbec2cacf69866a8e740380fe7b818fc78f8571221742d729d9d02d7f8989b87", m_expected_hash))
+ return false;
+
+ return true;
+ }
+
+ bool test()
+ {
+ crypto::hash hash;
+ crypto::cn_slow_hash(&m_data, sizeof(m_data), hash);
+ return hash == m_expected_hash;
+ }
+
+private:
+ data_t m_data;
+ crypto::hash m_expected_hash;
+};
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index 2ad503b83..72ee2ca6c 100644
--- a/tests/performance_tests/main.cpp
+++ b/tests/performance_tests/main.cpp
@@ -8,6 +8,7 @@
// tests
#include "construct_tx.h"
#include "check_ring_signature.h"
+#include "cn_slow_hash.h"
#include "derive_public_key.h"
#include "derive_secret_key.h"
#include "generate_key_derivation.h"
@@ -56,6 +57,8 @@ int main(int argc, char** argv)
TEST_PERFORMANCE0(test_derive_public_key);
TEST_PERFORMANCE0(test_derive_secret_key);
+ TEST_PERFORMANCE0(test_cn_slow_hash);
+
std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl;
return 0;
diff --git a/tests/unit_tests/checkpoints.cpp b/tests/unit_tests/checkpoints.cpp
new file mode 100644
index 000000000..0d7bd4de9
--- /dev/null
+++ b/tests/unit_tests/checkpoints.cpp
@@ -0,0 +1,140 @@
+// 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 "gtest/gtest.h"
+
+#include "cryptonote_core/checkpoints.cpp"
+
+using namespace cryptonote;
+
+
+TEST(checkpoints_is_alternative_block_allowed, handles_empty_checkpoins)
+{
+ checkpoints cp;
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(0, 0));
+
+ ASSERT_TRUE(cp.is_alternative_block_allowed(1, 1));
+ ASSERT_TRUE(cp.is_alternative_block_allowed(1, 9));
+ ASSERT_TRUE(cp.is_alternative_block_allowed(9, 1));
+}
+
+TEST(checkpoints_is_alternative_block_allowed, handles_one_checkpoint)
+{
+ checkpoints cp;
+ cp.add_checkpoint(5, "0000000000000000000000000000000000000000000000000000000000000000");
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(0, 0));
+
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 1));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 4));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 9));
+
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 1));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 4));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 9));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(5, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(5, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(5, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(5, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(5, 9));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(6, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(6, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(6, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(6, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(6, 9));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(9, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(9, 9));
+}
+
+TEST(checkpoints_is_alternative_block_allowed, handles_two_and_more_checkpoints)
+{
+ checkpoints cp;
+ cp.add_checkpoint(5, "0000000000000000000000000000000000000000000000000000000000000000");
+ cp.add_checkpoint(9, "0000000000000000000000000000000000000000000000000000000000000000");
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(0, 0));
+
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 1));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 4));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 8));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(1, 11));
+
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 1));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 4));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 8));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(4, 11));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(5, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(5, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(5, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(5, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(5, 8));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(5, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(5, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(5, 11));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(6, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(6, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(6, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(6, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(6, 8));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(6, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(6, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(6, 11));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(8, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(8, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(8, 5));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(8, 6));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(8, 8));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(8, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(8, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(8, 11));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 5));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 6));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 8));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(9, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(9, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(9, 11));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(10, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(10, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(10, 5));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(10, 6));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(10, 8));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(10, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(10, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(10, 11));
+
+ ASSERT_FALSE(cp.is_alternative_block_allowed(11, 1));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(11, 4));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(11, 5));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(11, 6));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(11, 8));
+ ASSERT_FALSE(cp.is_alternative_block_allowed(11, 9));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(11, 10));
+ ASSERT_TRUE (cp.is_alternative_block_allowed(11, 11));
+}