diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core_proxy/core_proxy.cpp | 13 | ||||
-rw-r--r-- | tests/core_proxy/core_proxy.h | 8 | ||||
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/unit_tests/ban.cpp | 8 | ||||
-rw-r--r-- | tests/unit_tests/block_queue.cpp | 87 | ||||
-rw-r--r-- | tests/unit_tests/hardfork.cpp | 3 | ||||
-rw-r--r-- | tests/unit_tests/mnemonics.cpp | 4 |
7 files changed, 121 insertions, 4 deletions
diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index c12b8e9a7..366937e1d 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -185,6 +185,19 @@ bool tests::proxy_core::handle_incoming_tx(const cryptonote::blobdata& tx_blob, return true; } +bool tests::proxy_core::handle_incoming_txs(const std::list<blobdata>& tx_blobs, std::vector<tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) +{ + tvc.resize(tx_blobs.size()); + size_t i = 0; + for (const auto &tx_blob: tx_blobs) + { + if (!handle_incoming_tx(tx_blob, tvc[i], keeped_by_block, relayed, do_not_relay)) + return false; + ++i; + } + return true; +} + bool tests::proxy_core::handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate) { block b = AUTO_VAL_INIT(b); diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h index 58645edb5..85518612a 100644 --- a/tests/core_proxy/core_proxy.h +++ b/tests/core_proxy/core_proxy.h @@ -66,6 +66,7 @@ namespace tests public: void on_synchronized(){} + void safesyncmode(const bool){} uint64_t get_current_blockchain_height(){return 1;} void set_target_blockchain_height(uint64_t) {} bool init(const boost::program_options::variables_map& vm); @@ -75,6 +76,7 @@ namespace tests bool have_block(const crypto::hash& id); bool get_blockchain_top(uint64_t& height, crypto::hash& top_id); bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); + bool handle_incoming_txs(const std::list<cryptonote::blobdata>& tx_blobs, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true); void pause_mine(){} void resume_mine(){} @@ -87,7 +89,7 @@ namespace tests bool prepare_handle_incoming_blocks(const std::list<cryptonote::block_complete_entry> &blocks) { return true; } bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; } uint64_t get_target_blockchain_height() const { return 1; } - size_t get_block_sync_size() const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; } + size_t get_block_sync_size(uint64_t height) const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; } virtual void on_transaction_relayed(const cryptonote::blobdata& tx) {} bool get_testnet() const { return false; } bool get_pool_transaction(const crypto::hash& id, cryptonote::blobdata& tx_blob) const { return false; } @@ -95,5 +97,9 @@ namespace tests bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata, cryptonote::block>>& blocks, std::list<cryptonote::blobdata>& txs) const { return false; } bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<cryptonote::transaction>& txs, std::list<crypto::hash>& missed_txs) const { return false; } bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; } + uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; } + uint8_t get_hard_fork_version(uint64_t height) const { return 0; } + cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; } + bool fluffy_blocks_enabled() const { return false; } }; } diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index da95a97a9..2f62dc2aa 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -31,6 +31,7 @@ set(unit_tests_sources ban.cpp base58.cpp blockchain_db.cpp + block_queue.cpp block_reward.cpp canonical_amounts.cpp chacha8.cpp @@ -72,6 +73,7 @@ add_executable(unit_tests target_link_libraries(unit_tests PRIVATE ringct + cryptonote_protocol cryptonote_core blockchain_db rpc diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp index 432d5bbf3..82ff058b1 100644 --- a/tests/unit_tests/ban.cpp +++ b/tests/unit_tests/ban.cpp @@ -43,6 +43,7 @@ class test_core { public: void on_synchronized(){} + void safesyncmode(const bool){} uint64_t get_current_blockchain_height() const {return 1;} void set_target_blockchain_height(uint64_t) {} bool init(const boost::program_options::variables_map& vm) {return true ;} @@ -52,6 +53,7 @@ public: bool have_block(const crypto::hash& id) const {return true;} bool get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=cryptonote::null_hash;return true;} bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; } + bool handle_incoming_txs(const std::list<cryptonote::blobdata>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; } bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; } void pause_mine(){} void resume_mine(){} @@ -64,7 +66,7 @@ public: bool prepare_handle_incoming_blocks(const std::list<cryptonote::block_complete_entry> &blocks) { return true; } bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; } uint64_t get_target_blockchain_height() const { return 1; } - size_t get_block_sync_size() const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; } + size_t get_block_sync_size(uint64_t height) const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; } virtual void on_transaction_relayed(const cryptonote::blobdata& tx) {} bool get_testnet() const { return false; } bool get_pool_transaction(const crypto::hash& id, cryptonote::blobdata& tx_blob) const { return false; } @@ -72,6 +74,10 @@ public: bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata, cryptonote::block>>& blocks, std::list<cryptonote::blobdata>& txs) const { return false; } bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<cryptonote::transaction>& txs, std::list<crypto::hash>& missed_txs) const { return false; } bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; } + uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; } + uint8_t get_hard_fork_version(uint64_t height) const { return 0; } + cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; } + bool fluffy_blocks_enabled() const { return false; } }; typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_core>> Server; diff --git a/tests/unit_tests/block_queue.cpp b/tests/unit_tests/block_queue.cpp new file mode 100644 index 000000000..f05d5487a --- /dev/null +++ b/tests/unit_tests/block_queue.cpp @@ -0,0 +1,87 @@ +// Copyright (c) 2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <boost/uuid/uuid.hpp> +#include "gtest/gtest.h" +#include "crypto/crypto.h" +#include "cryptonote_protocol/cryptonote_protocol_defs.h" +#include "cryptonote_protocol/block_queue.h" + +static const boost::uuids::uuid &uuid1() +{ + static const boost::uuids::uuid uuid = crypto::rand<boost::uuids::uuid>(); + return uuid; +} + +static const boost::uuids::uuid &uuid2() +{ + static const boost::uuids::uuid uuid = crypto::rand<boost::uuids::uuid>(); + return uuid; +} + +TEST(block_queue, empty) +{ + cryptonote::block_queue bq; + ASSERT_EQ(bq.get_max_block_height(), 0); +} + +TEST(block_queue, add_stepwise) +{ + cryptonote::block_queue bq; + bq.add_blocks(0, 200, uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 199); + bq.add_blocks(200, 200, uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 399); + bq.add_blocks(401, 200, uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 600); + bq.add_blocks(400, 10, uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 600); +} + +TEST(block_queue, flush_uuid) +{ + cryptonote::block_queue bq; + + bq.add_blocks(0, 200, uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 199); + bq.add_blocks(200, 200, uuid2()); + ASSERT_EQ(bq.get_max_block_height(), 399); + bq.flush_spans(uuid2()); + ASSERT_EQ(bq.get_max_block_height(), 199); + bq.flush_spans(uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 0); + + bq.add_blocks(0, 200, uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 199); + bq.add_blocks(200, 200, uuid2()); + ASSERT_EQ(bq.get_max_block_height(), 399); + bq.flush_spans(uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 399); + bq.add_blocks(0, 200, uuid1()); + ASSERT_EQ(bq.get_max_block_height(), 399); +} diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index febf8b2f7..c30feb461 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -31,7 +31,7 @@ #include <algorithm> #include "gtest/gtest.h" -#include "blockchain_db/lmdb/db_lmdb.h" +#include "blockchain_db/blockchain_db.h" #include "cryptonote_basic/cryptonote_format_utils.h" #include "cryptonote_basic/hardfork.h" @@ -47,6 +47,7 @@ public: virtual void open(const std::string& filename, const int db_flags = 0) { } virtual void close() {} virtual void sync() {} + virtual void safesyncmode(const bool onoff) {} virtual void reset() {} virtual std::vector<std::string> get_filenames() const { return std::vector<std::string>(); } virtual std::string get_db_name() const { return std::string(); } diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp index 553dcfb86..05894adf4 100644 --- a/tests/unit_tests/mnemonics.cpp +++ b/tests/unit_tests/mnemonics.cpp @@ -44,6 +44,7 @@ #include "mnemonics/russian.h" #include "mnemonics/french.h" #include "mnemonics/dutch.h" +#include "mnemonics/esperanto.h" #include "mnemonics/english_old.h" #include "mnemonics/language_base.h" #include "mnemonics/singleton.h" @@ -165,7 +166,8 @@ TEST(mnemonics, all_languages) Language::Singleton<Language::Italian>::instance(), Language::Singleton<Language::Russian>::instance(), Language::Singleton<Language::French>::instance(), - Language::Singleton<Language::Dutch>::instance() + Language::Singleton<Language::Dutch>::instance(), + Language::Singleton<Language::Esperanto>::instance() }); for (std::vector<Language::Base*>::iterator it = languages.begin(); it != languages.end(); it++) |