forked from lthn/blockchain
coretests: implemented the test "block_with_correct_prev_id_on_wrong_height" (#479)
This commit is contained in:
parent
11b8933345
commit
9e3ece1818
3 changed files with 49 additions and 1 deletions
|
|
@ -692,4 +692,41 @@ bool gen_block_wrong_version_agains_hardfork::generate(std::vector<test_event_en
|
|||
BLOCK_VALIDATION_INIT_GENERATE();
|
||||
DO_CALLBACK(events, "c1");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool block_with_correct_prev_id_on_wrong_height::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
// Test idea: make sure that a block with correct previous block identifier that is at the wrong height won't be accepted by the core.
|
||||
|
||||
GENERATE_ACCOUNT(miner);
|
||||
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).
|
||||
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");
|
||||
|
||||
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{};
|
||||
|
||||
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);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,3 +187,13 @@ struct gen_block_invalid_binary_format : public test_chain_unit_base
|
|||
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<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{};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1177,6 +1177,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY_HF(gen_block_unlock_time_is_timestamp_in_future, "0,3");
|
||||
GENERATE_AND_PLAY_HF(gen_block_height_is_low, "0,3");
|
||||
GENERATE_AND_PLAY_HF(gen_block_height_is_high, "0,3");
|
||||
GENERATE_AND_PLAY_HF(block_with_correct_prev_id_on_wrong_height, "3-*");
|
||||
GENERATE_AND_PLAY_HF(gen_block_miner_tx_has_2_tx_gen_in, "0,3");
|
||||
GENERATE_AND_PLAY_HF(gen_block_miner_tx_has_2_in, "0,3");
|
||||
GENERATE_AND_PLAY_HF(gen_block_miner_tx_with_txin_to_key, "0,3");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue