// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // 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 "chaingen.h" #include "wallet_tests_basic.h" template class gen_block_verification_base : public test_chain_unit_enchanced { public: gen_block_verification_base() { REGISTER_CALLBACK("check_block_purged", gen_block_verification_base::check_block_purged); } bool check_block_verification_context(const currency::block_verification_context& bvc, size_t event_idx, const currency::block& /*blk*/) { if (invalid_block_idx == event_idx) return bvc.m_verification_failed; else return !bvc.m_verification_failed; } bool check_block_purged(currency::core& c, size_t ev_index, const std::vector& events) { CHECK_TEST_CONDITION(invalid_block_idx < ev_index); CHECK_EQ(0, c.get_pool_transactions_count()); size_t invalid_block_height = invalid_block_idx - 1; // it's bad idea to use invalid_block_idx for both event index and block height, consider redisign -- sowle CHECK_EQ(invalid_block_height, c.get_current_blockchain_size()); return true; } }; template struct gen_block_accepted_base : public test_chain_unit_enchanced { gen_block_accepted_base() { REGISTER_CALLBACK("check_block_accepted", gen_block_accepted_base::check_block_accepted); } bool check_block_accepted(currency::core& c, size_t /*ev_index*/, const std::vector& /*events*/) { CHECK_EQ(0, c.get_pool_transactions_count()); CHECK_EQ(expected_blockchain_height, c.get_current_blockchain_size()); return true; } }; struct gen_block_big_major_version : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_big_minor_version : public gen_block_accepted_base<2 /* <- expected blockchain height */> { bool generate(std::vector& events) const; }; struct gen_block_ts_not_checked : public gen_block_accepted_base { bool generate(std::vector& events) const; }; struct gen_block_ts_in_past : public gen_block_verification_base { bool generate(std::vector& events) const; }; struct gen_block_ts_in_future : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_invalid_prev_id : public gen_block_verification_base<2> { bool generate(std::vector& events) const; bool check_block_verification_context(const currency::block_verification_context& bvc, size_t event_idx, const currency::block& /*blk*/); }; struct gen_block_invalid_nonce : public gen_block_verification_base<4> { bool generate(std::vector& events) const; }; struct gen_block_no_miner_tx : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_unlock_time_is_low : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_unlock_time_is_high : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_unlock_time_is_timestamp_in_past : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_unlock_time_is_timestamp_in_future : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_height_is_low : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_height_is_high : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_miner_tx_has_2_tx_gen_in : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_miner_tx_has_2_in : public gen_block_verification_base { bool generate(std::vector& events) const; }; struct gen_block_miner_tx_with_txin_to_key : public gen_block_verification_base { bool generate(std::vector& events) const; }; struct gen_block_miner_tx_out_is_small : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_miner_tx_out_is_big : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_miner_tx_has_no_out : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_miner_tx_has_out_to_initiator : public gen_block_accepted_base<2> { bool generate(std::vector& events) const; }; struct gen_block_has_invalid_tx : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_is_too_big : public gen_block_verification_base<2> { bool generate(std::vector& events) const; }; struct gen_block_wrong_version_agains_hardfork : public gen_block_verification_base<2> { public: gen_block_wrong_version_agains_hardfork(); bool c1(currency::core& c, size_t ev_index, const std::vector& events); bool generate(std::vector& events) const; }; struct gen_block_invalid_binary_format : public test_chain_unit_base { gen_block_invalid_binary_format(); bool generate(std::vector& events) const; bool check_block_verification_context(const currency::block_verification_context& bvc, size_t event_idx, const currency::block& /*blk*/); bool check_all_blocks_purged(currency::core& c, size_t ev_index, const std::vector& events); bool corrupt_blocks_boundary(currency::core& c, size_t ev_index, const std::vector& events); private: size_t m_corrupt_blocks_begin_idx; }; struct block_with_correct_prev_id_on_wrong_height : public gen_block_verification_base<1 + CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3> { block_with_correct_prev_id_on_wrong_height(); bool generate(std::vector& events) const; bool assert_blk_2_has_wrong_height(currency::core& c, size_t ev_index, const std::vector& events) const; }; struct block_reward_in_main_chain_basic : wallet_test { block_reward_in_main_chain_basic(); bool generate(std::vector& events) const; private: bool assert_balance(currency::core& core, size_t event_index, const std::vector& events) const; bool assert_reward(currency::core& core, size_t event_index, const std::vector& events) const; struct argument_assert; }; struct block_reward_in_alt_chain_basic : wallet_test { block_reward_in_alt_chain_basic(); bool generate(std::vector& events) const; private: bool assert_balance(currency::core& core, size_t event_index, const std::vector& events) const; bool assert_reward(currency::core& core, size_t event_index, const std::vector& events) const; struct argument_assert; }; struct block_choice_rule_bigger_fee : public wallet_test { block_choice_rule_bigger_fee(); bool generate(std::vector& events) const; bool c1(currency::core& c, size_t ev_index, const std::vector& events); private: struct argument_assert; };