diff options
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.cpp | 30 | ||||
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.h | 1 | ||||
-rw-r--r-- | src/blockchain_db/testdb.h | 201 | ||||
-rw-r--r-- | src/daemon/main.cpp | 6 | ||||
-rw-r--r-- | tests/core_tests/bulletproofs.h | 2 | ||||
-rw-r--r-- | tests/core_tests/chaingen.cpp | 18 | ||||
-rw-r--r-- | tests/core_tests/chaingen.h | 85 | ||||
-rw-r--r-- | tests/unit_tests/ban.cpp | 13 | ||||
-rw-r--r-- | tests/unit_tests/hardfork.cpp | 12 |
9 files changed, 147 insertions, 221 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index 3eb24494f..d138a1e7e 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -1654,36 +1654,6 @@ tx_out_index BlockchainBDB::get_output_tx_and_index(const uint64_t& amount, cons return indices[0]; } -std::vector<uint64_t> BlockchainBDB::get_tx_output_indices(const crypto::hash& h) const -{ - LOG_PRINT_L3("BlockchainBDB::" << __func__); - check_open(); - std::vector<uint64_t> index_vec; - - bdb_cur cur(DB_DEFAULT_TX, m_tx_outputs); - - Dbt_copy<crypto::hash> k(h); - Dbt_copy<uint32_t> v; - auto result = cur->get(&k, &v, DB_SET); - if (result == DB_NOTFOUND) - throw1(OUTPUT_DNE("Attempting to get an output by tx hash and tx index, but output not found")); - else if (result) - throw0(DB_ERROR("DB error attempting to get an output")); - - db_recno_t num_elems = 0; - cur->count(&num_elems, 0); - - for (uint64_t i = 0; i < num_elems; ++i) - { - index_vec.push_back(v); - cur->get(&k, &v, DB_NEXT_DUP); - } - - cur.close(); - - return index_vec; -} - std::vector<uint64_t> BlockchainBDB::get_tx_amount_output_indices(const crypto::hash& h) const { LOG_PRINT_L3("BlockchainBDB::" << __func__); diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h index 04a33d7c6..3ae90efe1 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.h +++ b/src/blockchain_db/berkeleydb/db_bdb.h @@ -312,7 +312,6 @@ public: virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index); virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices); - virtual std::vector<uint64_t> get_tx_output_indices(const crypto::hash& h) const; virtual std::vector<uint64_t> get_tx_amount_output_indices(const crypto::hash& h) const; virtual bool has_key_image(const crypto::key_image& img) const; diff --git a/src/blockchain_db/testdb.h b/src/blockchain_db/testdb.h index 1492fb2ae..6c97713d5 100644 --- a/src/blockchain_db/testdb.h +++ b/src/blockchain_db/testdb.h @@ -42,98 +42,97 @@ namespace cryptonote class BaseTestDB: public cryptonote::BlockchainDB { public: BaseTestDB() {} - 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 bool remove_data_file(const std::string& folder) const { return true; } - virtual std::string get_db_name() const { return std::string(); } - virtual bool lock() { return true; } - virtual void unlock() { } - virtual bool batch_start(uint64_t batch_num_blocks=0, uint64_t batch_bytes=0) { return true; } - virtual void batch_stop() {} - virtual void set_batch_transactions(bool) {} - virtual void block_wtxn_start() {} - virtual void block_wtxn_stop() {} - virtual void block_wtxn_abort() {} - virtual bool block_rtxn_start() const { return true; } - virtual void block_rtxn_stop() const {} - virtual void block_rtxn_abort() const {} + virtual void open(const std::string& filename, const int db_flags = 0) override { } + virtual void close() override {} + virtual void sync() override {} + virtual void safesyncmode(const bool onoff) override {} + virtual void reset() override {} + virtual std::vector<std::string> get_filenames() const override { return std::vector<std::string>(); } + virtual bool remove_data_file(const std::string& folder) const override { return true; } + virtual std::string get_db_name() const override { return std::string(); } + virtual bool lock() override { return true; } + virtual void unlock() override { } + virtual bool batch_start(uint64_t batch_num_blocks=0, uint64_t batch_bytes=0) override { return true; } + virtual void batch_stop() override {} + virtual void set_batch_transactions(bool) override {} + virtual void block_wtxn_start() override {} + virtual void block_wtxn_stop() override {} + virtual void block_wtxn_abort() override {} + virtual bool block_rtxn_start() const override { return true; } + virtual void block_rtxn_stop() const override {} + virtual void block_rtxn_abort() const override {} - virtual void drop_hard_fork_info() {} - virtual bool block_exists(const crypto::hash& h, uint64_t *height) const { return false; } - virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t& height) const { return cryptonote::t_serializable_object_to_blob(get_block_from_height(height)); } - virtual cryptonote::blobdata get_block_blob(const crypto::hash& h) const { return cryptonote::blobdata(); } - virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const { return false; } - virtual bool get_pruned_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const { return false; } - virtual bool get_prunable_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const { return false; } - virtual bool get_prunable_tx_hash(const crypto::hash& tx_hash, crypto::hash &prunable_hash) const { return false; } - virtual uint64_t get_block_height(const crypto::hash& h) const { return 0; } - virtual cryptonote::block_header get_block_header(const crypto::hash& h) const { return cryptonote::block_header(); } - virtual uint64_t get_block_timestamp(const uint64_t& height) const { return 0; } - virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const { return {}; } - virtual uint64_t get_top_block_timestamp() const { return 0; } - virtual size_t get_block_weight(const uint64_t& height) const { return 128; } - virtual std::vector<uint64_t> get_block_weights(uint64_t start_height, size_t count) const { return {}; } - virtual cryptonote::difficulty_type get_block_cumulative_difficulty(const uint64_t& height) const { return 10; } - virtual cryptonote::difficulty_type get_block_difficulty(const uint64_t& height) const { return 0; } - virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const { return 10000000000; } - virtual uint64_t get_block_long_term_weight(const uint64_t& height) const { return 128; } - virtual std::vector<uint64_t> get_long_term_block_weights(uint64_t start_height, size_t count) const { return {}; } - virtual crypto::hash get_block_hash_from_height(const uint64_t& height) const { return crypto::hash(); } - virtual std::vector<cryptonote::block> get_blocks_range(const uint64_t& h1, const uint64_t& h2) const { return std::vector<cryptonote::block>(); } - virtual std::vector<crypto::hash> get_hashes_range(const uint64_t& h1, const uint64_t& h2) const { return std::vector<crypto::hash>(); } - virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const { if (block_height) *block_height = 0; return crypto::hash(); } - virtual cryptonote::block get_top_block() const { return cryptonote::block(); } - virtual uint64_t height() const { return 1; } - virtual bool tx_exists(const crypto::hash& h) const { return false; } - virtual bool tx_exists(const crypto::hash& h, uint64_t& tx_index) const { return false; } - virtual uint64_t get_tx_unlock_time(const crypto::hash& h) const { return 0; } - virtual cryptonote::transaction get_tx(const crypto::hash& h) const { return cryptonote::transaction(); } - virtual bool get_tx(const crypto::hash& h, cryptonote::transaction &tx) const { return false; } - virtual uint64_t get_tx_count() const { return 0; } - virtual std::vector<cryptonote::transaction> get_tx_list(const std::vector<crypto::hash>& hlist) const { return std::vector<cryptonote::transaction>(); } - virtual uint64_t get_tx_block_height(const crypto::hash& h) const { return 0; } - virtual uint64_t get_num_outputs(const uint64_t& amount) const { return 1; } - virtual uint64_t get_indexing_base() const { return 0; } - virtual cryptonote::output_data_t get_output_key(const uint64_t& amount, const uint64_t& index, bool include_commitmemt) const { return cryptonote::output_data_t(); } - virtual cryptonote::tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const { return cryptonote::tx_out_index(); } - virtual cryptonote::tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const { return cryptonote::tx_out_index(); } - virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<cryptonote::tx_out_index> &indices) const {} - virtual void get_output_key(const epee::span<const uint64_t> &amounts, const std::vector<uint64_t> &offsets, std::vector<cryptonote::output_data_t> &outputs, bool allow_partial = false) const {} - virtual bool can_thread_bulk_indices() const { return false; } - virtual std::vector<uint64_t> get_tx_output_indices(const crypto::hash& h) const { return std::vector<uint64_t>(); } - virtual std::vector<std::vector<uint64_t>> get_tx_amount_output_indices(const uint64_t tx_index, size_t n_txes) const { return std::vector<std::vector<uint64_t>>(); } - virtual bool has_key_image(const crypto::key_image& img) const { return false; } - virtual void remove_block() { } - virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const std::pair<cryptonote::transaction, cryptonote::blobdata>& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash) {return 0;} - virtual void remove_transaction_data(const crypto::hash& tx_hash, const cryptonote::transaction& tx) {} - virtual uint64_t add_output(const crypto::hash& tx_hash, const cryptonote::tx_out& tx_output, const uint64_t& local_index, const uint64_t unlock_time, const rct::key *commitment) {return 0;} - virtual void add_tx_amount_output_indices(const uint64_t tx_index, const std::vector<uint64_t>& amount_output_indices) {} - virtual void add_spent_key(const crypto::key_image& k_image) {} - virtual void remove_spent_key(const crypto::key_image& k_image) {} + virtual void drop_hard_fork_info() override {} + virtual bool block_exists(const crypto::hash& h, uint64_t *height) const override { return false; } + virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t& height) const override { return cryptonote::t_serializable_object_to_blob(get_block_from_height(height)); } + virtual cryptonote::blobdata get_block_blob(const crypto::hash& h) const override { return cryptonote::blobdata(); } + virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const override { return false; } + virtual bool get_pruned_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const override { return false; } + virtual bool get_prunable_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const override { return false; } + virtual bool get_prunable_tx_hash(const crypto::hash& tx_hash, crypto::hash &prunable_hash) const override { return false; } + virtual uint64_t get_block_height(const crypto::hash& h) const override { return 0; } + virtual cryptonote::block_header get_block_header(const crypto::hash& h) const override { return cryptonote::block_header(); } + virtual uint64_t get_block_timestamp(const uint64_t& height) const override { return 0; } + virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const override { return {}; } + virtual uint64_t get_top_block_timestamp() const override { return 0; } + virtual size_t get_block_weight(const uint64_t& height) const override { return 128; } + virtual std::vector<uint64_t> get_block_weights(uint64_t start_height, size_t count) const override { return {}; } + virtual cryptonote::difficulty_type get_block_cumulative_difficulty(const uint64_t& height) const override { return 10; } + virtual cryptonote::difficulty_type get_block_difficulty(const uint64_t& height) const override { return 0; } + virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const override { return 10000000000; } + virtual uint64_t get_block_long_term_weight(const uint64_t& height) const override { return 128; } + virtual std::vector<uint64_t> get_long_term_block_weights(uint64_t start_height, size_t count) const override { return {}; } + virtual crypto::hash get_block_hash_from_height(const uint64_t& height) const override { return crypto::hash(); } + virtual std::vector<cryptonote::block> get_blocks_range(const uint64_t& h1, const uint64_t& h2) const override { return std::vector<cryptonote::block>(); } + virtual std::vector<crypto::hash> get_hashes_range(const uint64_t& h1, const uint64_t& h2) const override { return std::vector<crypto::hash>(); } + virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const override { if (block_height) *block_height = 0; return crypto::hash(); } + virtual cryptonote::block get_top_block() const override { return cryptonote::block(); } + virtual uint64_t height() const override { return 1; } + virtual bool tx_exists(const crypto::hash& h) const override { return false; } + virtual bool tx_exists(const crypto::hash& h, uint64_t& tx_index) const override { return false; } + virtual uint64_t get_tx_unlock_time(const crypto::hash& h) const override { return 0; } + virtual cryptonote::transaction get_tx(const crypto::hash& h) const override { return cryptonote::transaction(); } + virtual bool get_tx(const crypto::hash& h, cryptonote::transaction &tx) const override { return false; } + virtual uint64_t get_tx_count() const override { return 0; } + virtual std::vector<cryptonote::transaction> get_tx_list(const std::vector<crypto::hash>& hlist) const override { return std::vector<cryptonote::transaction>(); } + virtual uint64_t get_tx_block_height(const crypto::hash& h) const override { return 0; } + virtual uint64_t get_num_outputs(const uint64_t& amount) const override { return 1; } + virtual uint64_t get_indexing_base() const override { return 0; } + virtual cryptonote::output_data_t get_output_key(const uint64_t& amount, const uint64_t& index, bool include_commitmemt) const override { return cryptonote::output_data_t(); } + virtual cryptonote::tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const override { return cryptonote::tx_out_index(); } + virtual cryptonote::tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const override { return cryptonote::tx_out_index(); } + virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<cryptonote::tx_out_index> &indices) const override {} + virtual void get_output_key(const epee::span<const uint64_t> &amounts, const std::vector<uint64_t> &offsets, std::vector<cryptonote::output_data_t> &outputs, bool allow_partial = false) const override {} + virtual bool can_thread_bulk_indices() const override { return false; } + virtual std::vector<std::vector<uint64_t>> get_tx_amount_output_indices(const uint64_t tx_index, size_t n_txes) const override { return std::vector<std::vector<uint64_t>>(); } + virtual bool has_key_image(const crypto::key_image& img) const override { return false; } + virtual void remove_block() override { } + virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const std::pair<cryptonote::transaction, cryptonote::blobdata>& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash) override {return 0;} + virtual void remove_transaction_data(const crypto::hash& tx_hash, const cryptonote::transaction& tx) override {} + virtual uint64_t add_output(const crypto::hash& tx_hash, const cryptonote::tx_out& tx_output, const uint64_t& local_index, const uint64_t unlock_time, const rct::key *commitment) override {return 0;} + virtual void add_tx_amount_output_indices(const uint64_t tx_index, const std::vector<uint64_t>& amount_output_indices) override {} + virtual void add_spent_key(const crypto::key_image& k_image) override {} + virtual void remove_spent_key(const crypto::key_image& k_image) override {} - virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const { return true; } - virtual bool for_blocks_range(const uint64_t&, const uint64_t&, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const { return true; } - virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>, bool pruned) const { return true; } - virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> f) const { return true; } - virtual bool for_all_outputs(uint64_t amount, const std::function<bool(uint64_t height)> &f) const { return true; } - virtual bool is_read_only() const { return false; } - virtual std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked, uint64_t recent_cutoff, uint64_t min_count) const { return std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>>(); } - virtual bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, std::vector<uint64_t> &distribution, uint64_t &base) const { return false; } + virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const override { return true; } + virtual bool for_blocks_range(const uint64_t&, const uint64_t&, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const override { return true; } + virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>, bool pruned) const override { return true; } + virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> f) const override { return true; } + virtual bool for_all_outputs(uint64_t amount, const std::function<bool(uint64_t height)> &f) const override { return true; } + virtual bool is_read_only() const override { return false; } + virtual std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked, uint64_t recent_cutoff, uint64_t min_count) const override { return std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>>(); } + virtual bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, std::vector<uint64_t> &distribution, uint64_t &base) const override { return false; } - virtual void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const cryptonote::txpool_tx_meta_t& details) {} - virtual void update_txpool_tx(const crypto::hash &txid, const cryptonote::txpool_tx_meta_t& details) {} - virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const { return 0; } - virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; } - virtual void remove_txpool_tx(const crypto::hash& txid) {} - virtual bool get_txpool_tx_meta(const crypto::hash& txid, cryptonote::txpool_tx_meta_t &meta) const { return false; } - virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; } - virtual uint64_t get_database_size() const { return 0; } - virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; } - virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const cryptonote::txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; } + virtual void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const cryptonote::txpool_tx_meta_t& details) override {} + virtual void update_txpool_tx(const crypto::hash &txid, const cryptonote::txpool_tx_meta_t& details) override {} + virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const override { return 0; } + virtual bool txpool_has_tx(const crypto::hash &txid) const override { return false; } + virtual void remove_txpool_tx(const crypto::hash& txid) override {} + virtual bool get_txpool_tx_meta(const crypto::hash& txid, cryptonote::txpool_tx_meta_t &meta) const override { return false; } + virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const override { return false; } + virtual uint64_t get_database_size() const override { return 0; } + virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const override { return ""; } + virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const cryptonote::txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const override { return false; } virtual void add_block( const cryptonote::block& blk , size_t block_weight @@ -142,20 +141,20 @@ public: , const uint64_t& coins_generated , uint64_t num_rct_outs , const crypto::hash& blk_hash - ) { } - virtual cryptonote::block get_block_from_height(const uint64_t& height) const { return cryptonote::block(); } - virtual void set_hard_fork_version(uint64_t height, uint8_t version) {} - virtual uint8_t get_hard_fork_version(uint64_t height) const { return 0; } - virtual void check_hard_fork_info() {} + ) override { } + virtual cryptonote::block get_block_from_height(const uint64_t& height) const override { return cryptonote::block(); } + virtual void set_hard_fork_version(uint64_t height, uint8_t version) override {} + virtual uint8_t get_hard_fork_version(uint64_t height) const override { return 0; } + virtual void check_hard_fork_info() override {} - virtual uint32_t get_blockchain_pruning_seed() const { return 0; } - virtual bool prune_blockchain(uint32_t pruning_seed = 0) { return true; } - virtual bool update_pruning() { return true; } - virtual bool check_pruning() { return true; } - virtual void prune_outputs(uint64_t amount) {} + virtual uint32_t get_blockchain_pruning_seed() const override { return 0; } + virtual bool prune_blockchain(uint32_t pruning_seed = 0) override { return true; } + virtual bool update_pruning() override { return true; } + virtual bool check_pruning() override { return true; } + virtual void prune_outputs(uint64_t amount) override {} - virtual uint64_t get_max_block_size() { return 100000000; } - virtual void add_max_block_size(uint64_t sz) { } + virtual uint64_t get_max_block_size() override { return 100000000; } + virtual void add_max_block_size(uint64_t sz) override { } }; } diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index 9e1c86b91..dbbb2308c 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -257,11 +257,7 @@ int main(int argc, char const * argv[]) bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")}; if (!command_line::is_arg_defaulted(vm, daemon_args::arg_log_file)) log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file); -#ifdef __WIN32 - if (!strchr(log_file_path.c_str(), '/') && !strchr(log_file_path.c_str(), '\\')) -#else - if (!strchr(log_file_path.c_str(), '/')) -#endif + if (!log_file_path.has_parent_path()) log_file_path = bf::absolute(log_file_path, relative_path_base); mlog_configure(log_file_path.string(), true, command_line::get_arg(vm, daemon_args::arg_max_log_file_size), command_line::get_arg(vm, daemon_args::arg_max_log_files)); diff --git a/tests/core_tests/bulletproofs.h b/tests/core_tests/bulletproofs.h index f9768a316..83f160d71 100644 --- a/tests/core_tests/bulletproofs.h +++ b/tests/core_tests/bulletproofs.h @@ -49,7 +49,7 @@ struct gen_bp_tx_validation_base : public test_chain_unit_base return !tvc.m_verifivation_failed && tx_added; } - bool check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_idx, const std::vector<cryptonote::transaction>& /*txs*/) + bool check_tx_verification_context_array(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_idx, const std::vector<cryptonote::transaction>& /*txs*/) { size_t failed = 0; for (const cryptonote::tx_verification_context &tvc: tvcs) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 09bc10ea8..614585349 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -1146,3 +1146,21 @@ bool test_chain_unit_base::verify(const std::string& cb_name, cryptonote::core& } return cb_it->second(c, ev_index, events); } + +bool test_chain_unit_base::check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/) +{ + return !bvc.m_verifivation_failed; +} + +bool test_chain_unit_base::check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool /*tx_added*/, size_t /*event_index*/, const cryptonote::transaction& /*tx*/) +{ + return !tvc.m_verifivation_failed; +} + +bool test_chain_unit_base::check_tx_verification_context_array(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t /*tx_added*/, size_t /*event_index*/, const std::vector<cryptonote::transaction>& /*txs*/) +{ + for (const cryptonote::tx_verification_context &tvc: tvcs) + if (tvc.m_verifivation_failed) + return false; + return true; +} diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 797d1207b..c0d31bb8a 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -169,6 +169,10 @@ public: void register_callback(const std::string& cb_name, verify_callback cb); bool verify(const std::string& cb_name, cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events); + bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/); + bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool /*tx_added*/, size_t /*event_index*/, const cryptonote::transaction& /*tx*/); + bool check_tx_verification_context_array(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t /*tx_added*/, size_t /*event_index*/, const std::vector<cryptonote::transaction>& /*txs*/); + private: callbacks_map m_callbacks; }; @@ -487,77 +491,6 @@ uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cry bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks); -//-------------------------------------------------------------------------- -template<class t_test_class> -auto do_check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_index, const cryptonote::transaction& tx, t_test_class& validator, int) - -> decltype(validator.check_tx_verification_context(tvc, tx_added, event_index, tx)) -{ - return validator.check_tx_verification_context(tvc, tx_added, event_index, tx); -} -//-------------------------------------------------------------------------- -template<class t_test_class> -bool do_check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t /*event_index*/, const cryptonote::transaction& /*tx*/, t_test_class&, long) -{ - // Default block verification context check - if (tvc.m_verifivation_failed) - throw std::runtime_error("Transaction verification failed"); - return true; -} -//-------------------------------------------------------------------------- -template<class t_test_class> -bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_index, const cryptonote::transaction& tx, t_test_class& validator) -{ - // SFINAE in action - return do_check_tx_verification_context(tvc, tx_added, event_index, tx, validator, 0); -} -//-------------------------------------------------------------------------- -template<class t_test_class> -auto do_check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_index, const std::vector<cryptonote::transaction>& txs, t_test_class& validator, int) - -> decltype(validator.check_tx_verification_context(tvcs, tx_added, event_index, txs)) -{ - return validator.check_tx_verification_context(tvcs, tx_added, event_index, txs); -} -//-------------------------------------------------------------------------- -template<class t_test_class> -bool do_check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t /*event_index*/, const std::vector<cryptonote::transaction>& /*txs*/, t_test_class&, long) -{ - // Default block verification context check - for (const cryptonote::tx_verification_context &tvc: tvcs) - if (tvc.m_verifivation_failed) - throw std::runtime_error("Transaction verification failed"); - return true; -} -//-------------------------------------------------------------------------- -template<class t_test_class> -bool check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_index, const std::vector<cryptonote::transaction>& txs, t_test_class& validator) -{ - // SFINAE in action - return do_check_tx_verification_context(tvcs, tx_added, event_index, txs, validator, 0); -} -//-------------------------------------------------------------------------- -template<class t_test_class> -auto do_check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_index, const cryptonote::block& blk, t_test_class& validator, int) - -> decltype(validator.check_block_verification_context(bvc, event_index, blk)) -{ - return validator.check_block_verification_context(bvc, event_index, blk); -} -//-------------------------------------------------------------------------- -template<class t_test_class> -bool do_check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t /*event_index*/, const cryptonote::block& /*blk*/, t_test_class&, long) -{ - // Default block verification context check - if (bvc.m_verifivation_failed) - throw std::runtime_error("Block verification failed"); - return true; -} -//-------------------------------------------------------------------------- -template<class t_test_class> -bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_index, const cryptonote::block& blk, t_test_class& validator) -{ - // SFINAE in action - return do_check_block_verification_context(bvc, event_index, blk, validator, 0); -} - /************************************************************************/ /* */ /************************************************************************/ @@ -613,7 +546,7 @@ public: size_t pool_size = m_c.get_pool_transactions_count(); m_c.handle_incoming_tx(t_serializable_object_to_blob(tx), tvc, m_txs_keeped_by_block, false, false); bool tx_added = pool_size + 1 == m_c.get_pool_transactions_count(); - bool r = check_tx_verification_context(tvc, tx_added, m_ev_index, tx, m_validator); + bool r = m_validator.check_tx_verification_context(tvc, tx_added, m_ev_index, tx); CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed"); return true; } @@ -633,7 +566,7 @@ public: size_t pool_size = m_c.get_pool_transactions_count(); m_c.handle_incoming_txs(tx_blobs, tvcs, m_txs_keeped_by_block, false, false); size_t tx_added = m_c.get_pool_transactions_count() - pool_size; - bool r = check_tx_verification_context(tvcs, tx_added, m_ev_index, txs, m_validator); + bool r = m_validator.check_tx_verification_context_array(tvcs, tx_added, m_ev_index, txs); CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed"); return true; } @@ -652,7 +585,7 @@ public: } else bvc.m_verifivation_failed = true; - bool r = check_block_verification_context(bvc, m_ev_index, b, m_validator); + bool r = m_validator.check_block_verification_context(bvc, m_ev_index, b); CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed"); return r; } @@ -692,7 +625,7 @@ public: { blk = cryptonote::block(); } - bool r = check_block_verification_context(bvc, m_ev_index, blk, m_validator); + bool r = m_validator.check_block_verification_context(bvc, m_ev_index, blk); CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed"); return true; } @@ -716,7 +649,7 @@ public: tx = cryptonote::transaction(); } - bool r = check_tx_verification_context(tvc, tx_added, m_ev_index, tx, m_validator); + bool r = m_validator.check_tx_verification_context(tvc, tx_added, m_ev_index, tx); CHECK_AND_NO_ASSERT_MES(r, false, "transaction verification context check failed"); return true; } diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp index c8ce19ba4..0b267172f 100644 --- a/tests/unit_tests/ban.cpp +++ b/tests/unit_tests/ban.cpp @@ -93,7 +93,18 @@ typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_cor static bool is_blocked(Server &server, const epee::net_utils::network_address &address, time_t *t = NULL) { - return server.is_host_blocked(address.host_str(), t); + const std::string host = address.host_str(); + std::map<std::string, time_t> hosts = server.get_blocked_hosts(); + for (auto rec: hosts) + { + if (rec.first == host) + { + if (t) + *t = rec.second; + return true; + } + } + return false; } TEST(ban, add) diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index bb26b5533..1d1e8e9c0 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -46,7 +46,7 @@ namespace class TestDB: public cryptonote::BaseTestDB { public: - virtual uint64_t height() const { return blocks.size(); } + virtual uint64_t height() const override { return blocks.size(); } virtual void add_block( const block& blk , size_t block_weight , uint64_t long_term_block_weight @@ -54,19 +54,19 @@ public: , const uint64_t& coins_generated , uint64_t num_rct_outs , const crypto::hash& blk_hash - ) { + ) override { blocks.push_back(blk); } - virtual void remove_block() { blocks.pop_back(); } - virtual block get_block_from_height(const uint64_t& height) const { + virtual void remove_block() override { blocks.pop_back(); } + virtual block get_block_from_height(const uint64_t& height) const override { return blocks.at(height); } - virtual void set_hard_fork_version(uint64_t height, uint8_t version) { + virtual void set_hard_fork_version(uint64_t height, uint8_t version) override { if (versions.size() <= height) versions.resize(height+1); versions[height] = version; } - virtual uint8_t get_hard_fork_version(uint64_t height) const { + virtual uint8_t get_hard_fork_version(uint64_t height) const override { return versions.at(height); } |