1
0
Fork 0
forked from lthn/blockchain

1) test_chain_unit_enchanced::check_hardfork_active implemented, 2) core runtime config minor improvement

This commit is contained in:
sowle 2021-04-28 07:00:32 +03:00
parent 5d3a8e730a
commit ebf5486513
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 32 additions and 0 deletions

View file

@ -26,6 +26,18 @@ namespace currency
uint64_t hard_fork_02_starts_after_height;
uint64_t hard_fork_03_starts_after_height;
bool is_hardfork_active_for_height(size_t hardfork_id, uint64_t height) const
{
switch (hardfork_id)
{
case 0: return true;
case 1: return height > hard_fork_01_starts_after_height;
case 2: return height > hard_fork_02_starts_after_height;
case 3: return height > hard_fork_03_starts_after_height;
default: return false;
}
}
static uint64_t _default_core_time_function()
{
return time(NULL);

View file

@ -2099,6 +2099,7 @@ test_chain_unit_enchanced::test_chain_unit_enchanced()
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, print_tx_pool);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, remove_stuck_txs);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_offers_count);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_hardfork_active);
}
bool test_chain_unit_enchanced::configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
@ -2118,6 +2119,7 @@ void test_chain_unit_enchanced::set_hard_fork_heights_to_generator(test_generato
{
generator.set_hardfork_height(1, m_hardfork_01_height);
generator.set_hardfork_height(2, m_hardfork_02_height);
generator.set_hardfork_height(3, m_hardfork_03_height);
}
bool test_chain_unit_enchanced::check_top_block(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
@ -2232,3 +2234,19 @@ bool test_chain_unit_enchanced::check_offers_count(currency::core& c, size_t ev_
return true;
}
bool test_chain_unit_enchanced::check_hardfork_active(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
size_t hardfork_id_to_check = 0;
const std::string& params = boost::get<callback_entry>(events[ev_index]).callback_params;
CHECK_AND_ASSERT_MES(epee::string_tools::hex_to_pod(params, hardfork_id_to_check), false, "hex_to_pod failed, params = " << params);
uint64_t top_block_height = c.get_top_block_height();
if (!c.get_blockchain_storage().get_core_runtime_config().is_hardfork_active_for_height(hardfork_id_to_check, top_block_height))
{
LOG_ERROR("Hardfork #" << hardfork_id_to_check << " is not active yet (top block height is " << top_block_height << ")");
return false;
}
return true;
}

View file

@ -308,6 +308,7 @@ public:
bool print_tx_pool(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool remove_stuck_txs(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool check_offers_count(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool check_hardfork_active(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
protected:
struct params_top_block
@ -322,6 +323,7 @@ protected:
size_t m_unverifiable_tx_index;
size_t m_orphan_block_index;
// the following members is intended to be set by coretests with specific HF-related needs
uint64_t m_hardfork_01_height;
uint64_t m_hardfork_02_height;
uint64_t m_hardfork_03_height;