Test suite fixes

This commit is contained in:
Jason Rhinelander 2021-07-05 23:48:18 -03:00
parent a841886e62
commit de3340e5c8
21 changed files with 219 additions and 902 deletions

View File

@ -146,9 +146,6 @@ public:
, const crypto::hash& blk_hash
) override { }
virtual cryptonote::block get_block_from_height(uint64_t height) const override { return cryptonote::block(); }
virtual void set_hard_fork_version(uint64_t height, uint8_t version) override {}
virtual uint8_t get_hard_fork_version(uint64_t height) const override { return 0; }
virtual void check_hard_fork_info() override {}
virtual uint32_t get_blockchain_pruning_seed() const override { return 0; }
virtual bool prune_blockchain(uint32_t pruning_seed = 0) override { return true; }

View File

@ -55,8 +55,6 @@ namespace cryptonote
KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(m_encryption_iv, default_iv)
END_KV_SERIALIZE_MAP()
account_keys& operator=(account_keys const&) = default;
void encrypt(const crypto::chacha_key &key);
void decrypt(const crypto::chacha_key &key);
void encrypt_viewkey(const crypto::chacha_key &key);

View File

@ -26,6 +26,7 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cryptonote_config.h"
#define IN_UNIT_TESTS
#include <stdio.h>
@ -101,8 +102,6 @@ public:
return top;
}
virtual void pop_block(cryptonote::block &blk, std::vector<cryptonote::transaction> &txs) override { blocks.pop_back(); }
virtual void set_hard_fork_version(uint64_t height, uint8_t version) override { if (height >= hf.size()) hf.resize(height + 1); hf[height] = version; }
virtual uint8_t get_hard_fork_version(uint64_t height) const override { if (height >= hf.size()) return 255; return hf[height]; }
private:
std::vector<block_t> blocks;
@ -111,26 +110,6 @@ private:
}
#define PREFIX_WINDOW(hf_version,window) \
blockchain_objects_t bc_objects = {}; \
struct get_test_options { \
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks; \
const cryptonote::test_options test_options = { \
hard_forks, \
window, \
}; \
get_test_options(): hard_forks{{std::make_pair(cryptonote::network_version_7, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)LONG_TERM_BLOCK_WEIGHT_WINDOW)}} {} \
} opts; \
cryptonote::Blockchain *bc = &bc_objects.m_blockchain; \
bool r = bc->init(new TestDB(), nullptr /*ons_db*/, cryptonote::FAKECHAIN, true, &opts.test_options, 0); \
if (!r) \
{ \
fprintf(stderr, "Failed to init blockchain\n"); \
exit(1); \
}
#define PREFIX(hf_version) PREFIX_WINDOW(hf_version, LONG_TERM_BLOCK_WEIGHT_WINDOW)
static uint32_t lcg_seed = 0;
static uint32_t lcg()
@ -141,15 +120,27 @@ static uint32_t lcg()
static void test(test_t t, uint64_t blocks)
{
PREFIX(HF_VERSION_LONG_TERM_BLOCK_WEIGHT);
blockchain_objects_t bc_objects = {};
const std::vector<cryptonote::hard_fork> hard_forks{
{cryptonote::network_version_7, 0, 0, 0},
{cryptonote::network_version_11_infinite_staking, 0, 5000, 0}};
const cryptonote::test_options test_options{hard_forks, 5000};
auto& bc = bc_objects.m_blockchain;
if (!bc.init(new TestDB(), nullptr, cryptonote ::FAKECHAIN, true, &test_options, 0)) {
fprintf(stderr, "Failed to init blockchain\n");
exit(1);
};
for (uint64_t h = 0; h < LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
{
cryptonote::block b;
b.major_version = cryptonote::network_version_7;
b.minor_version = cryptonote::network_version_7;
bc->get_db().add_block(std::make_pair(b, ""), 300000, 300000, bc->get_db().height(), bc->get_db().height(), {});
if (!bc->update_next_cumulative_weight_limit())
bc.get_db().add_block(std::make_pair(b, ""), 300000, 300000, bc.get_db().height(), bc.get_db().height(), {});
if (!bc.update_next_cumulative_weight_limit())
{
fprintf(stderr, "Failed to update cumulative weight limit 1\n");
exit(1);
@ -159,7 +150,7 @@ static void test(test_t t, uint64_t blocks)
for (uint64_t h = 0; h < blocks; ++h)
{
uint64_t w;
uint64_t effective_block_weight_median = bc->get_current_cumulative_block_weight_median();
uint64_t effective_block_weight_median = bc.get_current_cumulative_block_weight_median();
switch (t)
{
case test_lcg:
@ -170,7 +161,7 @@ static void test(test_t t, uint64_t blocks)
break;
}
case test_max:
w = bc->get_current_cumulative_block_weight_limit();
w = bc.get_current_cumulative_block_weight_limit();
break;
case test_min:
w = 90;
@ -178,13 +169,13 @@ static void test(test_t t, uint64_t blocks)
default:
exit(1);
}
uint64_t ltw = bc->get_next_long_term_block_weight(w);
uint64_t ltw = bc.get_next_long_term_block_weight(w);
cryptonote::block b;
b.major_version = HF_VERSION_LONG_TERM_BLOCK_WEIGHT;
b.minor_version = HF_VERSION_LONG_TERM_BLOCK_WEIGHT;
bc->get_db().add_block(std::make_pair(std::move(b), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {});
bc.get_db().add_block(std::make_pair(std::move(b), ""), w, ltw, bc.get_db().height(), bc.get_db().height(), {});
if (!bc->update_next_cumulative_weight_limit())
if (!bc.update_next_cumulative_weight_limit())
{
fprintf(stderr, "Failed to update cumulative weight limit\n");
exit(1);

View File

@ -571,10 +571,10 @@ bool gen_block_is_too_big::generate(std::vector<test_event_entry>& events) const
bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& events) const
{
#if 1
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10);
gen.add_mined_money_unlock_blocks();

View File

@ -61,11 +61,11 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
++amounts_paid_len;
}
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = {
{7,0}, {8,1}, {target_hf, NUM_UNLOCKED_BLOCKS + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW + 1},
std::vector<cryptonote::hard_fork> hard_forks = {
{7,0,0}, {8,0,1}, {target_hf, 0, NUM_UNLOCKED_BLOCKS + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW + 1},
};
event_replay_settings settings = {};
settings.hard_forks = hard_forks;
settings.hard_forks = hard_forks;
events.push_back(settings);
// create 12 miner accounts, and have them mine the next 48 blocks
@ -78,8 +78,8 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
for (size_t i = 0; i < NUM_MINERS; ++i)
miner_accounts[i].generate();
uint8_t const first_hf = hard_forks[1].first;
uint8_t const last_hf = hard_forks.back().first;
uint8_t const first_hf = hard_forks[1].version;
uint8_t const last_hf = hard_forks.back().version;
generator.m_hf_version = first_hf;
for (size_t n = 0; n < NUM_UNLOCKED_BLOCKS; ++n) {
CHECK_AND_ASSERT_MES(

View File

@ -71,21 +71,21 @@ void oxen_register_callback(std::vector<test_event_entry> &events,
events.push_back(oxen_callback_entry{callback_name, callback});
}
std::vector<std::pair<uint8_t, uint64_t>>
std::vector<cryptonote::hard_fork>
oxen_generate_hard_fork_table(uint8_t hf_version, uint64_t pos_delay)
{
assert(hf_version < cryptonote::network_version_count);
// We always need block 0 == v7 for the genesis block:
std::vector<std::pair<uint8_t, uint64_t>> result{{cryptonote::network_version_7, 0}};
std::vector<cryptonote::hard_fork> result{{cryptonote::network_version_7, 0, 0}};
uint64_t version_height = 1;
// HF15 reduces and HF16+ eliminates miner block rewards, so we need to ensure we have enough
// HF14 blocks to generate enough LOKI for tests:
if (hf_version > cryptonote::network_version_14_blink) {
result.emplace_back(cryptonote::network_version_14_blink, version_height);
result.push_back({cryptonote::network_version_14_blink, 0, version_height});
version_height += pos_delay;
}
result.emplace_back(hf_version, version_height);
result.push_back({hf_version, 0, version_height});
return result;
}
@ -163,7 +163,7 @@ std::vector<cryptonote::block> oxen_chain_generator_db::get_blocks_range(const u
return result;
}
oxen_chain_generator::oxen_chain_generator(std::vector<test_event_entry> &events, const std::vector<std::pair<uint8_t, uint64_t>> &hard_forks)
oxen_chain_generator::oxen_chain_generator(std::vector<test_event_entry> &events, const std::vector<cryptonote::hard_fork>& hard_forks)
: events_(events)
, hard_forks_(hard_forks)
{
@ -270,7 +270,7 @@ cryptonote::account_base oxen_chain_generator::add_account()
void oxen_chain_generator::add_blocks_until_version(uint8_t hf_version)
{
assert(hard_forks_.size());
assert(hf_version_ <= hard_forks_.back().first);
assert(hf_version_ <= hard_forks_.back().version);
assert(db_.blocks.size() >= 1); // NOTE: We must have genesis block
for (;;)
{
@ -462,7 +462,7 @@ oxen_chain_generator::create_registration_tx(const cryptonote::account_base &src
uint64_t new_height = get_block_height(top().block) + 1;
uint8_t new_hf_version = get_hf_version_at(new_height);
const auto staking_requirement = service_nodes::get_staking_requirement(cryptonote::FAKECHAIN, new_height, new_hf_version);
const auto staking_requirement = service_nodes::get_staking_requirement(cryptonote::FAKECHAIN, new_height);
uint64_t amount = service_nodes::portions_to_amount(portions[0], staking_requirement);
uint64_t unlock_time = 0;
@ -1115,8 +1115,8 @@ uint8_t oxen_chain_generator::get_hf_version_at(uint64_t height) const {
uint8_t cur_hf_ver = 0;
for (auto i = 0u; i < hard_forks_.size(); ++i)
{
if (height < hard_forks_[i].second) break;
cur_hf_ver = hard_forks_[i].first;
if (height < hard_forks_[i].height) break;
cur_hf_ver = hard_forks_[i].version;
}
assert(cur_hf_ver != 0);
@ -1447,7 +1447,7 @@ cryptonote::transaction make_registration_tx(std::vector<test_event_entry>& even
uint8_t hf_version)
{
const auto new_height = cryptonote::get_block_height(head) + 1;
const auto staking_requirement = service_nodes::get_staking_requirement(cryptonote::FAKECHAIN, new_height, hf_version);
const auto staking_requirement = service_nodes::get_staking_requirement(cryptonote::FAKECHAIN, new_height);
uint64_t amount = service_nodes::portions_to_amount(portions[0], staking_requirement);
cryptonote::transaction tx;
@ -2269,7 +2269,7 @@ uint64_t get_unlocked_balance(const cryptonote::account_base& addr, const std::v
return res;
}
bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks)
bool extract_hard_forks(const std::vector<test_event_entry>& events, std::vector<cryptonote::hard_fork>& hard_forks)
{
for(auto & ev : events)
{

View File

@ -50,6 +50,7 @@
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/hardfork.h"
#include "cryptonote_config.h"
#include "cryptonote_core/cryptonote_core.h"
#include "cryptonote_basic/cryptonote_boost_serialization.h"
@ -203,11 +204,10 @@ private:
}
};
typedef std::vector<std::pair<uint8_t, uint64_t>> v_hardforks_t;
struct event_replay_settings
{
event_replay_settings() = default;
std::optional<v_hardforks_t> hard_forks;
std::optional<std::vector<cryptonote::hard_fork>> hard_forks;
private:
friend class boost::serialization::access;
@ -588,7 +588,7 @@ uint64_t get_amount(const cryptonote::account_base& account, const cryptonote::t
uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
uint64_t get_unlocked_balance(const cryptonote::account_base& addr, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks);
bool extract_hard_forks(const std::vector<test_event_entry>& events, std::vector<cryptonote::hard_fork>& hard_forks);
/************************************************************************/
/* */
/************************************************************************/
@ -908,7 +908,7 @@ inline bool replay_events_through_core_plain(cryptonote::core& cr, const std::ve
//--------------------------------------------------------------------------
template<typename t_test_class>
struct get_test_options {
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks = {{7, 0}};
const std::vector<cryptonote::hard_fork> hard_forks = {{7, 0, 0, 0}};
const cryptonote::test_options test_options = {
hard_forks, 0
};
@ -947,7 +947,7 @@ inline bool do_replay_events_get_core(std::vector<test_event_entry>& events, cry
// events should be passed a testing context which should have this specific
// testing situation
// Hardforks can be specified in events.
v_hardforks_t derived_hardforks;
std::vector<cryptonote::hard_fork> derived_hardforks;
bool use_derived_hardforks = extract_hard_forks(events, derived_hardforks);
const cryptonote::test_options derived_test_options =
{
@ -1152,18 +1152,6 @@ inline bool do_replay_file(const std::string& filename)
#define SET_EVENT_VISITOR_SETT(VEC_EVENTS, SETT, VAL) VEC_EVENTS.push_back(event_visitor_settings(SETT, VAL));
#define GENERATE(filename, generator_class) \
{ \
std::vector<test_event_entry> events; \
generator_class g; \
g.generate(events); \
if (!tools::serialize_obj_to_file(events, filename)) \
{ \
MERROR("Failed to serialize data to file: " << filename); \
throw std::runtime_error("Failed to serialize data to file"); \
} \
}
#define PLAY(filename, generator_class) \
if(!do_replay_file<generator_class>(filename)) \
@ -1242,19 +1230,6 @@ inline bool do_replay_file(const std::string& filename)
CATCH_GENERATE_REPLAY_CORE(generator_class, generator_class_instance, CORE); \
}
#define CALL_TEST(test_name, function) \
{ \
if(!function()) \
{ \
MERROR("#TEST# Failed " << test_name); \
return 1; \
} \
else \
{ \
MGINFO_GREEN("#TEST# Succeeded " << test_name); \
} \
}
#define QUOTEME(x) #x
#define DEFINE_TESTS_ERROR_CONTEXT(text) const char* perr_context = text;
#define CHECK_TEST_CONDITION(cond) CHECK_AND_ASSERT_MES(cond, false, "[" << perr_context << "] failed: \"" << QUOTEME(cond) << "\"")
@ -1263,7 +1238,7 @@ inline bool do_replay_file(const std::string& filename)
#define CHECK_NOT_EQ(v1, v2) CHECK_AND_ASSERT_MES(!(v1 == v2), false, "[" << perr_context << "] failed: \"" << QUOTEME(v1) << " != " << QUOTEME(v2) << "\", " << v1 << " == " << v2)
#define MK_COINS(amount) (UINT64_C(amount) * COIN)
static std::string make_junk() {
inline std::string make_junk() {
std::string junk;
junk.reserve(1024);
for (size_t i = 0; i < 256; i++)
@ -1393,7 +1368,7 @@ public:
void fill_nonce_with_oxen_generator(struct oxen_chain_generator const *generator, cryptonote::block& blk, const cryptonote::difficulty_type& diffic, uint64_t height);
void oxen_register_callback(std::vector<test_event_entry> &events, std::string const &callback_name, oxen_callback callback);
std::vector<std::pair<uint8_t, uint64_t>> oxen_generate_hard_fork_table(uint8_t hf_version = cryptonote::network_version_count - 1, uint64_t pos_delay = 60);
std::vector<cryptonote::hard_fork> oxen_generate_hard_fork_table(uint8_t hf_version = cryptonote::network_version_count - 1, uint64_t pos_delay = 60);
struct oxen_blockchain_entry
{
@ -1460,10 +1435,10 @@ struct oxen_chain_generator
oxen_chain_generator_db db_;
uint8_t hf_version_ = cryptonote::network_version_7;
std::vector<test_event_entry>& events_;
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks_;
const std::vector<cryptonote::hard_fork> hard_forks_;
cryptonote::account_base first_miner_;
oxen_chain_generator(std::vector<test_event_entry> &events, const std::vector<std::pair<uint8_t, uint64_t>> &hard_forks);
oxen_chain_generator(std::vector<test_event_entry> &events, const std::vector<cryptonote::hard_fork>& hard_forks);
uint64_t height() const { return cryptonote::get_block_height(db_.blocks.back().block); }
uint64_t chain_height() const { return height() + 1; }

View File

@ -39,11 +39,6 @@ namespace po = boost::program_options;
namespace
{
const command_line::arg_descriptor<std::string> arg_test_data_path = {"test_data_path", "", ""};
const command_line::arg_descriptor<bool> arg_generate_test_data = {"generate_test_data", ""};
const command_line::arg_descriptor<bool> arg_play_test_data = {"play_test_data", ""};
const command_line::arg_descriptor<bool> arg_generate_and_play_test_data = {"generate_and_play_test_data", ""};
const command_line::arg_descriptor<bool> arg_test_transactions = {"test_transactions", ""};
const command_line::arg_descriptor<std::string> arg_filter = { "filter", "Regular expression filter for which tests to run" };
const command_line::arg_descriptor<bool> arg_list_tests = {"list_tests", ""};
const command_line::arg_descriptor<std::string> arg_log_level = {"log-level", ""};
@ -63,11 +58,6 @@ int main(int argc, char* argv[])
po::options_description desc_options("Allowed options");
command_line::add_arg(desc_options, command_line::arg_help);
command_line::add_arg(desc_options, arg_test_data_path);
command_line::add_arg(desc_options, arg_generate_test_data);
command_line::add_arg(desc_options, arg_play_test_data);
command_line::add_arg(desc_options, arg_generate_and_play_test_data);
command_line::add_arg(desc_options, arg_test_transactions);
command_line::add_arg(desc_options, arg_filter);
command_line::add_arg(desc_options, arg_list_tests);
command_line::add_arg(desc_options, arg_log_level);
@ -97,21 +87,7 @@ int main(int argc, char* argv[])
size_t tests_count = 0;
std::vector<std::string> failed_tests;
std::string tests_folder = command_line::get_arg(vm, arg_test_data_path);
bool list_tests = false;
if (command_line::get_arg(vm, arg_generate_test_data))
{
GENERATE("chain001.dat", gen_simple_chain_001);
}
else if (command_line::get_arg(vm, arg_play_test_data))
{
PLAY("chain001.dat", gen_simple_chain_001);
}
else if (command_line::get_arg(vm, arg_test_transactions))
{
CALL_TEST("TRANSACTIONS TESTS", test_transactions);
}
else
{
list_tests = command_line::get_arg(vm, arg_list_tests);

View File

@ -39,9 +39,9 @@ using namespace cryptonote;
bool gen_double_spend_in_tx::generate(std::vector<test_event_entry>& events) const
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(20);
gen.add_mined_money_unlock_blocks();
@ -114,9 +114,9 @@ bool gen_double_spend_in_tx::generate(std::vector<test_event_entry>& events) con
bool gen_double_spend_in_the_same_block::generate(std::vector<test_event_entry>& events) const
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10);
gen.add_mined_money_unlock_blocks();
@ -157,9 +157,9 @@ bool gen_double_spend_in_the_same_block::generate(std::vector<test_event_entry>&
bool gen_double_spend_in_different_blocks::generate(std::vector<test_event_entry>& events) const
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10);
gen.add_mined_money_unlock_blocks();
@ -200,9 +200,9 @@ bool gen_double_spend_in_different_blocks::generate(std::vector<test_event_entry
bool gen_double_spend_in_alt_chain_in_the_same_block::generate(std::vector<test_event_entry>& events) const
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10);
gen.add_mined_money_unlock_blocks();
@ -244,9 +244,9 @@ bool gen_double_spend_in_alt_chain_in_the_same_block::generate(std::vector<test_
bool gen_double_spend_in_alt_chain_in_different_blocks::generate(std::vector<test_event_entry>& events) const
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10);
gen.add_mined_money_unlock_blocks();
@ -285,9 +285,9 @@ bool gen_double_spend_in_alt_chain_in_different_blocks::generate(std::vector<tes
bool gen_double_spend_in_different_chains::generate(std::vector<test_event_entry>& events) const
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10);
gen.add_mined_money_unlock_blocks();

View File

@ -98,10 +98,10 @@ bool gen_uint_overflow_base::mark_last_valid_block(cryptonote::core& c, size_t e
bool gen_uint_overflow_1::generate(std::vector<test_event_entry>& events) const
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(40);
gen.add_mined_money_unlock_blocks();

View File

@ -82,7 +82,7 @@ private:
template<>
struct get_test_options<gen_multisig_tx_validation_base> {
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks = {std::make_pair(7, 0)};
const std::vector<cryptonote::hard_fork> hard_forks = {{7,0,0,0}};
const cryptonote::test_options test_options = {
hard_forks, 0
};

View File

@ -69,10 +69,10 @@ static void add_service_nodes(oxen_chain_generator &gen, size_t count)
// code path" again
bool oxen_checkpointing_alt_chain_handle_alt_blocks_at_tip::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::CHECKPOINT_QUORUM_SIZE);
@ -128,10 +128,10 @@ bool oxen_checkpointing_alt_chain_handle_alt_blocks_at_tip::generate(std::vector
// NOTE: - Checks that a chain with a checkpoint but less PoW is preferred over a chain that is longer with more PoW but no checkpoints
bool oxen_checkpointing_alt_chain_more_service_node_checkpoints_less_pow_overtakes::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
int constexpr NUM_SERVICE_NODES = service_nodes::CHECKPOINT_QUORUM_SIZE;
@ -165,10 +165,10 @@ bool oxen_checkpointing_alt_chain_more_service_node_checkpoints_less_pow_overtak
// NOTE: - A chain that receives checkpointing votes sufficient to form a checkpoint should reorg back accordingly
bool oxen_checkpointing_alt_chain_receive_checkpoint_votes_should_reorg_back::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
int constexpr NUM_SERVICE_NODES = service_nodes::CHECKPOINT_QUORUM_SIZE;
@ -232,9 +232,9 @@ bool oxen_checkpointing_alt_chain_receive_checkpoint_votes_should_reorg_back::ge
bool oxen_checkpointing_alt_chain_too_old_should_be_dropped::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
int constexpr NUM_SERVICE_NODES = service_nodes::CHECKPOINT_QUORUM_SIZE;
@ -267,10 +267,10 @@ bool oxen_checkpointing_alt_chain_too_old_should_be_dropped::generate(std::vecto
// available checkpoint heights whilst maintaining equal heights with the main chain
bool oxen_checkpointing_alt_chain_with_increasing_service_node_checkpoints::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::CHECKPOINT_QUORUM_SIZE);
@ -327,10 +327,10 @@ bool oxen_checkpointing_alt_chain_with_increasing_service_node_checkpoints::gene
// - Checks invalid vote (signature or key) is not accepted due to not being part of the quorum
bool oxen_checkpointing_service_node_checkpoint_from_votes::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::CHECKPOINT_QUORUM_SIZE);
@ -391,10 +391,10 @@ bool oxen_checkpointing_service_node_checkpoint_from_votes::generate(std::vector
// - Checks you can add a block after the 1st checkpoint out of 2 checkpoints.
bool oxen_checkpointing_service_node_checkpoints_check_reorg_windows::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::CHECKPOINT_QUORUM_SIZE);
@ -438,11 +438,11 @@ bool oxen_checkpointing_service_node_checkpoints_check_reorg_windows::generate(s
bool oxen_core_block_reward_unpenalized_pre_pulse::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_16_pulse - 1);
auto hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_16_pulse - 1);
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
uint8_t newest_hf = hard_forks.back().first;
uint8_t newest_hf = hard_forks.back().version;
assert(newest_hf >= cryptonote::network_version_13_enforce_checkpoints);
gen.add_mined_money_unlock_blocks();
@ -478,13 +478,13 @@ bool oxen_core_block_reward_unpenalized_pre_pulse::generate(std::vector<test_eve
bool oxen_core_block_reward_unpenalized_post_pulse::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_count -1, 150 /*Proof Of Stake Delay*/);
auto hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_count -1, 150 /*Proof Of Stake Delay*/);
oxen_chain_generator gen(events, hard_forks);
uint8_t const newest_hf = hard_forks.back().first;
uint8_t const newest_hf = hard_forks.back().version;
assert(newest_hf >= cryptonote::network_version_13_enforce_checkpoints);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
// Make big chunky TX's to trigger the block size penalty
@ -527,11 +527,11 @@ bool oxen_core_block_reward_unpenalized_post_pulse::generate(std::vector<test_ev
bool oxen_core_fee_burning::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
uint8_t newest_hf = hard_forks.back().first;
uint8_t newest_hf = hard_forks.back().version;
assert(newest_hf >= cryptonote::network_version_14_blink);
gen.add_mined_money_unlock_blocks();
@ -609,14 +609,14 @@ bool oxen_core_fee_burning::generate(std::vector<test_event_entry>& events)
bool oxen_core_governance_batched_reward::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_10_bulletproofs);
auto hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_10_bulletproofs);
uint64_t hf10_height = 0;
for (std::pair<uint8_t, uint64_t> hf_pair : hard_forks)
for (const auto& [maj, sn_rev, height, ts] : hard_forks)
{
if (hf_pair.first == cryptonote::network_version_10_bulletproofs)
if (maj == cryptonote::network_version_10_bulletproofs)
{
hf10_height = hf_pair.second;
hf10_height = height;
break;
}
}
@ -635,14 +635,14 @@ bool oxen_core_governance_batched_reward::generate(std::vector<test_event_entry>
// NOTE(oxen): Since hard fork 8 we have an emissions curve change, so if
// you don't atleast progress and generate blocks from hf8 you will run into
// problems
std::vector<std::pair<uint8_t, uint64_t>> other_hard_forks = {
std::make_pair(cryptonote::network_version_7, 0),
std::make_pair(cryptonote::network_version_8, 1),
std::make_pair(cryptonote::network_version_9_service_nodes, hf10_height)};
std::vector<cryptonote::hard_fork> other_hard_forks = {
{7,0,0,0},
{8,0,1,0},
{9,0,hf10_height,0}};
std::vector<test_event_entry> unused_events;
oxen_chain_generator no_batched_governance_generator(unused_events, other_hard_forks);
no_batched_governance_generator.add_blocks_until_version(other_hard_forks.back().first);
no_batched_governance_generator.add_blocks_until_version(other_hard_forks.back().version);
while(no_batched_governance_generator.height() < batched_governance_generator.height())
no_batched_governance_generator.create_and_add_next_block();
@ -685,9 +685,9 @@ bool oxen_core_governance_batched_reward::generate(std::vector<test_event_entry>
bool oxen_core_block_rewards_lrc6::generate(std::vector<test_event_entry>& events)
{
constexpr auto& network = cryptonote::get_config(cryptonote::FAKECHAIN);
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_15_ons);
hard_forks.emplace_back(cryptonote::network_version_16_pulse, hard_forks.back().second + network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS + 10);
hard_forks.emplace_back(cryptonote::network_version_17, hard_forks.back().second + network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS);
auto hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_15_ons);
hard_forks.push_back({cryptonote::network_version_16_pulse, 0, hard_forks.back().height + network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS + 10, 0});
hard_forks.push_back({cryptonote::network_version_17, 0, hard_forks.back().height + network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS});
oxen_chain_generator batched_governance_generator(events, hard_forks);
batched_governance_generator.add_blocks_until_version(cryptonote::network_version_17);
batched_governance_generator.add_n_blocks(network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS);
@ -695,12 +695,12 @@ bool oxen_core_block_rewards_lrc6::generate(std::vector<test_event_entry>& event
uint64_t hf15_height = 0, hf16_height = 0, hf17_height = 0;
for (const auto &hf : hard_forks)
{
if (hf.first == cryptonote::network_version_15_ons)
hf15_height = hf.second;
else if (hf.first == cryptonote::network_version_16_pulse)
hf16_height = hf.second;
if (hf.version == cryptonote::network_version_15_ons)
hf15_height = hf.height;
else if (hf.version == cryptonote::network_version_16_pulse)
hf16_height = hf.height;
else
hf17_height = hf.second;
hf17_height = hf.height;
}
oxen_register_callback(events, "check_lrc6_7_block_rewards", [hf15_height, hf16_height, hf17_height, interval=network.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS](cryptonote::core &c, size_t ev_index)
@ -768,12 +768,12 @@ bool oxen_core_block_rewards_lrc6::generate(std::vector<test_event_entry>& event
bool oxen_core_test_deregister_preferred::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
const auto miner = gen.first_miner();
const auto alice = gen.add_account();
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10); /// give miner some outputs to spend and unlock them
add_service_nodes(gen, 12);
gen.add_mined_money_unlock_blocks();
@ -831,11 +831,11 @@ bool oxen_core_test_deregister_preferred::generate(std::vector<test_event_entry>
// to test), they don't get deregistered.
bool oxen_core_test_deregister_safety_buffer::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
const auto miner = gen.first_miner();
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::STATE_CHANGE_QUORUM_SIZE * 2 + 1);
gen.add_n_blocks(1);
@ -880,9 +880,9 @@ bool oxen_core_test_deregister_safety_buffer::generate(std::vector<test_event_en
// Daemon A accepts the block without X. Now X is too old and should not be added in future blocks.
bool oxen_core_test_deregister_too_old::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
/// generate some outputs and unlock them
gen.add_n_blocks(20);
@ -906,10 +906,10 @@ bool oxen_core_test_deregister_too_old::generate(std::vector<test_event_entry>&
bool oxen_core_test_deregister_zero_fee::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
size_t const NUM_SERVICE_NODES = 11;
@ -931,10 +931,10 @@ bool oxen_core_test_deregister_zero_fee::generate(std::vector<test_event_entry>
// those sitting on Chain 1 should not have problems switching over.
bool oxen_core_test_deregister_on_split::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::CHECKPOINT_QUORUM_SIZE + 1);
@ -991,10 +991,10 @@ bool oxen_core_test_deregister_on_split::generate(std::vector<test_event_entry>
bool oxen_core_test_state_change_ip_penalty_disallow_dupes::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::STATE_CHANGE_QUORUM_SIZE + 1);
@ -1053,11 +1053,11 @@ static bool verify_ons_mapping_record(char const *perr_context,
bool oxen_name_system_disallow_reserved_type::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
ons::mapping_value mapping_value = {};
@ -1091,8 +1091,8 @@ static ons_keys_t make_ons_keys(cryptonote::account_base const &src)
auto iter = result.wallet_value.buffer.begin();
uint8_t identifier = 0;
iter = std::copy_n(&identifier, 1, iter);
iter = std::copy_n(src.get_keys().m_account_address.m_spend_public_key.data, sizeof(&src.get_keys().m_account_address.m_spend_public_key.data), iter);
iter = std::copy_n(src.get_keys().m_account_address.m_view_public_key.data, sizeof(&src.get_keys().m_account_address.m_view_public_key.data), iter);
iter = std::copy_n(src.get_keys().m_account_address.m_spend_public_key.data, sizeof(src.get_keys().m_account_address.m_spend_public_key.data), iter);
iter = std::copy_n(src.get_keys().m_account_address.m_view_public_key.data, sizeof(src.get_keys().m_account_address.m_view_public_key.data), iter);
// NOTE: Just needs a 32 byte key. Reuse spend key
memcpy(&result.lokinet_value.buffer[0], (char *)&result.owner.wallet.address.m_spend_public_key, result.lokinet_value.len);
@ -1110,11 +1110,11 @@ uint64_t lokinet_expiry(ons::mapping_type type) {
bool oxen_name_system_expiration::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
ons_keys_t miner_key = make_ons_keys(miner);
@ -1182,12 +1182,12 @@ bool oxen_name_system_expiration::generate(std::vector<test_event_entry> &events
bool oxen_name_system_get_mappings_by_owner::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
cryptonote::account_base bob = gen.add_account();
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
// NOTE: Fund Bob's wallet
{
@ -1258,9 +1258,10 @@ bool oxen_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
std::vector<ons::mapping_record> records = ons_db.get_mappings_by_owner(bob_key.owner);
size_t expected_size = 0;
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::session)) expected_size += 2;
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::wallet)) expected_size += 2;
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::lokinet)) expected_size += 2;
auto netv = get_network_version(c.get_nettype(), c.get_current_blockchain_height());
if (ons::mapping_type_allowed(netv, ons::mapping_type::session)) expected_size += 2;
if (ons::mapping_type_allowed(netv, ons::mapping_type::wallet)) expected_size += 2;
if (ons::mapping_type_allowed(netv, ons::mapping_type::lokinet)) expected_size += 2;
CHECK_EQ(records.size(), expected_size);
std::sort(records.begin(), records.end(), [](const auto& a, const auto& b) {
@ -1268,7 +1269,7 @@ bool oxen_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
< std::make_tuple(b.update_height, b.name_hash);
});
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::session))
if (ons::mapping_type_allowed(netv, ons::mapping_type::session))
{
CHECK_EQ(records[0].name_hash, session_name_hash1);
CHECK_TEST_CONDITION(verify_ons_mapping_record(perr_context, records[0], ons::mapping_type::session, session_name1, bob_key.session_value, session_height, std::nullopt, session_name1_txid, bob_key.owner, {} /*backup_owner*/));
@ -1276,7 +1277,7 @@ bool oxen_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
CHECK_TEST_CONDITION(verify_ons_mapping_record(perr_context, records[1], ons::mapping_type::session, session_name2, bob_key.session_value, session_height, std::nullopt, session_name2_txid, bob_key.owner, {} /*backup_owner*/));
}
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::lokinet))
if (ons::mapping_type_allowed(netv, ons::mapping_type::lokinet))
{
CHECK_EQ(records[2].name_hash, lokinet_name_hash1);
CHECK_TEST_CONDITION(verify_ons_mapping_record(perr_context, records[2], ons::mapping_type::lokinet, lokinet_name1, bob_key.lokinet_value, lokinet_height, lokinet_height + lokinet_expiry(ons::mapping_type::lokinet), lokinet_name1_txid, bob_key.owner, {} /*backup_owner*/));
@ -1284,7 +1285,7 @@ bool oxen_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
CHECK_TEST_CONDITION(verify_ons_mapping_record(perr_context, records[3], ons::mapping_type::lokinet, lokinet_name2, bob_key.lokinet_value, lokinet_height, lokinet_height + lokinet_expiry(ons::mapping_type::lokinet_5years), lokinet_name2_txid, bob_key.owner, {} /*backup_owner*/));
}
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::wallet))
if (ons::mapping_type_allowed(netv, ons::mapping_type::wallet))
{
CHECK_EQ(records[4].name_hash, wallet_name_hash1);
CHECK_TEST_CONDITION(verify_ons_mapping_record(perr_context, records[4], ons::mapping_type::wallet, wallet_name1, bob_key.wallet_value, wallet_height, std::nullopt, wallet_name1_txid, bob_key.owner, {} /*backup_owner*/));
@ -1299,12 +1300,12 @@ bool oxen_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
bool oxen_name_system_get_mappings_by_owners::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
cryptonote::account_base bob = gen.add_account();
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
// NOTE: Fund Bob's wallet
{
@ -1369,12 +1370,12 @@ bool oxen_name_system_get_mappings_by_owners::generate(std::vector<test_event_en
bool oxen_name_system_get_mappings::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
cryptonote::account_base bob = gen.add_account();
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
// NOTE: Fund Bob's wallet
{
@ -1411,13 +1412,13 @@ bool oxen_name_system_get_mappings::generate(std::vector<test_event_entry> &even
bool oxen_name_system_handles_duplicate_in_ons_db::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
cryptonote::account_base bob = gen.add_account();
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
cryptonote::transaction transfer = gen.create_and_add_tx(miner, bob.get_keys().m_account_address, MK_COINS(400));
@ -1471,7 +1472,8 @@ bool oxen_name_system_handles_duplicate_in_ons_db::generate(std::vector<test_eve
CHECK_TEST_CONDITION(verify_ons_mapping_record(perr_context, record1, ons::mapping_type::session, session_name, bob_key.session_value, height_of_ons_entry, std::nullopt, session_tx_hash, miner_key.owner, {} /*backup_owner*/));
CHECK_EQ(record1.owner_id, owner.id);
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::lokinet))
auto netv = get_network_version(c.get_nettype(), c.get_current_blockchain_height());
if (ons::mapping_type_allowed(netv, ons::mapping_type::lokinet))
{
ons::mapping_record record2 = ons_db.get_mapping(ons::mapping_type::lokinet, session_name_hash);
CHECK_TEST_CONDITION(verify_ons_mapping_record(perr_context, record2, ons::mapping_type::lokinet, lokinet_name, miner_key.lokinet_value, height_of_ons_entry, height_of_ons_entry + lokinet_expiry(ons::mapping_type::lokinet_2years), lokinet_tx_hash, miner_key.owner, {} /*backup_owner*/));
@ -1488,13 +1490,13 @@ bool oxen_name_system_handles_duplicate_in_ons_db::generate(std::vector<test_eve
bool oxen_name_system_handles_duplicate_in_tx_pool::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
cryptonote::account_base bob = gen.add_account();
{
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
cryptonote::transaction transfer = gen.create_and_add_tx(miner, bob.get_keys().m_account_address, MK_COINS(400));
@ -1522,11 +1524,11 @@ bool oxen_name_system_handles_duplicate_in_tx_pool::generate(std::vector<test_ev
bool oxen_name_system_invalid_tx_extra_params::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
ons_keys_t miner_key = make_ons_keys(miner);
@ -1653,7 +1655,7 @@ bool oxen_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
bool oxen_name_system_large_reorg::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base const miner = gen.first_miner_;
@ -1661,7 +1663,7 @@ bool oxen_name_system_large_reorg::generate(std::vector<test_event_entry> &event
ons_keys_t const miner_key = make_ons_keys(miner);
ons_keys_t const bob_key = make_ons_keys(bob);
{
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
cryptonote::transaction transfer = gen.create_and_add_tx(miner, bob.get_keys().m_account_address, MK_COINS(400));
@ -1708,8 +1710,9 @@ bool oxen_name_system_large_reorg::generate(std::vector<test_event_entry> &event
CHECK_EQ(ons_db.height(), first_ons_height);
size_t expected_size = 1;
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::wallet)) expected_size += 1;
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::lokinet)) expected_size += 1;
auto netv = get_network_version(c.get_nettype(), c.get_current_blockchain_height());
if (ons::mapping_type_allowed(netv, ons::mapping_type::wallet)) expected_size += 1;
if (ons::mapping_type_allowed(netv, ons::mapping_type::lokinet)) expected_size += 1;
CHECK_EQ(records.size(), expected_size);
for (ons::mapping_record const &record : records)
@ -1814,8 +1817,9 @@ bool oxen_name_system_large_reorg::generate(std::vector<test_event_entry> &event
{
std::vector<ons::mapping_record> records = ons_db.get_mappings_by_owner(miner_key.owner);
size_t expected_size = 1;
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::wallet)) expected_size += 1;
if (ons::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), ons::mapping_type::lokinet)) expected_size += 1;
auto netv = get_network_version(c.get_nettype(), c.get_current_blockchain_height());
if (ons::mapping_type_allowed(netv, ons::mapping_type::wallet)) expected_size += 1;
if (ons::mapping_type_allowed(netv, ons::mapping_type::lokinet)) expected_size += 1;
CHECK_EQ(records.size(), expected_size);
for (ons::mapping_record const &record : records)
@ -1863,15 +1867,15 @@ bool oxen_name_system_large_reorg::generate(std::vector<test_event_entry> &event
bool oxen_name_system_name_renewal::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
if (!ons::mapping_type_allowed(hard_forks.back().first, ons::mapping_type::lokinet))
if (!ons::mapping_type_allowed(hard_forks.back().version, ons::mapping_type::lokinet))
return true;
{
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
}
@ -1946,11 +1950,11 @@ bool oxen_name_system_name_renewal::generate(std::vector<test_event_entry> &even
bool oxen_name_system_name_value_max_lengths::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
auto make_ons_tx_with_custom_extra = [&](oxen_chain_generator &gen,
@ -2016,11 +2020,11 @@ bool oxen_name_system_name_value_max_lengths::generate(std::vector<test_event_en
bool oxen_name_system_update_mapping_after_expiry_fails::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
ons_keys_t miner_key = make_ons_keys(miner);
@ -2070,9 +2074,9 @@ uint8_t oxen_name_system_update_mapping::hf() { return cryptonote::network_versi
uint8_t oxen_name_system_update_mapping_argon2::hf() { return cryptonote::network_version_15_ons; }
bool oxen_name_system_update_mapping::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table(hf());
auto hard_forks = oxen_generate_hard_fork_table(hf());
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
cryptonote::account_base miner = gen.first_miner_;
@ -2149,9 +2153,9 @@ ons::generic_signature ons_monero_signature(const crypto::hash& h, const crypto:
bool oxen_name_system_update_mapping_multiple_owners::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10); /// generate some outputs and unlock them
gen.add_mined_money_unlock_blocks();
@ -2413,9 +2417,9 @@ bool oxen_name_system_update_mapping_multiple_owners::generate(std::vector<test_
bool oxen_name_system_update_mapping_non_existent_name_fails::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
cryptonote::account_base miner = gen.first_miner_;
@ -2428,9 +2432,9 @@ bool oxen_name_system_update_mapping_non_existent_name_fails::generate(std::vect
bool oxen_name_system_update_mapping_invalid_signature::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
cryptonote::account_base miner = gen.first_miner_;
@ -2450,9 +2454,9 @@ bool oxen_name_system_update_mapping_invalid_signature::generate(std::vector<tes
bool oxen_name_system_update_mapping_replay::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
cryptonote::account_base miner = gen.first_miner_;
@ -2502,10 +2506,10 @@ bool oxen_name_system_update_mapping_replay::generate(std::vector<test_event_ent
bool oxen_name_system_wrong_burn::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
// NOTE: Fund Miner's wallet
{
@ -2563,11 +2567,11 @@ bool oxen_name_system_wrong_burn::generate(std::vector<test_event_entry> &events
bool oxen_name_system_wrong_version::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
std::string name = "ons_name";
@ -2601,10 +2605,10 @@ bool oxen_name_system_wrong_version::generate(std::vector<test_event_entry> &eve
// NOTE: Generate forked block, check that alternative quorums are generated and accessible
bool oxen_service_nodes_alt_quorums::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::STATE_CHANGE_QUORUM_SIZE + 3);
@ -2649,10 +2653,10 @@ bool oxen_service_nodes_alt_quorums::generate(std::vector<test_event_entry>& eve
bool oxen_service_nodes_checkpoint_quorum_size::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::CHECKPOINT_QUORUM_SIZE - 1);
@ -2689,13 +2693,13 @@ bool oxen_service_nodes_checkpoint_quorum_size::generate(std::vector<test_event_
bool oxen_service_nodes_gen_nodes::generate(std::vector<test_event_entry> &events)
{
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_9_service_nodes);
const auto hard_forks = oxen_generate_hard_fork_table(cryptonote::network_version_9_service_nodes);
oxen_chain_generator gen(events, hard_forks);
const auto miner = gen.first_miner();
const auto alice = gen.add_account();
size_t alice_account_base_event_index = gen.event_index();
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_n_blocks(10);
gen.add_mined_money_unlock_blocks();
@ -2768,9 +2772,9 @@ static bool contains(const std::vector<sn_info_t>& infos, const crypto::public_k
bool oxen_service_nodes_test_rollback::generate(std::vector<test_event_entry>& events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
add_service_nodes(gen, 11);
gen.add_n_blocks(5); /// create a few blocks with active service nodes
@ -2805,8 +2809,8 @@ bool oxen_service_nodes_test_rollback::generate(std::vector<test_event_entry>& e
CHECK_TEST_CONDITION(dereg_tx.data.tx.type == cryptonote::txtype::state_change);
cryptonote::tx_extra_service_node_state_change deregistration;
cryptonote::get_service_node_state_change_from_tx_extra(
dereg_tx.data.tx.extra, deregistration, c.get_blockchain_storage().get_current_hard_fork_version());
auto netv = get_network_version(c.get_nettype(), c.get_current_blockchain_height());
cryptonote::get_service_node_state_change_from_tx_extra(dereg_tx.data.tx.extra, deregistration, netv);
const auto uptime_quorum = c.get_quorum(service_nodes::quorum_type::obligations, deregistration.block_height);
CHECK_TEST_CONDITION(uptime_quorum);
@ -2842,11 +2846,11 @@ bool oxen_service_nodes_test_rollback::generate(std::vector<test_event_entry>& e
bool oxen_service_nodes_test_swarms_basic::generate(std::vector<test_event_entry>& events)
{
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks = {
std::make_pair(7, 0), std::make_pair(8, 1), std::make_pair(9, 2), std::make_pair(10, 150)};
const std::vector<cryptonote::hard_fork> hard_forks = {
{7,0,0,0}, {8,0,1,0}, {9,0,2,0}, {10,0,150,0}};
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.rbegin()[1].first);
gen.add_blocks_until_version(hard_forks.rbegin()[1].version);
/// Create some service nodes before hf version 10
constexpr size_t INIT_SN_COUNT = 13;
@ -2973,10 +2977,10 @@ bool oxen_service_nodes_test_swarms_basic::generate(std::vector<test_event_entry
bool oxen_service_nodes_insufficient_contribution::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
uint64_t operator_portions = STAKING_PORTIONS / 2;
@ -3005,10 +3009,10 @@ bool oxen_service_nodes_insufficient_contribution::generate(std::vector<test_eve
static oxen_chain_generator setup_pulse_tests(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator result(events, hard_forks);
result.add_blocks_until_version(hard_forks.back().first);
result.add_blocks_until_version(hard_forks.back().version);
result.add_mined_money_unlock_blocks();
std::vector<cryptonote::transaction> registration_txs(service_nodes::pulse_min_service_nodes(cryptonote::FAKECHAIN));
@ -3177,10 +3181,10 @@ bool oxen_pulse_reject_miner_block::generate(std::vector<test_event_entry> &even
bool oxen_pulse_generate_blocks::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::pulse_min_service_nodes(cryptonote::FAKECHAIN));
@ -3201,10 +3205,10 @@ bool oxen_pulse_generate_blocks::generate(std::vector<test_event_entry> &events)
bool oxen_pulse_fallback_to_pow_and_back::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, service_nodes::pulse_min_service_nodes(cryptonote::FAKECHAIN));
@ -3249,10 +3253,10 @@ bool oxen_pulse_fallback_to_pow_and_back::generate(std::vector<test_event_entry>
bool oxen_pulse_chain_split::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, std::max(service_nodes::pulse_min_service_nodes(cryptonote::FAKECHAIN), service_nodes::CHECKPOINT_QUORUM_SIZE));
@ -3294,10 +3298,10 @@ bool oxen_pulse_chain_split::generate(std::vector<test_event_entry> &events)
// Pulse chain weight to switch over.
bool oxen_pulse_chain_split_with_no_checkpoints::generate(std::vector<test_event_entry> &events)
{
std::vector<std::pair<uint8_t, uint64_t>> hard_forks = oxen_generate_hard_fork_table();
auto hard_forks = oxen_generate_hard_fork_table();
oxen_chain_generator gen(events, hard_forks);
gen.add_blocks_until_version(hard_forks.back().first);
gen.add_blocks_until_version(hard_forks.back().version);
gen.add_mined_money_unlock_blocks();
add_service_nodes(gen, std::max(service_nodes::pulse_min_service_nodes(cryptonote::FAKECHAIN), service_nodes::CHECKPOINT_QUORUM_SIZE));

View File

@ -85,7 +85,7 @@ private:
template<>
struct get_test_options<gen_rct_tx_validation_base> {
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65)};
const std::vector<cryptonote::hard_fork> hard_forks = {{1,0,0,0}, {2,0,1,0}, {4,0,65,0}};
const cryptonote::test_options test_options = {
hard_forks, 0
};
@ -271,7 +271,7 @@ struct gen_rct_tx_uses_output_too_early : public gen_rct_tx_validation_base
bool generate(std::vector<test_event_entry>& events) const;
};
template<> struct get_test_options<gen_rct_tx_uses_output_too_early> {
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(4, 65), std::make_pair(12, 69), std::make_pair(0, 0)};
const std::vector<cryptonote::hard_fork> hard_forks = {{1,0,0,0}, {2,0,1,0}, {4,0,65,0}, {12,0,69,0}, {0,0,0,0}};
const cryptonote::test_options test_options = {
hard_forks, 0
};

View File

@ -79,7 +79,7 @@ private:
template<>
struct get_test_options<gen_v2_tx_validation_base> {
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks = {std::make_pair(1, 0), std::make_pair(2, 1)};
const std::vector<cryptonote::hard_fork> hard_forks = {{1,0,0,0}, {2,0,0,0}};
const cryptonote::test_options test_options = {
hard_forks, 0
};

View File

@ -80,7 +80,6 @@ add_executable(unit_tests
test_peerlist.cpp
test_protocol_pack.cpp
threadpool.cpp
hardfork.cpp
unbound.cpp
uri.cpp
varint.cpp

View File

@ -156,7 +156,7 @@ template <typename T>
class BlockchainDBTest : public testing::Test
{
protected:
BlockchainDBTest() : m_db(new T()), m_hardfork(*m_db, 1, 0)
BlockchainDBTest() : m_db(new T())
{
for (auto& i : t_blocks)
{
@ -185,18 +185,11 @@ protected:
}
BlockchainDB* m_db;
HardFork m_hardfork;
fs::path m_prefix;
std::vector<std::pair<block, blobdata>> m_blocks;
std::vector<std::vector<std::pair<transaction, blobdata>>> m_txs;
std::vector<fs::path> m_filenames;
void init_hard_fork()
{
m_hardfork.init();
m_db->set_hard_fork(&m_hardfork);
}
void get_filenames()
{
m_filenames = m_db->get_filenames();
@ -265,7 +258,6 @@ TYPED_TEST(BlockchainDBTest, AddBlock)
// make sure open does not throw
ASSERT_NO_THROW(this->m_db->open(dirPath, cryptonote::FAKECHAIN));
this->get_filenames();
this->init_hard_fork();
db_wtxn_guard guard(this->m_db);
@ -313,7 +305,6 @@ TYPED_TEST(BlockchainDBTest, RetrieveBlockData)
// make sure open does not throw
ASSERT_NO_THROW(this->m_db->open(dirPath, cryptonote::FAKECHAIN));
this->get_filenames();
this->init_hard_fork();
db_wtxn_guard guard(this->m_db);

View File

@ -1,609 +0,0 @@
// Copyright (c) 2014-2018, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include <algorithm>
#include "gtest/gtest.h"
#include "blockchain_db/blockchain_db.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/hardfork.h"
#include "cryptonote_core/uptime_proof.h"
#include "blockchain_db/testdb.h"
#include "checkpoints/checkpoints.h"
using namespace cryptonote;
#define BLOCKS_PER_YEAR 525960
#define SECONDS_PER_YEAR 31557600
namespace
{
class TestDB: public cryptonote::BaseTestDB {
public:
virtual uint64_t height() const override { return blocks.size(); }
virtual void add_block( const block& blk
, size_t block_weight
, uint64_t long_term_block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
, uint64_t num_rct_outs
, const crypto::hash& blk_hash
) override {
blocks.push_back(blk);
}
virtual void remove_block() override { blocks.pop_back(); }
virtual block get_block_from_height(uint64_t height) const override {
return blocks.at(height);
}
virtual void set_hard_fork_version(uint64_t height, uint8_t version) override {
if (versions.size() <= height)
versions.resize(height+1);
versions[height] = version;
}
virtual uint8_t get_hard_fork_version(uint64_t height) const override {
return versions.at(height);
}
private:
std::vector<block> blocks;
std::deque<uint8_t> versions;
};
}
static cryptonote::block mkblock(uint8_t version, uint8_t vote)
{
cryptonote::block b;
b.major_version = version;
b.minor_version = vote;
return b;
}
static cryptonote::block mkblock(const HardFork &hf, uint64_t height, uint8_t vote)
{
cryptonote::block b;
b.major_version = hf.get(height);
b.minor_version = vote;
return b;
}
TEST(hardfork, major_only)
{
TestDB db;
HardFork hf(db, 1, 0, 0, 1, 0); // no voting
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 2, 1));
hf.init();
// block height 0, only version 1 is accepted
ASSERT_FALSE(hf.add(mkblock(0, 2), 0));
ASSERT_FALSE(hf.add(mkblock(2, 2), 0));
ASSERT_TRUE(hf.add(mkblock(1, 2), 0));
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, crypto::hash());
// block height 1, only version 1 is accepted
ASSERT_FALSE(hf.add(mkblock(0, 2), 1));
ASSERT_FALSE(hf.add(mkblock(2, 2), 1));
ASSERT_TRUE(hf.add(mkblock(1, 2), 1));
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, crypto::hash());
// block height 2, only version 2 is accepted
ASSERT_FALSE(hf.add(mkblock(0, 2), 2));
ASSERT_FALSE(hf.add(mkblock(1, 2), 2));
ASSERT_FALSE(hf.add(mkblock(3, 2), 2));
ASSERT_TRUE(hf.add(mkblock(2, 2), 2));
db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, crypto::hash());
}
TEST(hardfork, empty_hardforks_success)
{
TestDB db;
HardFork hf(db);
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
hf.init();
ASSERT_TRUE(hf.get_state(time(NULL)) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(time(NULL) + 3600*24*400) == HardFork::Ready);
for (uint64_t h = 0; h <= 10; ++h) {
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
ASSERT_EQ(hf.get(0), 1);
ASSERT_EQ(hf.get(1), 1);
ASSERT_EQ(hf.get(10), 1);
}
TEST(hardfork, ordering_success)
{
TestDB db;
HardFork hf(db);
ASSERT_NO_THROW(hf.add_fork(2, 2, 1));
ASSERT_ANY_THROW(hf.add_fork(3, 3, 0));
ASSERT_ANY_THROW(hf.add_fork(3, 2, 2));
ASSERT_ANY_THROW(hf.add_fork(2, 3, 2));
ASSERT_NO_THROW(hf.add_fork(3, 10, 2));
ASSERT_NO_THROW(hf.add_fork(4, 20, 3));
ASSERT_ANY_THROW(hf.add_fork(5, 5, 4));
}
TEST(hardfork, check_for_height_success)
{
TestDB db;
HardFork hf(db, 1, 0, 0, 1, 0); // no voting
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 5, 1));
hf.init();
for (uint64_t h = 0; h <= 4; ++h) {
ASSERT_TRUE(hf.check_for_height(mkblock(1, 1), h));
ASSERT_FALSE(hf.check_for_height(mkblock(2, 2), h)); // block version is too high
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 5; h <= 10; ++h) {
ASSERT_FALSE(hf.check_for_height(mkblock(1, 1), h)); // block version is too low
ASSERT_TRUE(hf.check_for_height(mkblock(2, 2), h));
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
TEST(hardfork, get_next_version)
{
TestDB db;
HardFork hf(db);
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 5, 1));
ASSERT_NO_THROW(hf.add_fork(4, 10, 2));
hf.init();
for (uint64_t h = 0; h <= 4; ++h) {
ASSERT_EQ(2, hf.get_next_version());
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 5; h <= 9; ++h) {
ASSERT_EQ(4, hf.get_next_version());
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 10; h <= 15; ++h) {
ASSERT_EQ(4, hf.get_next_version());
db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
TEST(hardfork, states_success)
{
TestDB db;
HardFork hf(db);
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, BLOCKS_PER_YEAR, SECONDS_PER_YEAR));
ASSERT_TRUE(hf.get_state(0) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR / 2) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + HardFork::DEFAULT_UPDATE_TIME / 2) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + (HardFork::DEFAULT_UPDATE_TIME + HardFork::DEFAULT_FORKED_TIME) / 2) == HardFork::UpdateNeeded);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + HardFork::DEFAULT_FORKED_TIME * 2) == HardFork::LikelyForked);
ASSERT_NO_THROW(hf.add_fork(3, BLOCKS_PER_YEAR * 5, SECONDS_PER_YEAR * 5));
ASSERT_TRUE(hf.get_state(0) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR / 2) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + HardFork::DEFAULT_UPDATE_TIME / 2) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + (HardFork::DEFAULT_UPDATE_TIME + HardFork::DEFAULT_FORKED_TIME) / 2) == HardFork::Ready);
ASSERT_TRUE(hf.get_state(SECONDS_PER_YEAR + HardFork::DEFAULT_FORKED_TIME * 2) == HardFork::Ready);
}
TEST(hardfork, steps_asap_success)
{
TestDB db;
HardFork hf(db, 1,1,1,1);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(4, 2, 1));
ASSERT_NO_THROW(hf.add_fork(7, 4, 2));
ASSERT_NO_THROW(hf.add_fork(9, 6, 3));
hf.init();
for (uint64_t h = 0; h < 10; ++h) {
db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
ASSERT_EQ(hf.get(0), 1);
ASSERT_EQ(hf.get(1), 1);
ASSERT_EQ(hf.get(2), 4);
ASSERT_EQ(hf.get(3), 4);
ASSERT_EQ(hf.get(4), 7);
ASSERT_EQ(hf.get(5), 7);
ASSERT_EQ(hf.get(6), 9);
ASSERT_EQ(hf.get(7), 9);
ASSERT_EQ(hf.get(8), 9);
ASSERT_EQ(hf.get(9), 9);
}
TEST(hardfork, steps_1_success)
{
TestDB db;
HardFork hf(db, 1,1,1,1);
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
for (int n = 1 ; n < 10; ++n)
ASSERT_NO_THROW(hf.add_fork(n+1, n, n));
hf.init();
for (uint64_t h = 0 ; h < 10; ++h) {
db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 0; h < 10; ++h) {
ASSERT_EQ(hf.get(h), std::max(1,(int)h));
}
}
TEST(hardfork, reorganize_same)
{
for (int history = 1; history <= 12; ++history) {
TestDB db;
HardFork hf(db, 1, 1, 1, history, 100);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(4, 2, 1));
ASSERT_NO_THROW(hf.add_fork(7, 4, 1)); // <- same timestamp should be allowed
ASSERT_NO_THROW(hf.add_fork(9, 6, 1)); //
hf.init();
// index 0 1 2 3 4 5 6 7 8 9
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
for (uint64_t h = 0; h < 20; ++h) {
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t rh = 0; rh < 20; ++rh) {
hf.reorganize_from_block_height(rh);
for (int hh = 0; hh < 20; ++hh) {
uint8_t version = hh >= history ? block_versions[hh - history] : 1;
ASSERT_EQ(hf.get(hh), version);
}
}
}
}
TEST(hardfork, reorganize_changed_1)
{
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 100);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(4, 2, 1));
ASSERT_NO_THROW(hf.add_fork(7, 4, 2));
ASSERT_NO_THROW(hf.add_fork(9, 6, 3));
hf.init();
// fork 4 7 9
// index 0 1 2 3 4 5 6 7 8 9
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9 };
for (uint64_t h = 0; h < 16; ++h) {
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE (hf.add(db.get_block_from_height(h), h));
}
for (uint64_t rh = 0; rh < 16; ++rh) {
hf.reorganize_from_block_height(rh);
for (int hh = 0; hh < 16; ++hh) {
ASSERT_EQ(hf.get(hh), expected_versions[hh]);
}
}
// delay a bit for 9, and go back to 1 to check it stays at 9
static const uint8_t block_versions_new[] = { 1, 1, 4, 4, 7, 7, 4, 7, 7, 7, 9, 9, 9, 9, 9, 1 };
static const uint8_t expected_versions_new[] = { 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 7, 7, 7, 9, 9 };
for (uint64_t h = 3; h < 16; ++h) {
db.remove_block();
}
ASSERT_EQ(db.height(), 3);
hf.reorganize_from_block_height(2);
for (uint64_t h = 3; h < 16; ++h) {
db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, crypto::hash());
bool ret = hf.add(db.get_block_from_height(h), h);
ASSERT_EQ (ret, h < 15);
}
db.remove_block(); // last block added to the blockchain, but not hf
ASSERT_EQ(db.height(), 15);
for (int hh = 0; hh < 15; ++hh) {
ASSERT_EQ(hf.get(hh), expected_versions_new[hh]);
}
}
TEST(hardfork, voting_threshold)
{
for (int threshold = 87; threshold <= 88; ++threshold) {
TestDB db;
HardFork hf(db, 1, 1, 1, 8, threshold);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 2, 1));
hf.init();
for (uint64_t h = 0; h <= 8; ++h) {
uint8_t v = 1 + !!(h % 8);
db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, crypto::hash());
bool ret = hf.add(db.get_block_from_height(h), h);
if (h >= 8 && threshold == 87) {
// for threshold 87, we reach the treshold at height 7, so from height 8, hard fork to version 2, but 8 tries to add 1
ASSERT_FALSE(ret);
}
else {
// for threshold 88, we never reach the threshold
ASSERT_TRUE(ret);
uint8_t expected = threshold == 88 ? 1 : h < 8 ? 1 : 2;
ASSERT_EQ(hf.get(h), expected);
}
}
}
}
TEST(hardfork, voting_different_thresholds)
{
for (int threshold = 87; threshold <= 88; ++threshold) {
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 50); // window size 4
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 5, 0, 1)); // asap
ASSERT_NO_THROW(hf.add_fork(3, 10, 100, 2)); // all votes
ASSERT_NO_THROW(hf.add_fork(4, 15, 3)); // default 50% votes
hf.init();
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
static const uint8_t block_versions[] = { 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 };
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };
for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) {
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
bool ret = hf.add(db.get_block_from_height(h), h);
ASSERT_EQ(ret, true);
}
for (uint64_t h = 0; h < sizeof(expected_versions) / sizeof(expected_versions[0]); ++h) {
ASSERT_EQ(hf.get(h), expected_versions[h]);
}
}
}
TEST(hardfork, voting_info)
{
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 50); // window size 4, default threshold 50%
// v h ts
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
// v h thr ts
ASSERT_NO_THROW(hf.add_fork(2, 5, 0, 1)); // asap
ASSERT_NO_THROW(hf.add_fork(3, 10, 100, 2)); // all votes
// v h ts
ASSERT_NO_THROW(hf.add_fork(4, 15, 3)); // default 50% votes
hf.init();
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
static const uint8_t block_versions[] = { 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 };
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };
static const uint8_t expected_thresholds[] = { 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 2, 2, 2, 2 };
for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) {
uint32_t window, votes, threshold;
uint64_t earliest_height;
uint8_t voting;
ASSERT_TRUE(hf.get_voting_info(1, window, votes, threshold, earliest_height, voting));
ASSERT_EQ(std::min<uint64_t>(h, 4), votes);
ASSERT_EQ(0, earliest_height);
ASSERT_EQ(hf.get_current_version() >= 2, hf.get_voting_info(2, window, votes, threshold, earliest_height, voting));
ASSERT_EQ(std::min<uint64_t>(h <= 3 ? 0 : h - 3, 4), votes);
ASSERT_EQ(5, earliest_height);
ASSERT_EQ(hf.get_current_version() >= 3, hf.get_voting_info(3, window, votes, threshold, earliest_height, voting));
ASSERT_EQ(std::min<uint64_t>(h <= 8 ? 0 : h - 8, 4), votes);
ASSERT_EQ(10, earliest_height);
ASSERT_EQ(hf.get_current_version() == 4, hf.get_voting_info(4, window, votes, threshold, earliest_height, voting));
ASSERT_EQ(std::min<uint64_t>(h <= 14 ? 0 : h - 14, 4), votes);
ASSERT_EQ(15, earliest_height);
ASSERT_EQ(std::min<uint64_t>(h, 4), window);
ASSERT_EQ(expected_thresholds[h], threshold);
ASSERT_EQ(4, voting);
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
TEST(hardfork, new_blocks_denied)
{
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 50);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 2, 1));
hf.init();
ASSERT_TRUE(hf.add(mkblock(1, 1), 0));
ASSERT_TRUE(hf.add(mkblock(1, 1), 1));
ASSERT_TRUE(hf.add(mkblock(1, 1), 2));
ASSERT_TRUE(hf.add(mkblock(1, 2), 3));
ASSERT_TRUE(hf.add(mkblock(1, 1), 4));
ASSERT_TRUE(hf.add(mkblock(1, 1), 5));
ASSERT_TRUE(hf.add(mkblock(1, 1), 6));
ASSERT_TRUE(hf.add(mkblock(1, 2), 7));
ASSERT_TRUE(hf.add(mkblock(1, 2), 8)); // we reach 50% of the last 4
ASSERT_FALSE(hf.add(mkblock(2, 1), 9)); // so this one can't get added
ASSERT_TRUE(hf.add(mkblock(2, 2), 9));
}
TEST(hardfork, new_version_early)
{
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 50);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 4, 1));
hf.init();
ASSERT_TRUE(hf.add(mkblock(1, 2), 0));
ASSERT_TRUE(hf.add(mkblock(1, 2), 1)); // we have enough votes already
ASSERT_TRUE(hf.add(mkblock(1, 2), 2));
ASSERT_TRUE(hf.add(mkblock(1, 1), 3)); // we accept a previous version because we did not switch, even with all the votes
ASSERT_TRUE(hf.add(mkblock(2, 2), 4)); // but have to wait for the declared height anyway
ASSERT_TRUE(hf.add(mkblock(2, 2), 5));
ASSERT_FALSE(hf.add(mkblock(2, 1), 6)); // we don't accept 1 anymore
ASSERT_TRUE(hf.add(mkblock(2, 2), 7)); // but we do accept 2
}
TEST(hardfork, reorganize_changed_2)
{
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 50);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 2, 1));
ASSERT_NO_THROW(hf.add_fork(3, 5, 2));
ASSERT_NO_THROW(hf.add_fork(4, 555, 222));
hf.init();
#define ADD(v, h, a) \
do { \
cryptonote::block b = mkblock(hf, h, v); \
db.add_block(b, 0, 0, 0, 0, 0, crypto::hash()); \
ASSERT_##a(hf.add(b, h)); \
} while(0)
#define ADD_TRUE(v, h) ADD(v, h, TRUE)
#define ADD_FALSE(v, h) ADD(v, h, FALSE)
ADD_TRUE(1, 0);
ADD_TRUE(1, 1);
ADD_TRUE(2, 2);
ADD_TRUE(2, 3); // switch to 2 here
ADD_TRUE(2, 4);
ADD_TRUE(2, 5);
ADD_TRUE(2, 6);
ASSERT_EQ(hf.get_current_version(), 2);
ADD_TRUE(3, 7);
ADD_TRUE(4, 8);
ADD_TRUE(4, 9);
ASSERT_EQ(hf.get_current_version(), 3);
// pop a few blocks and check current version goes back down
db.remove_block();
hf.reorganize_from_block_height(8);
ASSERT_EQ(hf.get_current_version(), 3);
db.remove_block();
hf.reorganize_from_block_height(7);
ASSERT_EQ(hf.get_current_version(), 2);
db.remove_block();
ASSERT_EQ(hf.get_current_version(), 2);
// add blocks again, but remaining at 2
ADD_TRUE(2, 7);
ADD_TRUE(2, 8);
ADD_TRUE(2, 9);
ASSERT_EQ(hf.get_current_version(), 2); // we did not bump to 3 this time
}
TEST(hardfork, get_higher)
{
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 50);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 2, 1));
ASSERT_NO_THROW(hf.add_fork(3, 5, 2));
hf.init();
ASSERT_EQ(hf.get_ideal_version(0), 1);
ASSERT_EQ(hf.get_ideal_version(1), 1);
ASSERT_EQ(hf.get_ideal_version(2), 2);
ASSERT_EQ(hf.get_ideal_version(3), 2);
ASSERT_EQ(hf.get_ideal_version(4), 2);
ASSERT_EQ(hf.get_ideal_version(5), 3);
ASSERT_EQ(hf.get_ideal_version(6), 3);
ASSERT_EQ(hf.get_ideal_version(7), 3);
}
TEST(hardfork, get_earliest_ideal_height)
{
TestDB db;
HardFork hf(db, 1, 1, 1, 4, 50);
// v h t
ASSERT_NO_THROW(hf.add_fork(1, 0, 0));
ASSERT_NO_THROW(hf.add_fork(2, 2, 1));
ASSERT_NO_THROW(hf.add_fork(5, 5, 2));
ASSERT_NO_THROW(hf.add_fork(6, 10, 3));
ASSERT_NO_THROW(hf.add_fork(9, 15, 4));
hf.init();
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(1), 0);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(2), 2);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(3), 5);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(4), 5);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(5), 5);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(6), 10);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(7), 15);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(8), 15);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(9), 15);
ASSERT_EQ(hf.get_earliest_ideal_height_for_version(10), std::numeric_limits<uint64_t>::max());
}

View File

@ -110,16 +110,14 @@ static uint32_t lcg()
#define PREFIX_WINDOW(hf_version,window) \
blockchain_objects_t bc_objects = {}; \
struct get_test_options { \
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks; \
const cryptonote::test_options test_options = { \
hard_forks, \
window, \
}; \
get_test_options(): hard_forks{{std::make_pair(cryptonote::network_version_7, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)1)}} {} \
} opts; \
const std::vector<cryptonote::hard_fork> hard_forks{ \
{7,0,0,0}, {hf_version,0,1,0}}; \
const cryptonote::test_options test_options = { \
hard_forks, \
window, \
}; \
cryptonote::Blockchain *bc = &bc_objects.m_blockchain; \
bool r = bc->init(new ::TestDB(), nullptr /*ons_db*/, cryptonote::FAKECHAIN, true, &opts.test_options, 0); \
bool r = bc->init(new ::TestDB(), nullptr /*ons_db*/, cryptonote::FAKECHAIN, true, &test_options, 0); \
ASSERT_TRUE(r)
#define PREFIX(hf_version) PREFIX_WINDOW(hf_version, TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW)

View File

@ -83,11 +83,10 @@ bool get_output_distribution(uint64_t amount, uint64_t from, uint64_t to, uint64
{
blockchain_objects_t bc = {};
struct get_test_options {
const std::vector<std::pair<uint8_t, uint64_t>> hard_forks;
const std::vector<cryptonote::hard_fork> hard_forks{{1,0,0,0}};
const cryptonote::test_options test_options = {
hard_forks
};
get_test_options():hard_forks{{std::make_pair((uint8_t)1, (uint64_t)0)}}{}
} opts;
cryptonote::Blockchain *blockchain = &bc.m_blockchain;
bool r = blockchain->init(new TestDB(test_distribution_size), nullptr /*ons_db*/, cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL);

View File

@ -45,7 +45,7 @@ TEST(service_nodes, staking_requirement)
// Try underflow
{
uint64_t height = 100;
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_8);
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
ASSERT_EQ(mainnet_requirement, (45000 * COIN));
}
@ -54,7 +54,7 @@ TEST(service_nodes, staking_requirement)
// NOTE: The maximum staking requirement is 50,000, in atomic units is 50,000,000,000,000 < int64 range (2^63-1)
// so casting is safe.
uint64_t height = 101250;
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_9_service_nodes);
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
ASSERT_EQ(mainnet_requirement, (45000 * COIN));
}
@ -62,7 +62,7 @@ TEST(service_nodes, staking_requirement)
// Check the requirements are decreasing
{
uint64_t height = 209250;
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_10_bulletproofs);
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
int64_t mainnet_expected = 29643'670390000;
int64_t mainnet_delta = std::abs(mainnet_requirement - mainnet_expected);
@ -73,7 +73,7 @@ TEST(service_nodes, staking_requirement)
// Sliftly after the boundary when the scheme switches over to a smooth emissions curve to 15k
{
uint64_t height = 235987;
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_11_infinite_staking);
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
int64_t mainnet_expected = 27164'648610000;
int64_t mainnet_delta = std::abs(mainnet_requirement - mainnet_expected);
@ -83,7 +83,7 @@ TEST(service_nodes, staking_requirement)
// Check staking requirement on height whose value is different with different floating point rounding modes, we expect FE_TONEAREST.
{
uint64_t height = 373200;
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_11_infinite_staking);
int64_t mainnet_requirement = (int64_t)service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
int64_t mainnet_expected = 20839'644149350;
ASSERT_EQ(mainnet_requirement, mainnet_expected);
@ -92,7 +92,7 @@ TEST(service_nodes, staking_requirement)
// NOTE: Staking Requirement Algorithm Switch: Integer Math Variant ^____^
{
uint64_t height = 450000;
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_13_enforce_checkpoints);
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
uint64_t mainnet_expected = 18898'351896001;
ASSERT_EQ(mainnet_requirement, mainnet_expected);
@ -101,7 +101,7 @@ TEST(service_nodes, staking_requirement)
// Just before drop to 15k
{
uint64_t height = 641110;
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_15_ons);
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
uint64_t mainnet_expected = 16396'730529714;
ASSERT_EQ(mainnet_requirement, mainnet_expected);
@ -110,7 +110,7 @@ TEST(service_nodes, staking_requirement)
// 15k requirement begins
{
uint64_t height = 641111;
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_16_pulse);
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
uint64_t mainnet_expected = 15000 * COIN;
ASSERT_EQ(mainnet_requirement, mainnet_expected);
@ -119,7 +119,7 @@ TEST(service_nodes, staking_requirement)
// into the Future
{
uint64_t height = 800'000;
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height, cryptonote::network_version_16_pulse);
uint64_t mainnet_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
uint64_t mainnet_expected = 15000 * COIN;
ASSERT_EQ(mainnet_requirement, mainnet_expected);
@ -453,7 +453,7 @@ TEST(service_nodes, min_stake_amount)
/// pre v11
uint64_t height = 101250;
uint8_t hf_version = cryptonote::network_version_9_service_nodes;
uint64_t stake_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height, hf_version);
uint64_t stake_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
{
const uint64_t reserved = stake_requirement / 2;
const uint64_t min_stake = service_nodes::get_min_node_contribution(hf_version, stake_requirement, reserved, 1);
@ -468,7 +468,7 @@ TEST(service_nodes, min_stake_amount)
/// post v11
hf_version = cryptonote::network_version_11_infinite_staking;
stake_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height, hf_version);
stake_requirement = service_nodes::get_staking_requirement(cryptonote::MAINNET, height);
{
// 50% reserved, with 1 contribution, max of 4- the minimum stake should be (50% / 3)
const uint64_t reserved = stake_requirement / 2;

View File

@ -140,8 +140,6 @@ public:
virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> f) const override { return true; }
virtual bool for_all_outputs(uint64_t amount, const std::function<bool(uint64_t height)> &f) const override { return true; }
virtual void set_hard_fork_version(uint64_t height, uint8_t version) override {}
virtual uint8_t get_hard_fork_version(uint64_t height) const override { return 0; }
virtual void check_hard_fork_info() override {}
virtual void drop_hard_fork_info() override {}