Skip to content

Commit

Permalink
'1'
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan-dolgorukov committed Dec 30, 2024
1 parent 66255c1 commit caea8b2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 77 deletions.
109 changes: 37 additions & 72 deletions tests/core_tests/block_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,117 +733,82 @@ bool block_with_correct_prev_id_on_wrong_height::assert_blk_2_has_wrong_height(c

block_reward_in_main_chain_basic::block_reward_in_main_chain_basic()
{
REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, c_0);
REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, c_1);
REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, c_2);
REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, c_3);
REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, c_4);
REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, c);
}

struct block_reward_in_main_chain_basic::arguments_c
{
uint64_t m_height{}, m_balance{};

arguments_c() = default;

arguments_c(const block_reward_in_main_chain_basic* test, uint64_t height, uint64_t coefficient_default_fee) : m_balance{PREMINE_AMOUNT + height * MK_TEST_COINS(100)}
{
assert(test != nullptr);

if (test->m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, height))
{
m_balance -= coefficient_default_fee * TESTS_DEFAULT_FEE;
}

m_height = height;
}

BEGIN_SERIALIZE()
FIELD(m_height)
FIELD(m_balance)
END_SERIALIZE()
};

bool block_reward_in_main_chain_basic::generate(std::vector<test_event_entry>& events) const
{
GENERATE_ACCOUNT(miner);
MAKE_GENESIS_BLOCK(events, blk_0, miner, test_core_time::get_time());

m_accounts.push_back(miner);
DO_CALLBACK(events, "c_0");

DO_CALLBACK_PARAMS_STR(events, "c", t_serializable_object_to_blob(arguments_c(this, get_block_height(blk_0), 0)));
DO_CALLBACK(events, "configure_core");

MAKE_NEXT_BLOCK(events, blk_1, blk_0, miner);

DO_CALLBACK(events, "c_1");
DO_CALLBACK_PARAMS_STR(events, "c", t_serializable_object_to_blob(arguments_c(this, get_block_height(blk_1), 0)))

REWIND_BLOCKS_N(events, blk_1r, blk_1, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW - 1);

MAKE_TX_FEE(events, tx_0, miner, miner, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, blk_1r);
MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1r, miner, tx_0);

DO_CALLBACK(events, "c_2");
DO_CALLBACK_PARAMS_STR(events, "c", t_serializable_object_to_blob(arguments_c(this, get_block_height(blk_2), 1)));

MAKE_TX_FEE(events, tx_1, miner, miner, MK_TEST_COINS(1), 2 * TESTS_DEFAULT_FEE, blk_2);
MAKE_TX_FEE(events, tx_2, miner, miner, MK_TEST_COINS(1), 3 * TESTS_DEFAULT_FEE, blk_2);

const std::list txs{tx_1, tx_2};
MAKE_NEXT_BLOCK_TX_LIST(events, blk_3, blk_2, miner, txs);

DO_CALLBACK(events, "c_3");
DO_CALLBACK_PARAMS_STR(events, "c", t_serializable_object_to_blob(arguments_c(this, get_block_height(blk_3), 1 + 2 + 3)));

REWIND_BLOCKS_N(events, blk_3r, blk_3, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);

DO_CALLBACK(events, "c_4");
DO_CALLBACK_PARAMS_STR(events, "c", t_serializable_object_to_blob(arguments_c(this, get_block_height(blk_3r), 1 + 2 + 3)));

return true;
}

bool block_reward_in_main_chain_basic::c_0(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const
bool block_reward_in_main_chain_basic::c(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const
{
CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_top_block_height(), 0);

const auto wallet{init_playtime_test_wallet(events, core, m_accounts.front())};

CHECK_AND_ASSERT_NEQ(wallet, nullptr);
wallet->refresh();
CHECK_AND_ASSERT_EQ(wallet->balance(), PREMINE_AMOUNT);

return true;
}

bool block_reward_in_main_chain_basic::c_1(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const
{
const auto height{core.get_blockchain_storage().get_top_block_height()};

CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_top_block_height(), height);

const auto wallet{init_playtime_test_wallet(events, core, m_accounts.front())};

CHECK_AND_ASSERT_NEQ(wallet, nullptr);
wallet->refresh();
CHECK_AND_ASSERT_EQ(wallet->balance(), PREMINE_AMOUNT + height * MK_TEST_COINS(100));

return true;
}

bool block_reward_in_main_chain_basic::c_2(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const
{
const auto height{core.get_blockchain_storage().get_top_block_height()};

CHECK_AND_ASSERT_EQ(height, 11);

const auto wallet{init_playtime_test_wallet(events, core, m_accounts.front())};

CHECK_AND_ASSERT_NEQ(wallet, nullptr);
wallet->refresh();
CHECK_AND_ASSERT_EQ(wallet->balance(), PREMINE_AMOUNT + height * MK_TEST_COINS(100) - m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, height) * TESTS_DEFAULT_FEE);

return true;
}

bool block_reward_in_main_chain_basic::c_3(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const
{
const auto height{core.get_blockchain_storage().get_top_block_height()};

CHECK_AND_ASSERT_EQ(height, 12);

const auto wallet{init_playtime_test_wallet(events, core, m_accounts.front())};

CHECK_AND_ASSERT_NEQ(wallet, nullptr);
wallet->refresh();
CHECK_AND_ASSERT_EQ(wallet->balance(), PREMINE_AMOUNT + height * MK_TEST_COINS(100) - m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, height) * (1 + 2 + 3) * TESTS_DEFAULT_FEE);

return true;
}

bool block_reward_in_main_chain_basic::c_4(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const
{
const auto height{core.get_blockchain_storage().get_top_block_height()};
const auto arguments_string{boost::get<callback_entry>(events.at(event_index)).callback_params};
arguments_c arguments{};

CHECK_AND_ASSERT_EQ(height, 22);
CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob<arguments_c>(arguments, arguments_string), true);
CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_top_block_height(), arguments.m_height);

const auto wallet{init_playtime_test_wallet(events, core, m_accounts.front())};

CHECK_AND_ASSERT_NEQ(wallet, nullptr);
wallet->refresh();
CHECK_AND_ASSERT_EQ(wallet->balance(), PREMINE_AMOUNT + height * MK_TEST_COINS(100) - m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, height) * (1 + 2 + 3) * TESTS_DEFAULT_FEE);
CHECK_AND_ASSERT_EQ(wallet->balance(), arguments.m_balance);

return true;
}
Expand Down
7 changes: 2 additions & 5 deletions tests/core_tests/block_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,8 @@ struct block_reward_in_main_chain_basic : wallet_test
bool generate(std::vector<test_event_entry>& events) const;

private:
bool c_0(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const;
bool c_1(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const;
bool c_2(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const;
bool c_3(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const;
bool c_4(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const;
bool c(currency::core& core, size_t event_index, const std::vector<test_event_entry>& events) const;
struct arguments_c;
};

struct block_reward_in_alt_chain_basic : wallet_test
Expand Down

0 comments on commit caea8b2

Please sign in to comment.