diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core_tests/chaingen_main.cpp | 12 | ||||
-rw-r--r-- | tests/performance_tests/cn_slow_hash.h | 45 | ||||
-rw-r--r-- | tests/performance_tests/main.cpp | 3 | ||||
-rw-r--r-- | tests/unit_tests/checkpoints.cpp | 140 |
4 files changed, 194 insertions, 6 deletions
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)); +} |