forked from lthn/blockchain
coretests: 1) tests_random_split_strategy added; 2) test_gentime_settings adapted and improved
This commit is contained in:
parent
ab58d091f2
commit
4ea5e67d44
4 changed files with 51 additions and 16 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2022 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
|
|
@ -25,8 +25,6 @@
|
|||
#include "wallet_test_core_proxy.h"
|
||||
#include "pos_block_builder.h"
|
||||
|
||||
//using namespace std;
|
||||
|
||||
using namespace epee;
|
||||
using namespace currency;
|
||||
|
||||
|
|
@ -34,7 +32,7 @@ using namespace currency;
|
|||
#define POS_DIFF_UP_TIMESTAMP_DELTA (DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN*2/3)
|
||||
|
||||
std::atomic<int64_t> test_core_time::m_time_shift;
|
||||
test_gentime_settings test_generator::m_test_gentime_settings_default = test_gentime_settings(tests_digits_split_strategy, CURRENCY_MINER_TX_MAX_OUTS, WALLET_MAX_ALLOWED_OUTPUT_AMOUNT, DEFAULT_DUST_THRESHOLD);
|
||||
const test_gentime_settings test_generator::m_test_gentime_settings_default{};
|
||||
test_gentime_settings test_generator::m_test_gentime_settings = test_generator::m_test_gentime_settings_default;
|
||||
|
||||
crypto::signature create_invalid_signature()
|
||||
|
|
@ -1347,6 +1345,18 @@ bool fill_tx_sources_and_destinations(const std::vector<test_event_entry>& event
|
|||
case tests_digits_split_strategy:
|
||||
tools::detail::digit_split_strategy(dsts, change_dst, tgs.dust_threshold, destinations, dust, tgs.tx_max_out_amount);
|
||||
break;
|
||||
case tests_random_split_strategy:
|
||||
{
|
||||
size_t outs_count = cache_back > 0 ? 2 : 1;
|
||||
if (outs_count < tgs.rss_min_number_of_outputs)
|
||||
{
|
||||
// decompose both target and cache back amounts
|
||||
// TODO: support tgs.tx_max_out_amount
|
||||
decompose_amount_randomly(amount, [&](uint64_t a){ destinations.emplace_back(a, to.back()); }, tgs.rss_min_number_of_outputs, tgs.rss_num_digits_to_keep);
|
||||
decompose_amount_randomly(cache_back, [&](uint64_t a){ destinations.emplace_back(a, from.account_address); }, tgs.rss_min_number_of_outputs, tgs.rss_num_digits_to_keep);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CHECK_AND_ASSERT_MES(false, false, "Invalid split strategy set in gentime settings");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,15 +212,15 @@ VARIANT_TAG(binary_archive, event_core_time, 0xd1);
|
|||
typedef boost::variant<currency::block, currency::transaction, currency::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings, event_special_block, event_core_time> test_event_entry;
|
||||
typedef std::unordered_map<crypto::hash, const currency::transaction*> map_hash2tx_t;
|
||||
|
||||
enum test_tx_split_strategy { tests_void_split_strategy, tests_null_split_strategy, tests_digits_split_strategy };
|
||||
enum test_tx_split_strategy { tests_void_split_strategy, tests_null_split_strategy, tests_digits_split_strategy, tests_random_split_strategy };
|
||||
struct test_gentime_settings
|
||||
{
|
||||
test_gentime_settings(test_tx_split_strategy split_strategy, size_t miner_tx_max_outs, uint64_t tx_max_out_amount, uint64_t dust_threshold)
|
||||
: split_strategy(split_strategy), miner_tx_max_outs(miner_tx_max_outs), tx_max_out_amount(tx_max_out_amount), dust_threshold(dust_threshold) {}
|
||||
test_tx_split_strategy split_strategy;
|
||||
size_t miner_tx_max_outs;
|
||||
uint64_t tx_max_out_amount;
|
||||
uint64_t dust_threshold;
|
||||
test_tx_split_strategy split_strategy = tests_digits_split_strategy;
|
||||
size_t miner_tx_max_outs = CURRENCY_MINER_TX_MAX_OUTS;
|
||||
uint64_t tx_max_out_amount = WALLET_MAX_ALLOWED_OUTPUT_AMOUNT;
|
||||
uint64_t dust_threshold = DEFAULT_DUST_THRESHOLD;
|
||||
size_t rss_min_number_of_outputs = CURRENCY_TX_MIN_ALLOWED_OUTS; // for random split strategy: min (target) number of tx outputs, one output will be split into this many parts
|
||||
size_t rss_num_digits_to_keep = CURRENCY_TX_OUTS_RND_SPLIT_DIGITS_TO_KEEP; // for random split strategy: number of digits to keep
|
||||
};
|
||||
|
||||
class test_generator;
|
||||
|
|
@ -541,7 +541,7 @@ private:
|
|||
|
||||
std::unordered_map<crypto::hash, block_info> m_blocks_info;
|
||||
static test_gentime_settings m_test_gentime_settings;
|
||||
static test_gentime_settings m_test_gentime_settings_default;
|
||||
static const test_gentime_settings m_test_gentime_settings_default;
|
||||
}; // class class test_generator
|
||||
|
||||
extern const crypto::signature invalid_signature; // invalid non-null signature for test purpose
|
||||
|
|
|
|||
|
|
@ -234,6 +234,7 @@ zarcanum_pos_block_math::zarcanum_pos_block_math()
|
|||
m_hardforks.set_hardfork_height(ZANO_HARDFORK_04_ZARCANUM, 1);
|
||||
|
||||
REGISTER_CALLBACK_METHOD(zarcanum_pos_block_math, c1);
|
||||
REGISTER_CALLBACK_METHOD(zarcanum_pos_block_math, c2);
|
||||
}
|
||||
|
||||
bool zarcanum_pos_block_math::generate(std::vector<test_event_entry>& events) const
|
||||
|
|
@ -248,7 +249,7 @@ bool zarcanum_pos_block_math::generate(std::vector<test_event_entry>& events) co
|
|||
account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts);
|
||||
account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts);
|
||||
|
||||
m_alice_amount = MK_TEST_COINS(1);
|
||||
m_alice_amount = MK_TEST_COINS(99);
|
||||
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time());
|
||||
DO_CALLBACK(events, "configure_core"); // necessary to set m_hardforks
|
||||
|
|
@ -263,8 +264,7 @@ bool zarcanum_pos_block_math::generate(std::vector<test_event_entry>& events) co
|
|||
crypto::secret_key tx_sec_key;
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_0, get_tx_version_from_events(events), tx_sec_key, 0);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
//DO_CALLBACK(events, "mark_invalid_tx");
|
||||
events.push_back(tx_0);
|
||||
ADD_CUSTOM_EVENT(events, tx_0);
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0);
|
||||
|
||||
|
|
@ -275,6 +275,18 @@ bool zarcanum_pos_block_math::generate(std::vector<test_event_entry>& events) co
|
|||
CREATE_TEST_WALLET(alice_wlt, alice_acc, blk_0);
|
||||
REFRESH_TEST_WALLET_AT_GEN_TIME(events, alice_wlt, blk_1r, 2 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 4);
|
||||
CHECK_TEST_WALLET_BALANCE_AT_GEN_TIME(alice_wlt, m_alice_amount);
|
||||
|
||||
// Alice -> Bob
|
||||
m_bob_amount = MK_TEST_COINS(15);
|
||||
|
||||
MAKE_TX(events, tx_1, alice_acc, bob_acc, m_bob_amount, blk_1r);
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1r, miner_acc, tx_1);
|
||||
|
||||
DO_CALLBACK(events, "c2");
|
||||
|
||||
CREATE_TEST_WALLET(bob_wlt, bob_acc, blk_0);
|
||||
REFRESH_TEST_WALLET_AT_GEN_TIME(events, bob_wlt, blk_2, 2 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5);
|
||||
CHECK_TEST_WALLET_BALANCE_AT_GEN_TIME(bob_wlt, m_bob_amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -284,7 +296,18 @@ bool zarcanum_pos_block_math::c1(currency::core& c, size_t ev_index, const std::
|
|||
std::shared_ptr<tools::wallet2> alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX);
|
||||
alice_wlt->refresh();
|
||||
|
||||
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", m_alice_amount, 0, MK_TEST_COINS(1), 0, 0), false, "");
|
||||
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", m_alice_amount, 0, m_alice_amount, 0, 0), false, "");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool zarcanum_pos_block_math::c2(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> bob_wlt = init_playtime_test_wallet(events, c, BOB_ACC_IDX);
|
||||
bob_wlt->refresh();
|
||||
|
||||
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt, "Bob", m_bob_amount, 0, 0, 0, 0), false, "");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ struct zarcanum_pos_block_math : public wallet_test
|
|||
zarcanum_pos_block_math();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
bool c2(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
|
||||
mutable uint64_t m_alice_amount = 0;
|
||||
mutable uint64_t m_bob_amount = 0;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue