1
0
Fork 0
forked from lthn/blockchain

changed approach to turn core_tests against hardforks

This commit is contained in:
cryptozoidberg 2023-05-01 00:03:24 +02:00
parent a83dedf2a4
commit 62d173424a
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 44 additions and 51 deletions

View file

@ -54,7 +54,6 @@ namespace
bool gen_block_big_major_version::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
block blk_1;
generator.construct_block_manually(blk_1, blk_0, miner_account, test_generator::bf_major_ver, CURRENT_BLOCK_MAJOR_VERSION + 1);
@ -68,7 +67,6 @@ bool gen_block_big_major_version::generate(std::vector<test_event_entry>& events
bool gen_block_big_minor_version::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
block blk_1;
generator.construct_block_manually(blk_1, blk_0, miner_account, test_generator::bf_minor_ver, 0, CURRENT_BLOCK_MINOR_VERSION + 1);
@ -82,7 +80,6 @@ bool gen_block_big_minor_version::generate(std::vector<test_event_entry>& events
bool gen_block_ts_not_checked::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_account, BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW - 2);
block blk_1;
@ -97,7 +94,6 @@ bool gen_block_ts_not_checked::generate(std::vector<test_event_entry>& events) c
bool gen_block_ts_in_past::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_account, BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW - 1);
uint64_t ts_below_median = boost::get<block>(events[BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW / 2 - 1]).timestamp;
@ -113,7 +109,6 @@ bool gen_block_ts_in_past::generate(std::vector<test_event_entry>& events) const
bool gen_block_ts_in_future::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
block blk_1;
generator.construct_block_manually(blk_1, blk_0, miner_account, test_generator::bf_timestamp, 0, 0, time(NULL) + 60*60 + CURRENCY_BLOCK_FUTURE_TIME_LIMIT);
events.push_back(blk_1);
@ -126,7 +121,6 @@ bool gen_block_ts_in_future::generate(std::vector<test_event_entry>& events) con
bool gen_block_invalid_prev_id::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
block blk_1;
crypto::hash prev_id = get_block_hash(blk_0);
reinterpret_cast<char &>(prev_id) ^= 1;
@ -149,7 +143,6 @@ bool gen_block_invalid_prev_id::check_block_verification_context(const currency:
bool gen_block_invalid_nonce::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
std::vector<uint64_t> timestamps;
std::vector<wide_difficulty_type> commulative_difficulties;
if (!lift_up_difficulty(events, timestamps, commulative_difficulties, generator, 2, blk_0, miner_account))
@ -179,7 +172,6 @@ bool gen_block_invalid_nonce::generate(std::vector<test_event_entry>& events) co
bool gen_block_no_miner_tx::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
transaction miner_tx;
miner_tx = AUTO_VAL_INIT(miner_tx);
@ -211,7 +203,6 @@ bool gen_block_unlock_time_is_low::generate(std::vector<test_event_entry>& event
bool gen_block_unlock_time_is_high::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
set_tx_unlock_time(miner_tx, get_tx_max_unlock_time(miner_tx) + 1);
@ -243,7 +234,6 @@ bool gen_block_unlock_time_is_timestamp_in_past::generate(std::vector<test_event
bool gen_block_unlock_time_is_timestamp_in_future::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
set_tx_unlock_time(miner_tx, blk_0.timestamp + 3 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW * DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN);
@ -259,7 +249,6 @@ bool gen_block_unlock_time_is_timestamp_in_future::generate(std::vector<test_eve
bool gen_block_height_is_low::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
boost::get<txin_gen>(miner_tx.vin[0]).height--;
@ -275,7 +264,6 @@ bool gen_block_height_is_low::generate(std::vector<test_event_entry>& events) co
bool gen_block_height_is_high::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
boost::get<txin_gen>(miner_tx.vin[0]).height++;
@ -291,7 +279,6 @@ bool gen_block_height_is_high::generate(std::vector<test_event_entry>& events) c
bool gen_block_miner_tx_has_2_tx_gen_in::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
txin_gen in;
@ -310,7 +297,6 @@ bool gen_block_miner_tx_has_2_tx_gen_in::generate(std::vector<test_event_entry>&
bool gen_block_miner_tx_has_2_in::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
REWIND_BLOCKS(events, blk_0r, blk_0, miner_account);
GENERATE_ACCOUNT(alice);
@ -355,7 +341,6 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector<test_event_entry>& events
bool gen_block_miner_tx_with_txin_to_key::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
// This block has only one output
block blk_1 = AUTO_VAL_INIT(blk_1);
@ -403,7 +388,6 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector<test_event_entry>
bool gen_block_miner_tx_out_is_small::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
boost::get<currency::tx_out_bare>( miner_tx.vout[0]).amount /= 2;
@ -419,7 +403,6 @@ boost::get<currency::tx_out_bare>( miner_tx.vout[0]).amount /= 2;
bool gen_block_miner_tx_out_is_big::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
boost::get<currency::tx_out_bare>( miner_tx.vout[0]).amount *= 2;
@ -435,7 +418,6 @@ boost::get<currency::tx_out_bare>( miner_tx.vout[0]).amount *= 2;
bool gen_block_miner_tx_has_no_out::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
miner_tx.vout.clear();
@ -451,7 +433,6 @@ bool gen_block_miner_tx_has_no_out::generate(std::vector<test_event_entry>& even
bool gen_block_miner_tx_has_out_to_alice::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
GENERATE_ACCOUNT(alice);
keypair txkey;
@ -480,7 +461,6 @@ boost::get<currency::tx_out_bare>( miner_tx.vout[0]).amount -= out_to_alice.amo
bool gen_block_has_invalid_tx::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
std::vector<crypto::hash> tx_hashes;
tx_hashes.push_back(crypto::hash());
@ -496,7 +476,6 @@ bool gen_block_has_invalid_tx::generate(std::vector<test_event_entry>& events) c
bool gen_block_is_too_big::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
// Creating a huge miner_tx, it will have a lot of outs
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
static const size_t tx_out_count = CURRENCY_BLOCK_GRANTED_FULL_REWARD_ZONE / 2;
@ -543,7 +522,6 @@ gen_block_invalid_binary_format::gen_block_invalid_binary_format()
bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
//wide_difficulty_type cummulative_diff = 1;
// Unlock blk_0 outputs
@ -711,7 +689,6 @@ bool gen_block_wrong_version_agains_hardfork::c1(currency::core& c, size_t ev_in
bool gen_block_wrong_version_agains_hardfork::generate(std::vector<test_event_entry>& events) const
{
BLOCK_VALIDATION_INIT_GENERATE();
SET_HARDFORKS_TO_OLD_TESTS();
DO_CALLBACK(events, "c1");
return true;
}

View file

@ -13,7 +13,10 @@ class gen_block_verification_base : public test_chain_unit_base
public:
gen_block_verification_base()
{
m_hardforks.m_height_the_hardfork_n_active_after.fill(0);
m_hardforks.m_height_the_hardfork_n_active_after[1] = 1440; \
m_hardforks.m_height_the_hardfork_n_active_after[2] = 1800; \
m_hardforks.m_height_the_hardfork_n_active_after[3] = 1801;
m_hardforks.m_height_the_hardfork_n_active_after[4] = 50000000000;
REGISTER_CALLBACK("check_block_purged", gen_block_verification_base<invalid_block_idx>::check_block_purged);
}
@ -26,6 +29,12 @@ public:
return !bvc.m_verification_failed;
}
// currency::core_runtime_config get_runtime_info_for_core() const
// {
// currency::core_runtime_config res = test_chain_unit_base::get_runtime_info_for_core();
//
// }
bool check_block_purged(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
@ -35,7 +44,7 @@ public:
return true;
}
mutable currency::hard_forks_descriptor m_hardforks;
//mutable currency::hard_forks_descriptor m_hardforks;
};
template<size_t expected_blockchain_height>
@ -56,7 +65,7 @@ struct gen_block_accepted_base : public test_chain_unit_base
}
};
struct gen_block_big_major_version : public gen_block_verification_base<2>
struct gen_block_big_major_version : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
@ -76,83 +85,83 @@ struct gen_block_ts_in_past : public gen_block_verification_base<BLOCKCHAIN_TIME
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_ts_in_future : public gen_block_verification_base<2>
struct gen_block_ts_in_future : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_invalid_prev_id : public gen_block_verification_base<2>
struct gen_block_invalid_prev_id : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& 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>
struct gen_block_invalid_nonce : public gen_block_verification_base<3>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_no_miner_tx : public gen_block_verification_base<2>
struct gen_block_no_miner_tx : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_unlock_time_is_low : public gen_block_verification_base<2>
struct gen_block_unlock_time_is_low : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_unlock_time_is_high : public gen_block_verification_base<2>
struct gen_block_unlock_time_is_high : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_unlock_time_is_timestamp_in_past : public gen_block_verification_base<2>
struct gen_block_unlock_time_is_timestamp_in_past : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_unlock_time_is_timestamp_in_future : public gen_block_verification_base<2>
struct gen_block_unlock_time_is_timestamp_in_future : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_height_is_low : public gen_block_verification_base<2>
struct gen_block_height_is_low : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_height_is_high : public gen_block_verification_base<2>
struct gen_block_height_is_high : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_miner_tx_has_2_tx_gen_in : public gen_block_verification_base<2>
struct gen_block_miner_tx_has_2_tx_gen_in : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_miner_tx_has_2_in : public gen_block_verification_base<CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2>
struct gen_block_miner_tx_has_2_in : public gen_block_verification_base<CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_miner_tx_with_txin_to_key : public gen_block_verification_base<CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3>
struct gen_block_miner_tx_with_txin_to_key : public gen_block_verification_base<CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_miner_tx_out_is_small : public gen_block_verification_base<2>
struct gen_block_miner_tx_out_is_small : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_miner_tx_out_is_big : public gen_block_verification_base<2>
struct gen_block_miner_tx_out_is_big : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_miner_tx_has_no_out : public gen_block_verification_base<2>
struct gen_block_miner_tx_has_no_out : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
@ -162,17 +171,17 @@ struct gen_block_miner_tx_has_out_to_alice : public gen_block_accepted_base<2>
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_has_invalid_tx : public gen_block_verification_base<2>
struct gen_block_has_invalid_tx : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_is_too_big : public gen_block_verification_base<2>
struct gen_block_is_too_big : public gen_block_verification_base<1>
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct gen_block_wrong_version_agains_hardfork : public gen_block_verification_base<2>
struct gen_block_wrong_version_agains_hardfork : public gen_block_verification_base<1>
{
public:
gen_block_wrong_version_agains_hardfork();
@ -192,4 +201,4 @@ struct gen_block_invalid_binary_format : public test_chain_unit_base
private:
size_t m_corrupt_blocks_begin_idx;
};
};

View file

@ -2266,6 +2266,15 @@ void test_chain_unit_base::on_test_generator_created(test_generator& gen) const
gen.set_hardforks(m_hardforks);
}
currency::core_runtime_config test_chain_unit_base::get_runtime_info_for_core() const
{
currency::core_runtime_config crc = currency::get_default_core_runtime_config();
crc.get_core_time = &test_core_time::get_time;
crc.tx_pool_min_fee = TESTS_DEFAULT_FEE;
crc.tx_default_fee = TESTS_DEFAULT_FEE;
crc.hard_forks = m_hardforks;
return crc;
}
//------------------------------------------------------------------------------
test_chain_unit_enchanced::test_chain_unit_enchanced()

View file

@ -256,6 +256,8 @@ public:
uint64_t get_tx_version_from_events(const std::vector<test_event_entry> &events) const;
void on_test_generator_created(test_generator& generator) const; // tests can override this for special initialization
currency::core_runtime_config get_runtime_info_for_core() const; // tests can override this for special initialization
private:
callbacks_map m_callbacks;

View file

@ -627,11 +627,7 @@ inline bool do_replay_events(const std::vector<test_event_entry>& events, t_test
bc_services::bc_offers_service offers_service(nullptr);
c.get_blockchain_storage().get_attachment_services_manager().add_service(&offers_service);
currency::core_runtime_config crc = c.get_blockchain_storage().get_core_runtime_config();
crc.get_core_time = &test_core_time::get_time;
crc.tx_pool_min_fee = TESTS_DEFAULT_FEE;
crc.tx_default_fee = TESTS_DEFAULT_FEE;
c.get_blockchain_storage().set_core_runtime_config(crc);
c.get_blockchain_storage().set_core_runtime_config(validator.get_runtime_info_for_core());
if (validator.need_core_proxy())
{