From 0c545f614ac228bc141f2b4c3783230b198e92b0 Mon Sep 17 00:00:00 2001 From: jeffro256 Date: Wed, 17 Jan 2024 17:17:16 -0600 Subject: epee/test: remove levin_protocol_handler and core_proxy tests --- tests/CMakeLists.txt | 2 - tests/core_proxy/CMakeLists.txt | 49 ------- tests/core_proxy/core_proxy.cpp | 295 ---------------------------------------- tests/core_proxy/core_proxy.h | 119 ---------------- 4 files changed, 465 deletions(-) delete mode 100644 tests/core_proxy/CMakeLists.txt delete mode 100644 tests/core_proxy/core_proxy.cpp delete mode 100644 tests/core_proxy/core_proxy.h (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 736872b04..700039c90 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -83,7 +83,6 @@ else () add_subdirectory(crypto) add_subdirectory(functional_tests) add_subdirectory(performance_tests) - add_subdirectory(core_proxy) add_subdirectory(unit_tests) add_subdirectory(difficulty) add_subdirectory(block_weight) @@ -159,7 +158,6 @@ set(enabled_tests block_weight hash performance_tests - core_proxy fuzz unit_tests) diff --git a/tests/core_proxy/CMakeLists.txt b/tests/core_proxy/CMakeLists.txt deleted file mode 100644 index e0ee5d7f5..000000000 --- a/tests/core_proxy/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (c) 2014-2023, 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. - -set(core_proxy_sources - core_proxy.cpp) - -set(core_proxy_headers - core_proxy.h) - -monero_add_minimal_executable(core_proxy - ${core_proxy_sources} - ${core_proxy_headers}) -target_link_libraries(core_proxy - PRIVATE - cryptonote_core - cryptonote_protocol - p2p - version - epee - ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) -set_property(TARGET core_proxy - PROPERTY - FOLDER "tests") diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp deleted file mode 100644 index fa5de5b3a..000000000 --- a/tests/core_proxy/core_proxy.cpp +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright (c) 2014-2023, 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. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - -// node.cpp : Defines the entry point for the console application. -// - - -#include "include_base_utils.h" -#include "version.h" -#include -#include - -#include - -#include "common/command_line.h" -#include "console_handler.h" -#include "p2p/net_node.h" -#include "p2p/net_node.inl" -//#include "cryptonote_core/cryptonote_core.h" -#include "cryptonote_protocol/cryptonote_protocol_handler.h" -#include "cryptonote_protocol/cryptonote_protocol_handler.inl" -#include "core_proxy.h" - -#if defined(WIN32) -#include -#endif - -namespace po = boost::program_options; -using namespace std; -using namespace epee; -using namespace cryptonote; -using namespace crypto; - - -BOOST_CLASS_VERSION(nodetool::node_server >, 1); - -int main(int argc, char* argv[]) -{ - -#ifdef WIN32 - _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); -#endif - - TRY_ENTRY(); - - tools::on_startup(); - string_tools::set_module_name_and_folder(argv[0]); - - //set up logging options - mlog_configure(mlog_get_default_log_path("core_proxy.log"), true); - mlog_set_log_level(2); - - - po::options_description desc("Allowed options"); - command_line::add_arg(desc, cryptonote::arg_data_dir); - nodetool::node_server >::init_options(desc); - - po::variables_map vm; - bool r = command_line::handle_error_helper(desc, [&]() - { - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - return true; - }); - if (!r) - return 1; - - MGINFO("Module folder: " << argv[0]); - MGINFO("Node starting ..."); - - - //create objects and link them - tests::proxy_core pr_core; - cryptonote::t_cryptonote_protocol_handler cprotocol(pr_core, NULL); - nodetool::node_server > p2psrv { - cprotocol - }; - cprotocol.set_p2p_endpoint(&p2psrv); - //pr_core.set_cryptonote_protocol(&cprotocol); - //daemon_cmmands_handler dch(p2psrv); - - //initialize objects - - MGINFO("Initializing p2p server..."); - bool res = p2psrv.init(vm); - CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize p2p server."); - MGINFO("P2p server initialized OK"); - - MGINFO("Initializing cryptonote protocol..."); - res = cprotocol.init(vm); - CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize cryptonote protocol."); - MGINFO("Cryptonote protocol initialized OK"); - - //initialize core here - MGINFO("Initializing proxy core..."); - res = pr_core.init(vm); - CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core"); - MGINFO("Core initialized OK"); - - MGINFO("Starting p2p net loop..."); - p2psrv.run(); - MGINFO("p2p net loop stopped"); - - //deinitialize components - MGINFO("Deinitializing core..."); - pr_core.deinit(); - MGINFO("Deinitializing cryptonote_protocol..."); - cprotocol.deinit(); - MGINFO("Deinitializing p2p..."); - p2psrv.deinit(); - - - //pr_core.set_cryptonote_protocol(NULL); - cprotocol.set_p2p_endpoint(NULL); - - - MGINFO("Node stopped."); - return 0; - - CATCH_ENTRY_L0("main", 1); -} - -/* -string tx2str(const cryptonote::transaction& tx, const cryptonote::hash256& tx_hash, const cryptonote::hash256& tx_prefix_hash, const cryptonote::blobdata& blob) { - stringstream ss; - - ss << "{" << endl; - ss << "\tversion:" << tx.version << endl; - ss << "\tunlock_time:" << tx.unlock_time << endl; - ss << "\t" - - return ss.str(); -}*/ - -bool tests::proxy_core::handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, cryptonote::relay_method tx_relay, bool relayed) { - if (tx_relay != cryptonote::relay_method::block) - return true; - - crypto::hash tx_hash = null_hash; - crypto::hash tx_prefix_hash = null_hash; - transaction tx; - - if (tx_blob.prunable_hash != crypto::null_hash) - { - cerr << "WRONG TRANSACTION, pruned blob rejected" << endl; - return false; - } - - if (!parse_and_validate_tx_from_blob(tx_blob.blob, tx, tx_hash, tx_prefix_hash)) { - cerr << "WRONG TRANSACTION BLOB, Failed to parse, rejected" << endl; - return false; - } - - cout << "TX " << endl << endl; - cout << tx_hash << endl; - cout << tx_prefix_hash << endl; - cout << tx_blob.blob.size() << endl; - //cout << string_tools::buff_to_hex_nodelimer(tx_blob) << endl << endl; - cout << obj_to_json_str(tx) << endl; - cout << endl << "ENDTX" << endl; - - return true; -} - -bool tests::proxy_core::handle_incoming_txs(const std::vector& tx_blobs, std::vector& tvc, cryptonote::relay_method tx_relay, bool relayed) -{ - tvc.resize(tx_blobs.size()); - size_t i = 0; - for (const auto &tx_blob: tx_blobs) - { - if (!handle_incoming_tx(tx_blob, tvc[i], tx_relay, relayed)) - return false; - ++i; - } - return true; -} - -bool tests::proxy_core::handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block_, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate) { - block b = AUTO_VAL_INIT(b); - - if(!parse_and_validate_block_from_blob(block_blob, b)) { - cerr << "Failed to parse and validate new block" << endl; - return false; - } - - crypto::hash h; - crypto::hash lh; - cout << "BLOCK" << endl << endl; - cout << (h = get_block_hash(b)) << endl; - cout << (lh = get_block_longhash(NULL, b, 0, 0)) << endl; - cout << get_transaction_hash(b.miner_tx) << endl; - cout << ::get_object_blobsize(b.miner_tx) << endl; - //cout << string_tools::buff_to_hex_nodelimer(block_blob) << endl; - cout << obj_to_json_str(b) << endl; - - cout << endl << "ENDBLOCK" << endl << endl; - - if (!add_block(h, lh, b, block_blob)) - return false; - - return true; -} - -bool tests::proxy_core::get_short_chain_history(std::list& ids) { - build_short_history(ids, m_lastblk); - return true; -} - -void tests::proxy_core::get_blockchain_top(uint64_t& height, crypto::hash& top_id) { - height = 0; - top_id = get_block_hash(m_genesis); -} - -bool tests::proxy_core::init(const boost::program_options::variables_map& /*vm*/) { - generate_genesis_block(m_genesis, config::GENESIS_TX, config::GENESIS_NONCE); - crypto::hash h = get_block_hash(m_genesis); - add_block(h, get_block_longhash(NULL, m_genesis, 0, 0), m_genesis, block_to_blob(m_genesis)); - return true; -} - -bool tests::proxy_core::have_block_unlocked(const crypto::hash& id, int *where) { - if (m_hash2blkidx.end() == m_hash2blkidx.find(id)) - return false; - if (where) *where = HAVE_BLOCK_MAIN_CHAIN; - return true; -} - -bool tests::proxy_core::have_block(const crypto::hash& id, int *where) { - return have_block_unlocked(id, where); -} - -void tests::proxy_core::build_short_history(std::list &m_history, const crypto::hash &m_start) { - m_history.push_front(get_block_hash(m_genesis)); - /*std::unordered_map::const_iterator cit = m_hash2blkidx.find(m_lastblk); - - do { - m_history.push_front(cit->first); - - size_t n = 1 << m_history.size(); - while (m_hash2blkidx.end() != cit && crypto::null_hash != cit->second.blk.prev_id && n > 0) { - n--; - cit = m_hash2blkidx.find(cit->second.blk.prev_id); - } - } while (m_hash2blkidx.end() != cit && get_block_hash(cit->second.blk) != cit->first);*/ -} - -bool tests::proxy_core::add_block(const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob) { - size_t height = 0; - - if (crypto::null_hash != _blk.prev_id) { - std::unordered_map::const_iterator cit = m_hash2blkidx.find(_blk.prev_id); - if (m_hash2blkidx.end() == cit) { - cerr << "ERROR: can't find previous block with id \"" << _blk.prev_id << "\"" << endl; - return false; - } - - height = cit->second.height + 1; - } - - m_known_block_list.push_back(_id); - - block_index bi(height, _id, _longhash, _blk, _blob, txes); - m_hash2blkidx.insert(std::make_pair(_id, bi)); - txes.clear(); - m_lastblk = _id; - - return true; -} diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h deleted file mode 100644 index f1f9bdb66..000000000 --- a/tests/core_proxy/core_proxy.h +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) 2014-2023, 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. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - -#pragma once - -#include - -#include "cryptonote_basic/cryptonote_basic_impl.h" -#include "cryptonote_basic/verification_context.h" -#include "cryptonote_core/i_core_events.h" -#include - -namespace tests -{ - struct block_index { - size_t height; - crypto::hash id; - crypto::hash longhash; - cryptonote::block blk; - cryptonote::blobdata blob; - std::list txes; - - block_index() : height(0), id(crypto::null_hash), longhash(crypto::null_hash) { } - block_index(size_t _height, const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob, const std::list &_txes) - : height(_height), id(_id), longhash(_longhash), blk(_blk), blob(_blob), txes(_txes) { } - }; - - class proxy_core : public cryptonote::i_core_events - { - cryptonote::block m_genesis; - std::list m_known_block_list; - std::unordered_map m_hash2blkidx; - - crypto::hash m_lastblk; - std::list txes; - - bool add_block(const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob); - void build_short_history(std::list &m_history, const crypto::hash &m_start); - - - public: - virtual bool is_synchronized() const final { return true; } - void on_synchronized(){} - void safesyncmode(const bool){} - virtual uint64_t get_current_blockchain_height() const final {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& ids); - bool have_block(const crypto::hash& id, int *where = NULL); - bool have_block_unlocked(const crypto::hash& id, int *where = NULL); - void get_blockchain_top(uint64_t& height, crypto::hash& top_id); - bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, cryptonote::relay_method tx_relay, bool relayed); - bool handle_incoming_txs(const std::vector& tx_blobs, std::vector& tvc, cryptonote::relay_method tx_relay, bool relayed); - bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true); - void pause_mine(){} - void resume_mine(){} - bool on_idle(){return true;} - bool find_blockchain_supplement(const std::list& qblock_ids, bool clip_pruned, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;} - bool handle_get_objects(cryptonote::NOTIFY_REQUEST_GET_OBJECTS::request& arg, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request& rsp, cryptonote::cryptonote_connection_context& context){return true;} - cryptonote::Blockchain &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class proxy_core."); } - bool get_test_drop_download() {return true;} - bool get_test_drop_download_height() {return true;} - bool prepare_handle_incoming_blocks(const std::vector &blocks_entry, std::vector &blocks) { return true; } - bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; } - bool update_checkpoints(const bool skip_dns = false) { return true; } - uint64_t get_target_blockchain_height() const { return 1; } - size_t get_block_sync_size(uint64_t height) const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; } - virtual void on_transactions_relayed(epee::span tx_blobs, cryptonote::relay_method tx_relay) {} - cryptonote::network_type get_nettype() const { return cryptonote::MAINNET; } - bool get_pool_transaction(const crypto::hash& id, cryptonote::blobdata& tx_blob, cryptonote::relay_category tx_category) const { return false; } - bool pool_has_tx(const crypto::hash &txid) const { return false; } - bool get_blocks(uint64_t start_offset, size_t count, std::vector>& blocks, std::vector& txs) const { return false; } - bool get_transactions(const std::vector& txs_ids, std::vector& txs, std::vector& 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() const { return 0; } - 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; } - uint64_t get_earliest_ideal_height_for_version(uint8_t version) const { return 0; } - cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; } - bool fluffy_blocks_enabled() const { return false; } - uint64_t prevalidate_block_hashes(uint64_t height, const std::vector &hashes, const std::vector &weights) { return 0; } - bool has_block_weights(uint64_t height, uint64_t nblocks) const { return false; } - bool is_within_compiled_block_hash_area(uint64_t height) const { return false; } - bool pad_transactions() const { return false; } - uint32_t get_blockchain_pruning_seed() const { return 0; } - bool prune_blockchain(uint32_t pruning_seed) const { return true; } - bool get_txpool_complement(const std::vector &hashes, std::vector &txes) { return false; } - bool get_pool_transaction_hashes(std::vector& txs, bool include_unrelayed_txes = true) const { return false; } - crypto::hash get_block_id_by_height(uint64_t height) const { return crypto::null_hash; } - }; -} -- cgit v1.2.3