forked from lthn/blockchain
fixed few bugs in locked pos mining, implemeted proper test
This commit is contained in:
parent
1ae2da4983
commit
67212dab51
13 changed files with 249 additions and 101 deletions
|
|
@ -3864,7 +3864,7 @@ bool blockchain_storage::get_output_keys_for_input_with_checks(const transaction
|
|||
//check tx unlock time
|
||||
uint64_t source_out_unlock_time = get_tx_unlock_time(source_tx, out_i);
|
||||
//let coinbase sources for PoS block to have locked inputs, the outputs supposed to be locked same way, except the reward
|
||||
if (is_coinbase(source_tx) && is_pos_block(source_tx))
|
||||
if (is_coinbase(validated_tx) && is_pos_block(validated_tx))
|
||||
{
|
||||
if (source_out_unlock_time > m_max_unlock_time)
|
||||
m_max_unlock_time = source_out_unlock_time;
|
||||
|
|
@ -4336,9 +4336,16 @@ bool blockchain_storage::validate_coinbase_outs_unlocktime(const transaction& mi
|
|||
uint64_t major_unlock_time = get_tx_x_detail<etc_tx_details_unlock_time>(miner_tx);
|
||||
if (major_unlock_time)
|
||||
{
|
||||
//if there was etc_tx_details_unlock_time present in tx, then ignore etc_tx_details_unlock_time2
|
||||
if (major_unlock_time < max_unlock_time)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
CHECK_AND_ASSERT_MES(get_block_height(miner_tx) > m_core_runtime_config.hard_fork1_starts_after_height, false, "error in block [" << get_block_height(miner_tx) << "] etc_tx_details_unlock_time2 can exist only after hard fork point : " << m_core_runtime_config.hard_fork1_starts_after_height);
|
||||
|
||||
//etc_tx_details_unlock_time2 can be kept only after hard_fork_1 point
|
||||
etc_tx_details_unlock_time2 ut2 = AUTO_VAL_INIT(ut2);
|
||||
get_type_in_variant_container(miner_tx.extra, ut2);
|
||||
CHECK_AND_ASSERT_MES(ut2.unlock_time_array.size() == miner_tx.vout.size(), false, "ut2.unlock_time_array.size()<" << ut2.unlock_time_array.size()
|
||||
|
|
|
|||
|
|
@ -107,17 +107,29 @@ namespace currency
|
|||
out_amounts.resize(out_amounts.size() - 1);
|
||||
}
|
||||
|
||||
|
||||
std::vector<tx_destination_entry> destinations;
|
||||
for (auto a : out_amounts)
|
||||
{
|
||||
tx_destination_entry de = AUTO_VAL_INIT(de);
|
||||
de.addr.push_back(miner_address);
|
||||
de.amount = a;
|
||||
if (pe.stake_unlock_time && pe.stake_unlock_time > height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW)
|
||||
{
|
||||
//this means that block is creating after hardfork_1 and unlock_time is needed to set for every destination separately
|
||||
de.unlock_time = height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW;
|
||||
}
|
||||
destinations.push_back(de);
|
||||
}
|
||||
|
||||
if (pos)
|
||||
destinations.push_back(tx_destination_entry(pe.amount, stakeholder_address, pe.stake_unlock_time));
|
||||
{
|
||||
uint64_t stake_lock_time = 0;
|
||||
if (pe.stake_unlock_time && pe.stake_unlock_time > height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW)
|
||||
stake_lock_time = pe.stake_unlock_time;
|
||||
destinations.push_back(tx_destination_entry(pe.amount, stakeholder_address, stake_lock_time));
|
||||
}
|
||||
|
||||
|
||||
return construct_miner_tx(height, median_size, already_generated_coins, current_block_size, fee, destinations, tx, extra_nonce, max_outs, pos, pe);
|
||||
}
|
||||
|
|
@ -198,7 +210,12 @@ namespace currency
|
|||
|
||||
|
||||
tx.version = CURRENT_TRANSACTION_VERSION;
|
||||
set_tx_unlock_time(tx, height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
if (!have_type_in_variant_container<etc_tx_details_unlock_time2>(tx.extra))
|
||||
{
|
||||
//if stake unlock time was not set, then we can use simple "whole transaction" lock scheme
|
||||
set_tx_unlock_time(tx, height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -112,13 +112,19 @@ namespace currency
|
|||
}
|
||||
CHECK_AND_ASSERT_THROW_MES(ut2.unlock_time_array.size() == tx.vout.size(), "unlock_time_array.size=" << ut2.unlock_time_array.size()
|
||||
<< " is not equal tx.vout.size()=" << tx.vout.size() << " in tx: " << get_transaction_hash(tx));
|
||||
for (size_t i = 0; i != ut2.unlock_time_array.size(); i++)
|
||||
if (ut2.unlock_time_array.size())
|
||||
{
|
||||
if (ut2.unlock_time_array[i] > max_unlock_time)
|
||||
max_unlock_time = ut2.unlock_time_array[i];
|
||||
if (ut2.unlock_time_array[i] < min_unlock_time)
|
||||
min_unlock_time = ut2.unlock_time_array[i];
|
||||
max_unlock_time = min_unlock_time = ut2.unlock_time_array[0];
|
||||
for (size_t i = 1; i != ut2.unlock_time_array.size(); i++)
|
||||
{
|
||||
if (ut2.unlock_time_array[i] > max_unlock_time)
|
||||
max_unlock_time = ut2.unlock_time_array[i];
|
||||
if (ut2.unlock_time_array[i] < min_unlock_time)
|
||||
min_unlock_time = ut2.unlock_time_array[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace currency
|
|||
|
||||
tx_destination_entry() : amount(0), minimum_sigs(0), amount_to_provide(0), unlock_time(0){}
|
||||
tx_destination_entry(uint64_t a, const account_public_address& ad) : amount(a), addr(1, ad), minimum_sigs(0), amount_to_provide(0), unlock_time(0){}
|
||||
tx_destination_entry(uint64_t a, const account_public_address& ad, uint64_t unlock_time) : amount(a), addr(1, ad), minimum_sigs(0), amount_to_provide(0) {}
|
||||
tx_destination_entry(uint64_t a, const account_public_address& ad, uint64_t ut) : amount(a), addr(1, ad), minimum_sigs(0), amount_to_provide(0), unlock_time(ut) {}
|
||||
tx_destination_entry(uint64_t a, const std::list<account_public_address>& addr) : amount(a), addr(addr), minimum_sigs(addr.size()), amount_to_provide(0), unlock_time(0){}
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace tools
|
|||
{
|
||||
|
||||
//---------------------------------------------------------------
|
||||
uint64_t wallet2::get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const tools::wallet_rpc::wallet_transfer_info_details& td)
|
||||
uint64_t wallet2::get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const money_transfer2_details& td)
|
||||
{
|
||||
uint64_t max_unlock_time = 0;
|
||||
// etc_tx_details_expiration_time have priority over etc_tx_details_expiration_time2
|
||||
|
|
@ -50,7 +50,7 @@ namespace tools
|
|||
|
||||
CHECK_AND_ASSERT_THROW_MES(ut2.unlock_time_array.size() == tx.vout.size(), "Internal error: wrong tx transfer details: ut2.unlock_time_array.size()" << ut2.unlock_time_array.size() << " is not equal transaction outputs vector size=" << tx.vout.size());
|
||||
|
||||
for (auto ri : td.rcv)
|
||||
for (auto ri : td.receive_indices)
|
||||
{
|
||||
CHECK_AND_ASSERT_THROW_MES(ri < tx.vout.size(), "Internal error: wrong tx transfer details: reciev index=" << ri << " is greater than transaction outputs vector " << tx.vout.size());
|
||||
if (tx.vout[ri].target.type() == typeid(currency::txout_to_key))
|
||||
|
|
@ -960,7 +960,7 @@ void wallet2::prepare_wti(wallet_rpc::wallet_transfer_info& wti, uint64_t height
|
|||
wti.amount = amount;
|
||||
wti.height = height;
|
||||
fill_transfer_details(tx, td, wti.td);
|
||||
wti.unlock_time = get_max_unlock_time_from_receive_indices(tx, wti.td);
|
||||
wti.unlock_time = get_max_unlock_time_from_receive_indices(tx, td);
|
||||
wti.timestamp = timestamp;
|
||||
wti.fee = currency::is_coinbase(tx) ? 0:currency::get_tx_fee(tx);
|
||||
wti.tx_blob_size = static_cast<uint32_t>(currency::get_object_blobsize(wti.tx));
|
||||
|
|
@ -2818,9 +2818,7 @@ void wallet2::cancel_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, uin
|
|||
crypto::generate_signature(crypto::cn_fast_hash(sig_blob.data(), sig_blob.size()), ephemeral.pub, ephemeral.sec, co.sig);
|
||||
bc_services::put_offer_into_attachment(co, attachments);
|
||||
|
||||
destinations.push_back(tx_dest);
|
||||
uint64_t fee = TX_DEFAULT_FEE;
|
||||
transfer(destinations, 0, 0, fee, extra, attachments, detail::ssi_digit, tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx);
|
||||
transfer(std::vector<currency::tx_destination_entry>(), 0, 0, fee, extra, attachments, detail::ssi_digit, tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::update_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, const bc_services::offer_details_ex& od, currency::transaction& res_tx)
|
||||
|
|
|
|||
|
|
@ -721,7 +721,7 @@ namespace tools
|
|||
void finalize_transaction(const finalize_tx_param& ftp, currency::transaction& tx, crypto::secret_key& tx_key, bool broadcast_tx);
|
||||
|
||||
std::string get_log_prefix() const { return m_log_prefix; }
|
||||
static uint64_t get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const tools::wallet_rpc::wallet_transfer_info_details& td);
|
||||
static uint64_t get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const money_transfer2_details& td);
|
||||
private:
|
||||
void add_transfers_to_expiration_list(const std::vector<uint64_t>& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id);
|
||||
void remove_transfer_from_expiration_list(uint64_t transfer_index);
|
||||
|
|
@ -953,10 +953,11 @@ namespace boost
|
|||
a & x.contract;
|
||||
a & x.selected_indicies;
|
||||
a & x.srv_attachments;
|
||||
a & x.unlock_time;
|
||||
//do not store this items in the file since it's quite easy to restore it from original tx
|
||||
if (Archive::is_loading::value)
|
||||
{
|
||||
x.unlock_time = tools::wallet2::get_max_unlock_time_from_receive_indices(x.tx, x.td);
|
||||
|
||||
x.is_service = currency::is_service_tx(x.tx);
|
||||
x.is_mixing = currency::is_mixin_tx(x.tx);
|
||||
x.is_mining = currency::is_coinbase(x.tx);
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ bool test_generator::build_wallets(const blockchain_vector& blocks,
|
|||
currency::core_runtime_config pc = cc;
|
||||
pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE;
|
||||
pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH;
|
||||
pc.hard_fork1_starts_after_height = m_hardfork_after_heigh;
|
||||
wallets.back()->set_core_runtime_config(pc);
|
||||
}
|
||||
|
||||
|
|
@ -481,6 +482,7 @@ bool test_generator::find_kernel(const std::list<currency::account_base>& accs,
|
|||
uint64_t& found_timestamp,
|
||||
crypto::hash& found_kh)
|
||||
{
|
||||
bool is_after_hardfork = blck_chain.size() > m_hardfork_after_heigh ? true : false;
|
||||
uint64_t median_timestamp = get_timestamps_median(blck_chain);
|
||||
wide_difficulty_type basic_diff = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -941,6 +941,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(before_hard_fork_1_cumulative_difficulty);
|
||||
GENERATE_AND_PLAY(inthe_middle_hard_fork_1_cumulative_difficulty);
|
||||
GENERATE_AND_PLAY(after_hard_fork_1_cumulative_difficulty);
|
||||
GENERATE_AND_PLAY(hard_fork_1_locked_mining_test);
|
||||
|
||||
//GENERATE_AND_PLAY(gen_block_reward); */
|
||||
|
||||
|
|
|
|||
|
|
@ -34,3 +34,4 @@
|
|||
#include "misc_tests.h"
|
||||
#include "emission_test.h"
|
||||
#include "hard_fork_1_locked_pos_test.h"
|
||||
#include "hard_fork_1_consensus_test.h"
|
||||
|
|
|
|||
119
tests/core_tests/hard_fork_1_consensus_test.cpp
Normal file
119
tests/core_tests/hard_fork_1_consensus_test.cpp
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "chaingen.h"
|
||||
#include "pos_validation.h"
|
||||
#include "tx_builder.h"
|
||||
#include "hard_fork_1_consensus_test.h"
|
||||
#include "random_helper.h"
|
||||
|
||||
using namespace epee;
|
||||
using namespace crypto;
|
||||
using namespace currency;
|
||||
|
||||
hard_fork_1_cumulative_difficulty_base::hard_fork_1_cumulative_difficulty_base()
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(hard_fork_1_cumulative_difficulty_base, c1);
|
||||
REGISTER_CALLBACK_METHOD(hard_fork_1_cumulative_difficulty_base, configure_core);
|
||||
}
|
||||
|
||||
bool hard_fork_1_cumulative_difficulty_base::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
random_state_test_restorer::reset_random();
|
||||
|
||||
GENERATE_ACCOUNT(preminer_acc);
|
||||
GENERATE_ACCOUNT(miner_acc);
|
||||
m_accounts.push_back(miner_acc);
|
||||
std::list<account_base> miner_acc_lst(1, miner_acc);
|
||||
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, preminer_acc, 1564434616);
|
||||
generator.set_hardfork_height(get_hardfork_height());
|
||||
|
||||
DO_CALLBACK(events, "configure_core");
|
||||
REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3);
|
||||
block last_block = blk_0r;
|
||||
for (size_t i = 0; i != 20; i++)
|
||||
{
|
||||
MAKE_NEXT_POS_BLOCK(events, next_blk_pos, last_block, miner_acc, miner_acc_lst);
|
||||
MAKE_NEXT_BLOCK(events, next_blk_pow, next_blk_pos, miner_acc);
|
||||
events.push_back(event_core_time(next_blk_pow.timestamp - 10));
|
||||
|
||||
last_block = next_blk_pow;
|
||||
}
|
||||
|
||||
generator.set_pos_to_low_timestamp(true);
|
||||
last_block = blk_0r;
|
||||
for (size_t i = 0; i != 20; i++)
|
||||
{
|
||||
MAKE_NEXT_POS_BLOCK(events, next_blk_pos, last_block, miner_acc, miner_acc_lst);
|
||||
MAKE_NEXT_BLOCK_TIMESTAMP_ADJUSTMENT(-14, events, next_blk_pow, next_blk_pos, miner_acc);
|
||||
last_block = next_blk_pow;
|
||||
}
|
||||
|
||||
|
||||
DO_CALLBACK(events, "c1");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hard_fork_1_cumulative_difficulty_base::configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config();
|
||||
pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; //four blocks
|
||||
pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; //four blocks
|
||||
pc.hard_fork1_starts_after_height = get_hardfork_height();
|
||||
|
||||
c.get_blockchain_storage().set_core_runtime_config(pc);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool before_hard_fork_1_cumulative_difficulty::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
|
||||
std::shared_ptr<block_extended_info> last_pow_block = c.get_blockchain_storage().get_last_block_of_type(false);
|
||||
std::shared_ptr<block_extended_info> last_pos_block = c.get_blockchain_storage().get_last_block_of_type(true);
|
||||
CHECK_AND_ASSERT_MES(last_pow_block->cumulative_diff_precise == 184, false, "Incorrect condition failed: last_pow_block->cumulative_diff_precise == 184");
|
||||
CHECK_AND_ASSERT_MES(last_pos_block->cumulative_diff_precise == 20, false, "Incorrect condition failed: last_pos_block->cumulative_diff_precise == 20");
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t before_hard_fork_1_cumulative_difficulty::get_hardfork_height()const
|
||||
{
|
||||
return 10000; //just big number which is obviously bigger then test blockchain
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool inthe_middle_hard_fork_1_cumulative_difficulty::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
|
||||
std::shared_ptr<block_extended_info> last_pow_block = c.get_blockchain_storage().get_last_block_of_type(false);
|
||||
std::shared_ptr<block_extended_info> last_pos_block = c.get_blockchain_storage().get_last_block_of_type(true);
|
||||
CHECK_AND_ASSERT_MES(last_pow_block->cumulative_diff_precise == 184, false, "Incorrect condition failed: last_pow_block->cumulative_diff_precise == 184");
|
||||
CHECK_AND_ASSERT_MES(last_pos_block->cumulative_diff_precise == 20, false, "Incorrect condition failed: last_pos_block->cumulative_diff_precise == 20");
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t inthe_middle_hard_fork_1_cumulative_difficulty::get_hardfork_height()const
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
bool after_hard_fork_1_cumulative_difficulty::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
|
||||
std::shared_ptr<block_extended_info> last_pow_block = c.get_blockchain_storage().get_last_block_of_type(false);
|
||||
std::shared_ptr<block_extended_info> last_pos_block = c.get_blockchain_storage().get_last_block_of_type(true);
|
||||
CHECK_AND_ASSERT_MES(last_pow_block->cumulative_diff_precise == 172, false, "Incorrect condition failed: last_pow_block->cumulative_diff_precise == 184");
|
||||
CHECK_AND_ASSERT_MES(last_pos_block->cumulative_diff_precise == 199, false, "Incorrect condition failed: last_pos_block->cumulative_diff_precise == 20");
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t after_hard_fork_1_cumulative_difficulty::get_hardfork_height()const
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
40
tests/core_tests/hard_fork_1_consensus_test.h
Normal file
40
tests/core_tests/hard_fork_1_consensus_test.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
#include "chaingen.h"
|
||||
#include "wallet_tests_basic.h"
|
||||
|
||||
|
||||
struct hard_fork_1_cumulative_difficulty_base : public wallet_test
|
||||
{
|
||||
hard_fork_1_cumulative_difficulty_base();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
bool configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)= 0;
|
||||
virtual uint64_t get_hardfork_height()const =0;
|
||||
};
|
||||
|
||||
// this test check if code still work same way as it supposed to work before hard fork point
|
||||
struct before_hard_fork_1_cumulative_difficulty : public hard_fork_1_cumulative_difficulty_base
|
||||
{
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual uint64_t get_hardfork_height()const;
|
||||
};
|
||||
|
||||
// this test check if code still work same way as it supposed to work is split happened before hard fork point but finished after hard fork point
|
||||
struct inthe_middle_hard_fork_1_cumulative_difficulty : public hard_fork_1_cumulative_difficulty_base
|
||||
{
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual uint64_t get_hardfork_height()const;
|
||||
};
|
||||
|
||||
// this test check if code follow the new consensus algorithm and prefer balanced branch of the blockchain tree
|
||||
struct after_hard_fork_1_cumulative_difficulty : public hard_fork_1_cumulative_difficulty_base
|
||||
{
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual uint64_t get_hardfork_height()const;
|
||||
};
|
||||
|
||||
|
|
@ -13,19 +13,21 @@ using namespace epee;
|
|||
using namespace crypto;
|
||||
using namespace currency;
|
||||
|
||||
hard_fork_1_cumulative_difficulty_base::hard_fork_1_cumulative_difficulty_base()
|
||||
hard_fork_1_locked_mining_test::hard_fork_1_locked_mining_test()
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(hard_fork_1_cumulative_difficulty_base, c1);
|
||||
REGISTER_CALLBACK_METHOD(hard_fork_1_cumulative_difficulty_base, configure_core);
|
||||
REGISTER_CALLBACK_METHOD(hard_fork_1_locked_mining_test, c1);
|
||||
REGISTER_CALLBACK_METHOD(hard_fork_1_locked_mining_test, configure_core);
|
||||
}
|
||||
|
||||
bool hard_fork_1_cumulative_difficulty_base::generate(std::vector<test_event_entry>& events) const
|
||||
bool hard_fork_1_locked_mining_test::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
random_state_test_restorer::reset_random();
|
||||
|
||||
GENERATE_ACCOUNT(preminer_acc);
|
||||
GENERATE_ACCOUNT(miner_acc);
|
||||
GENERATE_ACCOUNT(pos_miner_acc);
|
||||
m_accounts.push_back(miner_acc);
|
||||
m_accounts.push_back(pos_miner_acc);
|
||||
std::list<account_base> miner_acc_lst(1, miner_acc);
|
||||
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, preminer_acc, 1564434616);
|
||||
|
|
@ -33,31 +35,43 @@ bool hard_fork_1_cumulative_difficulty_base::generate(std::vector<test_event_ent
|
|||
|
||||
DO_CALLBACK(events, "configure_core");
|
||||
REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3);
|
||||
block last_block = blk_0r;
|
||||
for (size_t i = 0; i != 20; i++)
|
||||
|
||||
//construc tx that locks transaction for some period of time
|
||||
// make a couple of huge txs
|
||||
bool r = false;
|
||||
std::vector<extra_v> extra;
|
||||
|
||||
std::vector<tx_source_entry> sources_1;
|
||||
r = fill_tx_sources(sources_1, events, blk_0r, miner_acc.get_keys(), 2000000000000+TESTS_DEFAULT_FEE, 0);
|
||||
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed");
|
||||
std::vector<tx_destination_entry> destinations({ tx_destination_entry(2010000000000, pos_miner_acc.get_public_address()) });
|
||||
crypto::secret_key stub;
|
||||
transaction tx_1 = AUTO_VAL_INIT(tx_1);
|
||||
r = construct_tx(miner_acc.get_keys(), sources_1, destinations, extra, empty_attachment, tx_1, stub, get_block_height(blk_0r)+2000);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
events.push_back(tx_1); // push it to the pool
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_0r_tx, blk_0r, miner_acc, tx_1);
|
||||
|
||||
block last_block = blk_0r_tx;
|
||||
for (size_t i = 0; i != CURRENCY_MINED_MONEY_UNLOCK_WINDOW; i++)
|
||||
{
|
||||
MAKE_NEXT_POS_BLOCK(events, next_blk_pos, last_block, miner_acc, miner_acc_lst);
|
||||
MAKE_NEXT_BLOCK(events, next_blk_pow, next_blk_pos, miner_acc);
|
||||
events.push_back(event_core_time(next_blk_pow.timestamp - 10));
|
||||
|
||||
last_block = next_blk_pow;
|
||||
}
|
||||
|
||||
generator.set_pos_to_low_timestamp(true);
|
||||
last_block = blk_0r;
|
||||
for (size_t i = 0; i != 20; i++)
|
||||
{
|
||||
MAKE_NEXT_POS_BLOCK(events, next_blk_pos, last_block, miner_acc, miner_acc_lst);
|
||||
MAKE_NEXT_BLOCK_TIMESTAMP_ADJUSTMENT(-14, events, next_blk_pow, next_blk_pos, miner_acc);
|
||||
last_block = next_blk_pow;
|
||||
}
|
||||
|
||||
|
||||
std::list<currency::account_base> accounts_2;
|
||||
accounts_2.push_back(pos_miner_acc);
|
||||
//let's try to mint PoS block from locked account
|
||||
MAKE_NEXT_POS_BLOCK(events, next_blk_pos, last_block, pos_miner_acc, accounts_2);
|
||||
|
||||
DO_CALLBACK(events, "c1");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hard_fork_1_cumulative_difficulty_base::configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
bool hard_fork_1_locked_mining_test::configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config();
|
||||
pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; //four blocks
|
||||
|
|
@ -68,52 +82,16 @@ bool hard_fork_1_cumulative_difficulty_base::configure_core(currency::core& c, s
|
|||
return true;
|
||||
}
|
||||
|
||||
bool before_hard_fork_1_cumulative_difficulty::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
bool hard_fork_1_locked_mining_test::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
|
||||
std::shared_ptr<block_extended_info> last_pow_block = c.get_blockchain_storage().get_last_block_of_type(false);
|
||||
std::shared_ptr<block_extended_info> last_pos_block = c.get_blockchain_storage().get_last_block_of_type(true);
|
||||
CHECK_AND_ASSERT_MES(last_pow_block->cumulative_diff_precise == 184, false, "Incorrect condition failed: last_pow_block->cumulative_diff_precise == 184");
|
||||
CHECK_AND_ASSERT_MES(last_pos_block->cumulative_diff_precise == 20, false, "Incorrect condition failed: last_pos_block->cumulative_diff_precise == 20");
|
||||
//
|
||||
uint64_t h = c.get_blockchain_storage().get_current_blockchain_size();
|
||||
CHECK_AND_ASSERT_MES(h == 36, false, "locked pos block is not accepted");
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t before_hard_fork_1_cumulative_difficulty::get_hardfork_height()const
|
||||
uint64_t hard_fork_1_locked_mining_test::get_hardfork_height()const
|
||||
{
|
||||
return 10000; //just big number which is obviously bigger then test blockchain
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool inthe_middle_hard_fork_1_cumulative_difficulty::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
|
||||
std::shared_ptr<block_extended_info> last_pow_block = c.get_blockchain_storage().get_last_block_of_type(false);
|
||||
std::shared_ptr<block_extended_info> last_pos_block = c.get_blockchain_storage().get_last_block_of_type(true);
|
||||
CHECK_AND_ASSERT_MES(last_pow_block->cumulative_diff_precise == 184, false, "Incorrect condition failed: last_pow_block->cumulative_diff_precise == 184");
|
||||
CHECK_AND_ASSERT_MES(last_pos_block->cumulative_diff_precise == 20, false, "Incorrect condition failed: last_pos_block->cumulative_diff_precise == 20");
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t inthe_middle_hard_fork_1_cumulative_difficulty::get_hardfork_height()const
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
bool after_hard_fork_1_cumulative_difficulty::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
|
||||
std::shared_ptr<block_extended_info> last_pow_block = c.get_blockchain_storage().get_last_block_of_type(false);
|
||||
std::shared_ptr<block_extended_info> last_pos_block = c.get_blockchain_storage().get_last_block_of_type(true);
|
||||
CHECK_AND_ASSERT_MES(last_pow_block->cumulative_diff_precise == 172, false, "Incorrect condition failed: last_pow_block->cumulative_diff_precise == 184");
|
||||
CHECK_AND_ASSERT_MES(last_pos_block->cumulative_diff_precise == 199, false, "Incorrect condition failed: last_pos_block->cumulative_diff_precise == 20");
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t after_hard_fork_1_cumulative_difficulty::get_hardfork_height()const
|
||||
{
|
||||
return 12;
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,33 +8,11 @@
|
|||
#include "wallet_tests_basic.h"
|
||||
|
||||
|
||||
struct hard_fork_1_cumulative_difficulty_base : public wallet_test
|
||||
struct hard_fork_1_locked_mining_test : public wallet_test
|
||||
{
|
||||
hard_fork_1_cumulative_difficulty_base();
|
||||
hard_fork_1_locked_mining_test();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
bool configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)= 0;
|
||||
virtual uint64_t get_hardfork_height()const =0;
|
||||
};
|
||||
|
||||
// this test check if code still work same way as it supposed to work before hard fork point
|
||||
struct before_hard_fork_1_cumulative_difficulty : public hard_fork_1_cumulative_difficulty_base
|
||||
{
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual uint64_t get_hardfork_height()const;
|
||||
};
|
||||
|
||||
// this test check if code still work same way as it supposed to work is split happened before hard fork point but finished after hard fork point
|
||||
struct inthe_middle_hard_fork_1_cumulative_difficulty : public hard_fork_1_cumulative_difficulty_base
|
||||
{
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual uint64_t get_hardfork_height()const;
|
||||
};
|
||||
|
||||
// this test check if code follow the new consensus algorithm and prefer balanced branch of the blockchain tree
|
||||
struct after_hard_fork_1_cumulative_difficulty : public hard_fork_1_cumulative_difficulty_base
|
||||
{
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
virtual uint64_t get_hardfork_height()const;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue