1
0
Fork 0
forked from lthn/blockchain

coretests: Update "block_with_correct_prev_id_on_wrong_height" test (#499)

* Core tests: implement the test "block_with_correct_prev_id_on_wrong_height"

* Core tests: update "block_with_correct_prev_id_on_wrong_height" test
This commit is contained in:
Stёpa Dolgorukov 2025-01-29 15:24:18 +05:00 committed by GitHub
parent 072d53de9b
commit dd64c805d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 13 deletions

View file

@ -696,7 +696,7 @@ bool gen_block_wrong_version_agains_hardfork::generate(std::vector<test_event_en
block_with_correct_prev_id_on_wrong_height::block_with_correct_prev_id_on_wrong_height()
{
REGISTER_CALLBACK("assert_blk_2_has_wrong_height", block_with_correct_prev_id_on_wrong_height::assert_blk_2_has_wrong_height);
REGISTER_CALLBACK_METHOD(block_with_correct_prev_id_on_wrong_height, assert_blk_2_has_wrong_height);
}
bool block_with_correct_prev_id_on_wrong_height::generate(std::vector<test_event_entry>& events) const
@ -707,26 +707,40 @@ bool block_with_correct_prev_id_on_wrong_height::generate(std::vector<test_event
MAKE_GENESIS_BLOCK(events, blk_0, miner, test_core_time::get_time());
DO_CALLBACK(events, "configure_core");
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
MAKE_TX(events, tx_0, miner, miner, MK_TEST_COINS(2), blk_0r);
MAKE_NEXT_BLOCK(events, blk_1, blk_0r, miner);
m_blk_2.prev_id = currency::get_block_hash(blk_1);
m_blk_2.miner_tx = blk_0r.miner_tx;
m_blk_2.major_version = blk_0r.major_version;
// blk_1 is the previous for blk_2, but height(blk_2) < height(blk_1).
block blk_2{};
blk_2.prev_id = currency::get_block_hash(blk_1);
blk_2.miner_tx = blk_0r.miner_tx;
blk_2.major_version = blk_0r.major_version;
CHECK_AND_ASSERT_EQ(currency::get_block_height(blk_1), 11);
CHECK_AND_ASSERT_EQ(currency::get_block_height(m_blk_2), 10);
DO_CALLBACK(events, "assert_blk_2_has_wrong_height");
CHECK_AND_ASSERT_EQ(currency::get_block_height(blk_2), 10);
// blk_1 is the previous for blk_2, but height(blk_2) < height(blk_1).
DO_CALLBACK_PARAMS_STR(events, "assert_blk_2_has_wrong_height", t_serializable_object_to_blob(blk_2));
return true;
}
bool block_with_correct_prev_id_on_wrong_height::assert_blk_2_has_wrong_height(currency::core& c, [[maybe_unused]] size_t ev_index, [[maybe_unused]] const std::vector<test_event_entry>& events) const
{
currency::block_verification_context context_blk_2{};
block blk_2{};
CHECK_AND_ASSERT_EQ(boost::get<txin_gen>(m_blk_2.miner_tx.vin.front()).height, 10);
CHECK_AND_ASSERT_EQ(c.get_blockchain_storage().add_new_block(m_blk_2, context_blk_2), false);
{
const auto serialized_block{boost::get<callback_entry>(events.at(ev_index)).callback_params};
CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(blk_2, serialized_block), true);
}
{
currency::block_verification_context context_blk_2{};
CHECK_AND_ASSERT_EQ(boost::get<txin_gen>(blk_2.miner_tx.vin.front()).height, 10);
// Make sure, that it's impossible to insert blk_2.
CHECK_AND_ASSERT_EQ(c.get_blockchain_storage().add_new_block(blk_2, context_blk_2), false);
}
return true;
}

View file

@ -194,9 +194,6 @@ struct block_with_correct_prev_id_on_wrong_height : public gen_block_verificatio
block_with_correct_prev_id_on_wrong_height();
bool generate(std::vector<test_event_entry>& events) const;
bool assert_blk_2_has_wrong_height(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events) const;
private:
mutable currency::block m_blk_2{};
};
struct block_reward_in_main_chain_basic : wallet_test