1
0
Fork 0
forked from lthn/blockchain

merge from develop

This commit is contained in:
cryptozoidberg 2024-10-15 17:57:50 +04:00
commit 2c72622d7e
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
29 changed files with 1617 additions and 835 deletions

View file

@ -812,26 +812,7 @@ namespace crypto
friend bool operator==(const point_t& lhs, const point_t& rhs)
{
// TODO: @#@# (performance) consider checking (lhs - rhs).is_zero() instead
// convert to xy form, then compare components (because (x, y, z, t) representation is not unique)
fe lrecip, lx, ly;
fe rrecip, rx, ry;
fe_invert(lrecip, lhs.m_p3.Z);
fe_invert(rrecip, rhs.m_p3.Z);
fe_mul(lx, lhs.m_p3.X, lrecip);
fe_mul(rx, rhs.m_p3.X, rrecip);
if (memcmp(&lx, &rx, sizeof lx) != 0)
return false;
fe_mul(ly, lhs.m_p3.Y, lrecip);
fe_mul(ry, rhs.m_p3.Y, rrecip);
if (memcmp(&ly, &ry, sizeof ly) != 0)
return false;
return true;
return (lhs - rhs).is_zero();
}
friend bool operator!=(const point_t& lhs, const point_t& rhs)

View file

@ -253,7 +253,7 @@
#define BC_OFFERS_CURRENCY_MARKET_FILENAME "market.bin"
#define WALLET_FILE_SERIALIZATION_VERSION 167
#define WALLET_FILE_SERIALIZATION_VERSION 168
#define WALLET_FILE_LAST_SUPPORTED_VERSION 165
#define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31)

View file

@ -1202,7 +1202,7 @@ bool simple_wallet::show_staking_history(const std::vector<std::string>& args)
bool transfers_found = false;
for (auto it = transfers.rbegin(); it != transfers.rend(); it++)
{
const auto& td = *it;
const auto& td = it->second;
if (timestamp && td.m_ptx_wallet_info->m_block_timestamp < timestamp)
break;
@ -1264,8 +1264,9 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args
m_wallet->get_transfers(transfers);
bool transfers_found = false;
for (const auto& td : transfers)
for (const auto& tr : transfers)
{
const auto& td = tr.second;
if (!filter || available != static_cast<bool>(td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_SPENT))
{
if (!transfers_found)
@ -1308,8 +1309,9 @@ bool simple_wallet::show_incoming_transfers_counts(const std::vector<std::string
uint64_t spent_count = 0;
uint64_t unspent_count = 0;
for (const auto& td : transfers)
for (const auto& tr : transfers)
{
const auto& td = tr.second;
if (td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_SPENT)
{
++spent_count;

View file

@ -5,9 +5,9 @@
#define PROJECT_MAJOR_VERSION "2"
#define PROJECT_MINOR_VERSION "0"
#define PROJECT_REVISION "1"
#define PROJECT_REVISION "2"
#define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION
#define PROJECT_VERSION_BUILD_NO 349
#define PROJECT_VERSION_BUILD_NO 351
#define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO)
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"

File diff suppressed because it is too large Load diff

View file

@ -50,6 +50,8 @@
#define WALLET_DEFAULT_TX_SPENDABLE_AGE CURRENCY_HF4_MANDATORY_MIN_COINAGE
#define WALLET_POS_MINT_CHECK_HEIGHT_INTERVAL 1
#define WALLET_CONCISE_MODE_MAX_REORG_BLOCKS CURRENCY_BLOCKS_PER_DAY * 7 //week
#define WALLET_CONCISE_MODE_MOBILE_MAX_HISTORY_SIZE 500
const uint64_t WALLET_MINIMUM_HEIGHT_UNSET_CONST = std::numeric_limits<uint64_t>::max();
@ -134,9 +136,9 @@ namespace tools
std::unordered_map<crypto::key_image, size_t> m_key_images;
std::vector<wallet_public::wallet_transfer_info> m_transfer_history;
std::unordered_map<crypto::hash, currency::transaction> m_unconfirmed_in_transfers;
std::unordered_map<crypto::hash, tools::wallet_public::wallet_transfer_info> m_unconfirmed_txs;
unconfirmed_txs_container m_unconfirmed_txs;
std::unordered_set<crypto::hash> m_unconfirmed_multisig_transfers;
std::unordered_map<crypto::hash, crypto::secret_key> m_tx_keys;
tx_secrete_keys_container m_tx_keys;
std::unordered_map<crypto::public_key, wallet_own_asset_context> m_own_asset_descriptors;
std::unordered_map<crypto::public_key, currency::asset_descriptor_base> m_custom_assets; //assets that manually added by user
mutable std::unordered_map<crypto::public_key, currency::asset_descriptor_base> m_whitelisted_assets; //assets that whitelisted
@ -149,13 +151,14 @@ namespace tools
uint64_t m_last_pow_block_h = 0;
std::list<std::pair<uint64_t, wallet_event_t>> m_rollback_events;
std::list<std::pair<uint64_t, uint64_t> > m_last_zc_global_indexs; // <height, last_zc_global_indexs>, biggest height comes in front
//variables that not being serialized
std::atomic<uint64_t> m_last_bc_timestamp = 0;
uint64_t m_height_of_start_sync = 0;
std::atomic<uint64_t> m_last_sync_percent = 0;
mutable uint64_t m_current_wallet_file_size = 0;
bool m_use_assets_whitelisting = true;
bool m_use_assets_whitelisting = true;
mutable std::optional<bool> m_has_bare_unspent_outputs; // recalculated each time the balance() is called
// variables that should be part of state data object but should not be stored during serialization
@ -201,7 +204,17 @@ namespace tools
a & m_chain;
a & m_minimum_height;
a & m_amount_gindex_to_transfer_id;
a & m_transfers;
if (ver <= 167)
{
std::deque<transfer_details> transfer_container_old;
a& transfer_container_old;
for (size_t i = 0; i != transfer_container_old.size(); i++){m_transfers[i] = transfer_container_old[i];}
}
else
{
a& m_transfers;
}
a & m_multisig_transfers;
a & m_key_images;
a & m_unconfirmed_txs;
@ -234,7 +247,12 @@ namespace tools
{
//workaround for m_last_zc_global_indexs holding invalid index for last item
m_last_zc_global_indexs.pop_front();
}
}
if (ver <= 167)
{
return;
}
}
};
@ -565,10 +583,12 @@ namespace tools
currency::transaction &escrow_template_tx);
bool check_connection();
bool truncate_transfers_and_history(const std::list<size_t>& items_to_remove);
bool truncate_wallet();
// PoS mining
void do_pos_mining_prepare_entry(mining_context& cxt, size_t transfer_index);
bool do_pos_mining_iteration(mining_context& cxt, size_t transfer_index, uint64_t ts);
void do_pos_mining_prepare_entry(mining_context& cxt, const transfer_details& td);
bool do_pos_mining_iteration(mining_context& cxt, uint64_t ts);
template<typename idle_condition_cb_t> //do refresh as external callback
bool scan_pos(mining_context& cxt, std::atomic<bool>& stop, idle_condition_cb_t idle_condition_cb, const currency::core_runtime_config &runtime_config);
bool fill_mining_context(mining_context& ctx);
@ -740,6 +760,9 @@ namespace tools
bool is_in_hardfork_zone(uint64_t hardfork_index) const;
//performance inefficient call, suitable only for rare ocasions or super lazy developers
bool proxy_to_daemon(const std::string& uri, const std::string& body, int& response_code, std::string& response_body);
void set_concise_mode(bool enabled) { m_concise_mode = enabled; }
void set_concise_mode_reorg_max_reorg_blocks(uint64_t max_blocks) { m_wallet_concise_mode_max_reorg_blocks = max_blocks; }
void set_concise_mode_truncate_history(uint64_t max_entries) { m_truncate_history_max_entries = max_entries; }
construct_tx_param get_default_construct_tx_param();
@ -774,7 +797,7 @@ private:
bool on_idle();
void unserialize_block_complete_entry(const currency::COMMAND_RPC_GET_BLOCKS_FAST::response& serialized,
currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& unserialized);
void pull_blocks(size_t& blocks_added, std::atomic<bool>& stop);
void pull_blocks(size_t& blocks_added, std::atomic<bool>& stop, bool& full_reset_needed);
bool prepare_free_transfers_cache(uint64_t fake_outputs_count);
bool select_transfers(assets_selection_context& needed_money_map, size_t fake_outputs_count, uint64_t dust, std::vector<uint64_t>& selected_indicies);
void add_transfers_to_transfers_cache(const std::vector<uint64_t>& indexs);
@ -795,7 +818,7 @@ private:
void add_to_last_zc_global_indexs(uint64_t h, uint64_t last_zc_output_index);
uint64_t get_actual_zc_global_index();
void handle_pulled_blocks(size_t& blocks_added, std::atomic<bool>& stop,
currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& blocks);
currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& blocks, bool& full_reset_needed);
std::string get_alias_for_address(const std::string& addr);
std::vector<std::string> get_aliases_for_address(const std::string& addr);
bool is_connected_to_net();
@ -958,9 +981,17 @@ private:
std::string m_votes_config_path;
tools::wallet_public::wallet_vote_config m_votes_config;
std::atomic<bool> m_concise_mode = true; //in this mode the wallet don't keep spent entries in m_transfers as well as m_recent_transfers longer then 100 entries
uint64_t m_last_known_daemon_height = 0;
//this needed to access wallets state in coretests, for creating abnormal blocks and transactions
uint64_t m_wallet_concise_mode_max_reorg_blocks = WALLET_CONCISE_MODE_MAX_REORG_BLOCKS;
uint64_t m_full_resync_requested_at_h = 0;
uint64_t m_truncate_history_max_entries
#ifdef MOBILE_WALLET_BUILD
= WALLET_CONCISE_MODE_MOBILE_MAX_HISTORY_SIZE;
#else
= 0;
#endif
//this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions
friend class test_generator;
}; // class wallet2
@ -1071,7 +1102,13 @@ namespace tools
if (tr_index != UINT64_MAX)
{
transfer_details& td = m_transfers[tr_index];
auto it_tr = m_transfers.find(tr_index);
if (it_tr == m_transfers.end())
{
throw tools::error::wallet_error_resync_needed();
}
transfer_details& td = it_tr->second;
ptc.total_balance_change[td.get_asset_id()] -= td.amount();
if (td.is_native_coin())
{
@ -1121,9 +1158,9 @@ namespace tools
ts_middle -= ts_middle % POS_SCAN_STEP;
uint64_t ts_window = std::min(ts_middle - ts_from, ts_to - ts_middle);
for (size_t transfer_index = 0; transfer_index != m_transfers.size(); transfer_index++)
for (auto it = m_transfers.begin(); it != m_transfers.end(); it++)//size_t transfer_index = 0; transfer_index != m_transfers.size(); transfer_index++)
{
auto& tr = m_transfers[transfer_index];
auto& tr = it->second;
uint64_t stake_unlock_time = 0;
if (!is_transfer_okay_for_pos(tr, cxt.zarcanum, stake_unlock_time))
@ -1149,7 +1186,7 @@ namespace tools
}
};
do_pos_mining_prepare_entry(cxt, transfer_index);
do_pos_mining_prepare_entry(cxt, tr);
cxt.total_items_checked++;
cxt.total_amount_checked += tr.amount();
while(step <= ts_window)
@ -1178,9 +1215,9 @@ namespace tools
return false;
cxt.iterations_processed++;
if (do_pos_mining_iteration(cxt, transfer_index, ts))
if (do_pos_mining_iteration(cxt, ts))
{
cxt.index = transfer_index;
cxt.index = it->first;
cxt.stake_unlock_time = stake_unlock_time;
cxt.status = API_RETURN_CODE_OK;
return true;

View file

@ -51,7 +51,8 @@
#define WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER uint32_t(1 << 3)
#define WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION uint32_t(1 << 4) // transfer is reserved for cold-signing (unsigned tx was created and passed for signing)
#define WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM uint32_t(1 << 5) // for htlc keeps info if this htlc belong as redeem or as refund
#define WALLET_TRANSFER_DETAIL_FLAG_ASSET_OP_RESERVATION uint32_t(1 << 6) // transfer is reserved for an ongoing asset operation with external signing
#define WALLET_TRANSFER_DETAIL_CONCISE_MODE_PRESERVE uint32_t(1 << 6) // do not truncate this output with CONCISE mode
#define WALLET_TRANSFER_DETAIL_FLAG_ASSET_OP_RESERVATION uint32_t(1 << 7) // transfer is reserved for an ongoing asset operation with external signing
@ -511,12 +512,14 @@ namespace tools
typedef std::unordered_multimap<std::string, payment_details> payment_container;
typedef std::deque<transfer_details> transfer_container;
typedef std::map<uint64_t, transfer_details> transfer_container; //typedef std::deque<transfer_details> transfer_container;
typedef std::unordered_map<crypto::hash, transfer_details_base> multisig_transfer_container;
typedef std::unordered_map<crypto::hash, tools::wallet_public::escrow_contract_details_basic> escrow_contracts_container;
typedef std::map<uint64_t, std::set<size_t> > free_amounts_cache_type;
typedef std::unordered_map<crypto::public_key, free_amounts_cache_type> free_assets_amounts_cache_type;
typedef std::unordered_map<std::pair<uint64_t, uint64_t>, uint64_t> amount_gindex_to_transfer_id_container; // maps [amount; gindex] -> tid
typedef std::unordered_map<crypto::hash, crypto::secret_key> tx_secrete_keys_container;
typedef std::unordered_map<crypto::hash, tools::wallet_public::wallet_transfer_info> unconfirmed_txs_container;
}// namespace tools

View file

@ -321,6 +321,11 @@ namespace tools
const currency::transaction m_tx;
};
//----------------------------------------------------------------------------------------------------
struct wallet_error_resync_needed : public std::exception
{
virtual const char* what() const noexcept override { return "wallet_error_resync_needed"; }
};
//----------------------------------------------------------------------------------------------------
struct tx_parse_error : public refresh_error
{
explicit tx_parse_error(std::string&& loc, const currency::blobdata& tx_blob)

View file

@ -52,7 +52,7 @@ bool atomic_base_test::generate(std::vector<test_event_entry>& events) const
test_core_time::adjust(m_genesis_timestamp);
epee::debug::get_set_enable_assert(true, true);
//epee::debug::get_set_enable_assert(true, true);
currency::account_base genesis_acc;
genesis_acc.generate();
@ -68,7 +68,7 @@ bool atomic_base_test::generate(std::vector<test_event_entry>& events) const
REWIND_BLOCKS_N(events, blk_0r, blk_0, m_mining_accunt, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5);
DO_CALLBACK(events, "c1");
epee::debug::get_set_enable_assert(true, false);
//epee::debug::get_set_enable_assert(true, false);
return true;
}
@ -78,8 +78,8 @@ bool atomic_base_test::generate(std::vector<test_event_entry>& events) const
bool atomic_simple_test::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
epee::debug::get_set_enable_assert(true, true);
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); });
//epee::debug::get_set_enable_assert(true, true);
//misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); });
/*

View file

@ -997,6 +997,8 @@ bool test_generator::init_test_wallet(const currency::account_base& account, con
w->set_genesis(genesis_hash);
w->set_core_proxy(m_wallet_test_core_proxy);
w->set_disable_tor_relay(true);
w->set_concise_mode(true);
w->set_concise_mode_reorg_max_reorg_blocks(TESTS_CONCISE_MODE_REORG_MAX_REORG_BLOCK);
result = w;
return true;
@ -2225,12 +2227,13 @@ bool make_tx_multisig_to_key(const currency::transaction& source_tx,
bool estimate_wallet_balance_blocked_for_escrow(const tools::wallet2& w, uint64_t& result, bool substruct_change_from_result /* = true */)
{
std::deque<tools::transfer_details> transfers;
tools::transfer_container transfers;
w.get_transfers(transfers);
result = 0;
for (const tools::transfer_details& td : transfers)
for (const auto& tr : transfers)
{
const tools::transfer_details& td = tr.second;
if (td.m_flags == (WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION))
result += td.amount();
}

View file

@ -19,8 +19,10 @@
#define TESTS_DEFAULT_FEE ((uint64_t)TX_DEFAULT_FEE)
#define MK_TEST_COINS(amount) (static_cast<uint64_t>(amount) * TX_DEFAULT_FEE)
#define TESTS_POS_CONFIG_MIN_COINSTAKE_AGE 4
#define TESTS_POS_CONFIG_POS_MINIMUM_HEIGH 4
#define TESTS_POS_CONFIG_MIN_COINSTAKE_AGE 4
#define TESTS_POS_CONFIG_POS_MINIMUM_HEIGH 4
#define TESTS_CONCISE_MODE_REORG_MAX_REORG_BLOCK 5
namespace concolor
{

View file

@ -1218,7 +1218,9 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(tx_expiration_time_and_chain_switching);
GENERATE_AND_PLAY(tx_key_image_pool_conflict);
//GENERATE_AND_PLAY_HF(tx_version_against_hardfork, "4-*");
GENERATE_AND_PLAY_HF(tx_pool_semantic_validation, "4-*");
/* To execute the check of bare balance (function "check_tx_bare_balance") we need to run the test "tx_pool_semantic_validation" on the HF 3. By default behaviour bare outputs are disallowed on
the heights >= 10. */
GENERATE_AND_PLAY_HF(tx_pool_semantic_validation, "3");
// Double spend
GENERATE_AND_PLAY(gen_double_spend_in_tx<false>);
@ -1299,6 +1301,7 @@ int main(int argc, char* argv[])
//GENERATE_AND_PLAY_HF(asset_current_and_total_supplies_comparative_constraints, "4-*"); <-- temporary disabled, waiting for Stepan's fix -- sowle
GENERATE_AND_PLAY_HF(pos_fuse_test, "4-*");
GENERATE_AND_PLAY_HF(wallet_reorganize_and_trim_test, "4-*");

View file

@ -14,7 +14,7 @@ using namespace currency;
cumulative_difficulty_adjustment_test::cumulative_difficulty_adjustment_test()
{
epee::debug::get_set_enable_assert(true, true);
//epee::debug::get_set_enable_assert(true, true);
REGISTER_CALLBACK_METHOD(cumulative_difficulty_adjustment_test, configure_core);
REGISTER_CALLBACK_METHOD(cumulative_difficulty_adjustment_test, configure_check_height1);
REGISTER_CALLBACK_METHOD(cumulative_difficulty_adjustment_test, memorize_main_chain);
@ -25,7 +25,7 @@ cumulative_difficulty_adjustment_test::cumulative_difficulty_adjustment_test()
}
cumulative_difficulty_adjustment_test::~cumulative_difficulty_adjustment_test()
{
epee::debug::get_set_enable_assert(true, false);
//epee::debug::get_set_enable_assert(true, false);
}
#define FIRST_ALIAS_NAME "first"
#define SECOND_ALIAS_NAME "second"

View file

@ -317,7 +317,8 @@ bool escrow_altchain_meta_impl::c1(currency::core& c, size_t ev_index, const std
alice_wlt->scan_tx_pool(stub);
size_t blocks_fetched = 0;
alice_wlt->refresh(blocks_fetched);
CHECK_AND_ASSERT_MES(blocks_fetched == se.expected_blocks, false, "Alice got " << blocks_fetched << " after refresh, but " << se.expected_blocks << " is expected");
//fetched blocks disabled since resync might happened on different situation and number of blocks_fetched might be unexpected
//CHECK_AND_ASSERT_MES(blocks_fetched == se.expected_blocks, false, "Alice got " << blocks_fetched << " after refresh, but " << se.expected_blocks << " is expected");
LOG_PRINT_GREEN("Alice's transfers:" << ENDL << alice_wlt->dump_trunsfers(), LOG_LEVEL_1);
if (se.a_balance != UINT64_MAX)
{
@ -335,7 +336,8 @@ bool escrow_altchain_meta_impl::c1(currency::core& c, size_t ev_index, const std
bob_wlt->scan_tx_pool(stub);
blocks_fetched = 0;
bob_wlt->refresh(blocks_fetched);
CHECK_AND_ASSERT_MES(blocks_fetched == se.expected_blocks, false, "Bob got " << blocks_fetched << " after refresh, but " << se.expected_blocks << " is expected");
//fetched blocks disabled since resync might happened on different situation and number of blocks_fetched might be unexpected
//CHECK_AND_ASSERT_MES(blocks_fetched == se.expected_blocks, false, "Bob got " << blocks_fetched << " after refresh, but " << se.expected_blocks << " is expected");
LOG_PRINT_GREEN("Bob's transfers:" << ENDL << bob_wlt->dump_trunsfers(), LOG_LEVEL_1);
if (se.b_balance != UINT64_MAX)
{

View file

@ -32,7 +32,7 @@ escrow_wallet_test::escrow_wallet_test()
bool escrow_wallet_test::generate(std::vector<test_event_entry>& events) const
{
epee::debug::get_set_enable_assert(true, true);
//epee::debug::get_set_enable_assert(true, true);
currency::account_base genesis_acc;
genesis_acc.generate();
@ -47,7 +47,7 @@ bool escrow_wallet_test::generate(std::vector<test_event_entry>& events) const
DO_CALLBACK(events, "c1");
epee::debug::get_set_enable_assert(true, false);
//epee::debug::get_set_enable_assert(true, false);
return true;
}
@ -272,8 +272,8 @@ bool escrow_wallet_test::exec_test_with_cancel_release_type(currency::core& c, c
bool escrow_wallet_test::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
epee::debug::get_set_enable_assert(true, true);
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); });
//epee::debug::get_set_enable_assert(true, true);
//misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); });
bool r = exec_test_with_cancel_release_type(c, events);
if (!r)
@ -287,7 +287,7 @@ bool escrow_wallet_test::c1(currency::core& c, size_t ev_index, const std::vecto
if (!r)
return false;
epee::debug::get_set_enable_assert(true, false);
//epee::debug::get_set_enable_assert(true, false);
return r;
}
@ -780,7 +780,7 @@ bool escrow_proposal_expiration::c1(currency::core& c, size_t ev_index, const st
uint64_t alice_post_proposal_balance = alice_wlt->balance();
uint64_t alice_post_proposal_balance_expected = alice_start_balance - TESTS_DEFAULT_FEE;
CHECK_AND_ASSERT_MES(alice_post_proposal_balance == alice_post_proposal_balance_expected, false, "Incorrect alice_post_proposal_balance: " << print_money(alice_post_proposal_balance) << ", expected: " << print_money(alice_post_proposal_balance_expected));
std::deque<tools::transfer_details> transfers;
tools::transfer_container transfers;
alice_wlt->get_transfers(transfers);
CHECK_AND_ASSERT_MES(transfers.size() == 2 && (
(transfers[0].is_spent() && (transfers[1].m_flags & (WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION))) ||
@ -2283,7 +2283,7 @@ bool escrow_proposal_not_enough_money::c1(currency::core& c, size_t ev_index, co
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", MK_TEST_COINS(30), 0, MK_TEST_COINS(30), 0, 0), false, "");
std::deque<tools::transfer_details> transfers;
tools::transfer_container transfers;
alice_wlt->get_transfers(transfers);
CHECK_AND_ASSERT_MES(transfers.size() == 1, false, "Incorrect transfers size: " << transfers.size());

View file

@ -32,7 +32,7 @@ bool isolate_auditable_and_proof::generate(std::vector<test_event_entry>& events
test_core_time::adjust(m_genesis_timestamp);
epee::debug::get_set_enable_assert(true, true);
//epee::debug::get_set_enable_assert(true, true);
currency::account_base genesis_acc;
genesis_acc.generate();
@ -47,7 +47,7 @@ bool isolate_auditable_and_proof::generate(std::vector<test_event_entry>& events
REWIND_BLOCKS_N(events, blk_0r, blk_0, m_mining_accunt, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 15);
DO_CALLBACK(events, "c1");
epee::debug::get_set_enable_assert(true, false);
//epee::debug::get_set_enable_assert(true, false);
return true;
}
@ -61,8 +61,8 @@ bool isolate_auditable_and_proof::configure_core(currency::core& c, size_t ev_in
bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
epee::debug::get_set_enable_assert(true, true);
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); });
//epee::debug::get_set_enable_assert(true, true);
//misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); });
LOG_PRINT_MAGENTA("Mining Address: " << currency::get_account_address_as_str(m_mining_accunt.get_public_address()), LOG_LEVEL_0);

View file

@ -535,7 +535,7 @@ bool assets_and_explicit_native_coins_in_outs::c2_alice_deploys_asset(currency::
// make sure Alice has two UTXO now
tools::transfer_container transfers{};
alice_wlt->get_transfers(transfers);
size_t unspent_transfers = std::count_if(transfers.begin(), transfers.end(), [](const tools::transfer_details& tr){ return !tr.is_spent(); });
size_t unspent_transfers = std::count_if(transfers.begin(), transfers.end(), [](const auto& tr){ return !tr.second.is_spent(); });
CHECK_AND_ASSERT_MES(unspent_transfers == 2, false, "unexpected number of Alice's unspent transfers: " << unspent_transfers);
asset_descriptor_base adb{};
@ -694,15 +694,15 @@ bool asset_depoyment_and_few_zc_utxos::c1(currency::core& c, size_t ev_index, co
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", m_alice_initial_balance, 0, m_alice_initial_balance, 0, 0), false, "");
// make sure Alice has correct UTXO wallet structure
tools::transfer_container transfers{};
tools::transfer_container transfers;
alice_wlt->get_transfers(transfers);
size_t zc_unspent_outs = 0, unspent_outs = 0;
for(auto& td : transfers)
{
if (!td.is_spent())
if (!td.second.is_spent())
{
++unspent_outs;
if (td.is_zc())
if (td.second.is_zc())
++zc_unspent_outs;
}
}

View file

@ -2571,7 +2571,7 @@ bool multisig_unconfirmed_transfer_and_multiple_scan_pool_calls::c1(currency::co
LOG_PRINT_YELLOW("%%%%% tx " << get_transaction_hash(tx) << " is spending multisig output " << multisig_id, LOG_LEVEL_0);
bool stub;
std::deque<tools::transfer_details> transfers;
tools::transfer_container transfers;
std::vector<tools::wallet_public::wallet_transfer_info> unconfirmed_transfers;
alice_wlt->scan_tx_pool(stub);

View file

@ -1728,7 +1728,7 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
{
transaction tx{};
tx.vin.emplace_back();
tx.vin.emplace_back(txin_gen{});
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
@ -1750,7 +1750,6 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
point_t point_public_key{};
txout_to_key target{};
std::array<txin_to_key, 2> inputs{};
tx_out_bare output{};
transaction tx{};
CHECK_AND_ASSERT_EQ(point_public_key.from_string("499790c3302b9f0514e2db09b390679283d43d971383d33dc24c7991ea4cf6d7"), true);
@ -1763,10 +1762,6 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
tx.vin.push_back(input);
}
output.amount = 1;
output.target = target;
tx.vout.push_back(output);
CHECK_AND_ASSERT_GREATER(inputs.at(0).amount, inputs.at(0).amount + inputs.at(1).amount);
CHECK_AND_ASSERT_GREATER(inputs.at(1).amount, inputs.at(0).amount + inputs.at(1).amount);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
@ -1803,41 +1798,38 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
// Equal key images in inputs.
{
tx_out_bare output;
tx_out_bare output{};
transaction tx{};
std::array<txin_to_key, 2> inputs{};
point_t key_image_point{};
key_image image{};
output.amount = 1;
tx.vout.push_back(output);
CHECK_AND_ASSERT_EQ(key_image_point.from_string("8fc7cbfd1054690767d0c20917a68371b34b190aac5997581641f064b93d1b96"), true);
image = key_image_point.to_key_image();
for (int position{}; position < 2; ++position)
{
inputs.at(position).k_image = image;
tx.vin.push_back(inputs.at(position));
auto& input{inputs.at(position)};
input.k_image = key_image_point.to_key_image();
tx.vin.push_back(input);
}
CHECK_AND_ASSERT_EQ(tx.vin.at(0).type(), typeid(txin_to_key));
CHECK_AND_ASSERT_EQ(tx.vin.at(0).type(), tx.vin.at(1).type());
CHECK_AND_ASSERT_EQ(boost::get<txin_to_key>(tx.vin.at(0)).k_image, boost::get<txin_to_key>(tx.vin.at(1)).k_image);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// Two entries of the same type in extra.
{
tx_out_bare output;
transaction tx{};
std::array<txin_to_key, 2> inputs{};
std::array<point_t, 2> key_image_points{};
key_image image{};
output.amount = 1;
tx.vout.push_back(output);
CHECK_AND_ASSERT_EQ(key_image_points.at(0).from_string("de3c22a62f15e6de8abe6b217085b2aead196daf5ddd67d9c4b366330736fbeb"), true);
CHECK_AND_ASSERT_EQ(key_image_points.at(1).from_string("9f3eef913921ca35239e696725595e3686bb0d69e3e805791c5aa93d5754aa5c"), true);
@ -1859,8 +1851,8 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
// tx.version <= TRANSACTION_VERSION_PRE_HF4. Balance check fail: sum of inputs <= sum of outputs.
{
tx_out_bare output{};
transaction tx{};
tx_out_bare output;
std::array<point_t, 2> key_image_points{};
std::array<txin_to_key, 2> inputs{};
@ -1879,7 +1871,10 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
tx.vin.push_back(input);
}
CHECK_AND_ASSERT_GREATER(output.amount, std::accumulate(inputs.begin(), inputs.end(), std::uint64_t{}, [](uint64_t sum, const txin_to_key& input) { return sum + input.amount; }));
const uint64_t sum_inputs{std::accumulate(inputs.begin(), inputs.end(), std::uint64_t{}, [](uint64_t sum, const txin_to_key& input) { return sum + input.amount; })};
CHECK_AND_ASSERT_LESS(sum_inputs, output.amount);
CHECK_AND_ASSERT_EQ(output.amount - sum_inputs, 1);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
@ -1911,5 +1906,201 @@ bool tx_pool_semantic_validation::generate(std::vector<test_event_entry>& events
ADD_CUSTOM_EVENT(events, tx);
}
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
// Construct a valid transaction and then modify it so that the transaction is no longer semantically correct.
// No inputs.
{
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(2), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
tx.vin = {};
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// Unsupported input type.
{
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(2), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
tx.vin.emplace_back(txin_gen{});
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// Unsupported output type.
{
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(2), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
tx.vout.emplace_back();
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// Inputs amount overflow.
{
point_t point_public_key{};
txout_to_key target{};
std::array<txin_to_key, 2> inputs{};
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(2), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
CHECK_AND_ASSERT_EQ(point_public_key.from_string("499790c3302b9f0514e2db09b390679283d43d971383d33dc24c7991ea4cf6d7"), true);
target.key = point_public_key.to_public_key();
inputs.at(0).amount = 1;
inputs.at(1).amount = UINT64_MAX;
for (const auto& input : inputs)
{
tx.vin.push_back(input);
}
CHECK_AND_ASSERT_GREATER(inputs.at(0).amount, inputs.at(0).amount + inputs.at(1).amount);
CHECK_AND_ASSERT_GREATER(inputs.at(1).amount, inputs.at(0).amount + inputs.at(1).amount);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// Outputs amount overflow.
{
point_t point_public_key{};
txout_to_key target{};
std::array<tx_out_bare, 2> outputs{};
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(2), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
CHECK_AND_ASSERT_EQ(point_public_key.from_string("78ef3d9af7b5e3d09556d57820cf68c2b3553a9d8205c01fe40fc70aae86bb4f"), true);
target.key = point_public_key.to_public_key();
outputs.at(0).amount = 1;
outputs.at(1).amount = UINT64_MAX;
for (auto& output : outputs)
{
output.target = target;
tx.vout.push_back(output);
}
tx.vin.push_back(txin_to_key{});
CHECK_AND_ASSERT_GREATER(outputs.at(0).amount, outputs.at(0).amount + outputs.at(1).amount);
CHECK_AND_ASSERT_GREATER(outputs.at(1).amount, outputs.at(0).amount + outputs.at(1).amount);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// Equal key images in inputs.
{
tx_out_bare output{};
std::array<txin_to_key, 2> inputs{};
point_t key_image_point{};
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(2), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
output.amount = 1;
tx.vout.push_back(output);
CHECK_AND_ASSERT_EQ(key_image_point.from_string("8fc7cbfd1054690767d0c20917a68371b34b190aac5997581641f064b93d1b96"), true);
for (int position{}; position < 2; ++position)
{
inputs.at(position).k_image = key_image_point.to_key_image();
tx.vin.push_back(inputs.at(position));
}
{
const auto& input_preceding_last{tx.vin.at(tx.vin.size() - 2u)};
CHECK_AND_ASSERT_EQ(tx.vin.back().type(), typeid(txin_to_key));
CHECK_AND_ASSERT_EQ(tx.vin.back().type(), input_preceding_last.type());
CHECK_AND_ASSERT_EQ(boost::get<txin_to_key>(tx.vin.back()).k_image, boost::get<txin_to_key>(input_preceding_last).k_image);
}
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// Two entries of the same type in extra.
{
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(2), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
tx.extra.push_back(null_pkey);
tx.extra.push_back(null_pkey);
CHECK_AND_ASSERT_GREATER(tx.extra.size(), 2);
CHECK_AND_ASSERT_EQ(typeid(tx.extra.back()), typeid(tx.extra.at(tx.extra.size() - 2)));
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
// tx.version <= TRANSACTION_VERSION_PRE_HF4. Balance check fail: sum of inputs <= sum of outputs.
{
tx_out_bare output{};
std::array<point_t, 2> key_image_points{};
std::array<txin_to_key, 2> inputs{};
MAKE_TX_FEE(events, tx, miner, miner, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, blk_0r);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), true);
output.amount = 10'000'000'003;
tx.vout.push_back(output);
tx.version = 0;
CHECK_AND_ASSERT_EQ(key_image_points.at(0).from_string("8fc7cbfd1054690767d0c20917a68371b34b190aac5997581641f064b93d1b96"), true);
CHECK_AND_ASSERT_EQ(key_image_points.at(1).from_string("dc48b741dacda5ac026ad0a7d193b816049eb08724907a1ff6f95839cfb0efa5"), true);
for (int position{}; position < 2; ++position)
{
auto& input{inputs.at(position)};
input.amount = 1;
input.k_image = key_image_points.at(position).to_key_image();
tx.vin.push_back(input);
}
const auto inputs_sum{[](const uint64_t sum, const txin_v& input) -> uint64_t
{
if (input.type() == typeid(txin_to_key))
{
return sum + boost::get<txin_to_key>(input).amount;
}
if (input.type() == typeid(txin_multisig))
{
return sum + boost::get<txin_multisig>(input).amount;
}
}
};
const auto outputs_sum{[](const uint64_t sum, const tx_out_v& output) -> uint64_t
{
if (output.type() == typeid(tx_out_bare))
{
return sum + boost::get<tx_out_bare>(output).amount;
}
}
};
const uint64_t inputs_amount{std::accumulate(tx.vin.begin(), tx.vin.end(), std::uint64_t{}, inputs_sum)};
const uint64_t outputs_amount{std::accumulate(tx.vout.begin(), tx.vout.end(), std::uint64_t{}, outputs_sum)};
CHECK_AND_ASSERT_LESS(inputs_amount, outputs_amount);
CHECK_AND_ASSERT_EQ(outputs_amount - inputs_amount, 1);
CHECK_AND_ASSERT(tx.version <= TRANSACTION_VERSION_PRE_HF4, false);
CHECK_AND_ASSERT_EQ(get_block_height(blk_0r), 10);
CHECK_AND_ASSERT_EQ(m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_03, 10), true);
CHECK_AND_ASSERT_EQ(m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, 10), false);
CHECK_AND_ASSERT_EQ(validate_tx_semantic(tx, CURRENCY_MAX_TRANSACTION_BLOB_SIZE - 1), false);
DO_CALLBACK(events, "mark_invalid_tx");
ADD_CUSTOM_EVENT(events, tx);
}
return true;
}

View file

@ -161,7 +161,7 @@ struct tx_version_against_hardfork : public test_chain_unit_enchanced
bool generate(std::vector<test_event_entry>& events) const;
};
struct tx_pool_semantic_validation : public test_chain_unit_enchanced
struct tx_pool_semantic_validation : public test_chain_unit_enchanced
{
bool generate(std::vector<test_event_entry>& events) const;
};

View file

@ -89,7 +89,7 @@ bool wallet_test_core_proxy::call_COMMAND_RPC_GET_BLOCKS_FAST(const currency::CO
rsp.current_height = m_blocks.size();
rsp.status = API_RETURN_CODE_OK;
if (!m_first_call)
if (!m_first_call && rsp.start_height != 0 /*second condition needed for re-sync in concise_mode*/)
{
m_first_call = true;
return true; // respond with empty blocks on second call to gracefully stop wallet refreshing

View file

@ -1490,6 +1490,9 @@ bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& e
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
CREATE_TEST_WALLET(alice_wlt, alice_acc, blk_0);
//disable concise because this test count on on_transfer callbacks and resync cause firing on_transfer() for previous transactions
alice_wlt->set_concise_mode(false);
REFRESH_TEST_WALLET_AT_GEN_TIME(events, alice_wlt, blk_0r, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
// these attachments will be used across all the transactions in this test
@ -3819,6 +3822,7 @@ bool wallet_and_sweep_below::c1(currency::core& c, size_t ev_index, const std::v
//------------------------------------------------------------------------------
block_template_blacklist_test::block_template_blacklist_test()
{
REGISTER_CALLBACK_METHOD(block_template_blacklist_test, c1);
@ -3908,3 +3912,64 @@ bool block_template_blacklist_test::c1(currency::core& c, size_t ev_index, const
return true;
}
//------------------------------------------------------------------------------
wallet_reorganize_and_trim_test::wallet_reorganize_and_trim_test()
{
REGISTER_CALLBACK_METHOD(wallet_reorganize_and_trim_test, c1);
}
bool wallet_reorganize_and_trim_test::generate(std::vector<test_event_entry>& events) const
{
uint64_t ts = test_core_time::get_time();
m_accounts.resize(1);
account_base preminer_acc;
preminer_acc.generate();
preminer_acc.set_createtime(ts);
account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts);
MAKE_GENESIS_BLOCK(events, blk_0, preminer_acc, ts);
DO_CALLBACK(events, "configure_core");
MAKE_NEXT_BLOCK(events, blk_1, blk_0, preminer_acc);
REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, 2 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW - 1);
DO_CALLBACK(events, "c1");
return true;
}
bool wallet_reorganize_and_trim_test::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
std::shared_ptr<tools::wallet2> miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX);
//mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, 2);
#define WALLET_REORGANIZE_AND_TRIM_TEST_REORG_SIZE 10
miner_wlt->set_concise_mode(true);
miner_wlt->set_concise_mode_reorg_max_reorg_blocks(6);
account_base acc;
acc.generate();
std::shared_ptr<tools::wallet2> alice = init_playtime_test_wallet(events, c, acc);
miner_wlt->refresh();
miner_wlt->transfer(COIN, alice->get_account().get_public_address());
mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, 2);
mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_REORGANIZE_AND_TRIM_TEST_REORG_SIZE);
uint64_t h1 = c.get_blockchain_storage().get_top_block_height();
miner_wlt->refresh();
uint64_t unlocked = 0;
uint64_t total = miner_wlt->balance(unlocked);
c.get_blockchain_storage().truncate_blockchain(c.get_blockchain_storage().get_top_block_height() - (WALLET_REORGANIZE_AND_TRIM_TEST_REORG_SIZE-1));
mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, 10);
uint64_t h2 = c.get_blockchain_storage().get_top_block_height();
miner_wlt->refresh();
uint64_t unlocked2 = 0;
uint64_t total2 = miner_wlt->balance(unlocked2);
if (unlocked2 != unlocked || total2 != total)
{
CHECK_AND_ASSERT_MES(false, false, "wallet concise mode check failed");
}
return true;
}

View file

@ -301,4 +301,11 @@ struct block_template_blacklist_test : public wallet_test
block_template_blacklist_test();
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);
};
struct wallet_reorganize_and_trim_test : public wallet_test
{
wallet_reorganize_and_trim_test();
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);
};

View file

@ -60,6 +60,8 @@ struct wallet_test : virtual public test_chain_unit_enchanced
w->set_genesis(genesis_hash);
w->set_core_proxy(m_core_proxy);
w->set_disable_tor_relay(true);
w->set_concise_mode(true);
w->set_concise_mode_reorg_max_reorg_blocks(TESTS_CONCISE_MODE_REORG_MAX_REORG_BLOCK);
return w;
#undef LOCAL_HOST_CSTR

View file

@ -450,7 +450,7 @@ namespace boost
bool core_concurrency_test(boost::program_options::variables_map& vm, size_t wthreads, size_t rthreads, size_t blocks_count)
{
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
//epee::debug::get_set_enable_assert(true, false);
epee::debug::get_set_enable_assert(true, false);
log_space::get_set_need_thread_id(true, true);
cct_accounts_t accounts(s_wallets_total_count);

View file

@ -317,7 +317,7 @@ inline std::ostream& operator<<(std::ostream& ss, const fe &f)
{
constexpr size_t fe_index_max = (sizeof f / sizeof f[0]) - 1;
ss << "{";
for (size_t i = 0; i <= fe_index_max; ++i)
for (size_t i = 0; i < fe_index_max; ++i)
ss << f[i] << ", ";
return ss << f[fe_index_max] << "}";
}
@ -490,14 +490,6 @@ struct test_keeper_t
};
////////////////////////////////////////////////////////////////////////////////
// #include "crypto_tests_ml2s.h"
#include "crypto_tests_range_proofs.h"
#include "crypto_tests_clsag.h"
#include "crypto_tests_one_out_of_many_proofs.h"
////////////////////////////////////////////////////////////////////////////////
//
// Tests
@ -609,8 +601,6 @@ TEST(crypto, constants)
#include "crypto_tests_performance.h"
TEST(crypto, ge_scalarmult_vartime_p3)
{
// make sure that my ge_scalarmult_vartime_p3 gives the same result as ge_scalarmul_p3
@ -1501,6 +1491,86 @@ TEST(crypto, point_is_zero)
return true;
}
// pairs of the same points but with different fe representation (that caused old eq op to fail)
std::vector<std::pair<point_t, point_t>> twin_point_pairs {
{
point_t{{-21128868, 3837998, 33062696, -4394645, -14632370, -4032942, -13494326, 9949403, -22877702, 12347080, -23842113, 10741520, -31317130, 13501783, -30346713, 9537971, -4230538, 5133263, 19202715, 304530, 11783766, -14713954, 31928743, -15802260, -23524982, -12132264, -2221079, -13294882, 15351986, -12208940, -25429666, -10630821, 10586935, 3680531, -5196293, 15100068, -4109273, 2588076, -22807834, 9178747}},
point_t{{-9713365, -9829929, 12195149, -3403928, -26261133, -16229257, -31293898, -3007350, 14656870, -441189, -21842901, -10684017, -14933612, -15577968, 6355936, -12616303, 17881365, 2613091, -29791631, 8160616, -6564960, 3860717, -32409761, 10253039, -32570848, -3563771, -7755841, 14547843, -12480489, 13372339, 21802122, 15976373, -16158840, -2718080, -16676669, 14276439, -7192951, 11049430, 27384949, 10563297}}
},
{
point_t{{3695219, -9621154, -17709499, 2939106, 3744267, -14575097, -23519506, -10091102, -2604099, 14269408, -3229226, 6334758, -32391005, -2351680, -8798530, -2266840, 32921382, -2519414, -18691041, 3881653, -15053990, 9136740, -3226527, -4942926, 1506694, -9001375, 27935490, -14623776, -3948473, 4210796, 18939736, -15596865, -13293120, 1337568, -18317440, -5143258, 16723454, 14691110, 9769827, -3118966}},
point_t{{-11397382, -16642076, -15110371, -3127178, -20841265, -8333469, -8416820, -11641211, -24444275, -1309821, -3258975, -14590075, 2704495, -11408556, -1158440, -13417600, -17702918, 15792391, -17674166, 7544500, -30233403, -6317281, -29573467, 13768629, -1805743, 10305936, -5964981, 2553131, 25279025, 5554228, 24015913, 3005849, 25526408, -4040648, 14468366, 14790756, 25816013, 15853930, 18508209, -16582046}}
},
{
point_t{{3469318, -85183, 29056087, 13528494, -23149977, 16623454, 3373881, 7763807, 24097266, 11526397, 8089099, -2103871, -32120521, 1046529, 28087844, 6858112, -27963932, -3359170, 21430085, -5312246, 21764518, -13443543, -12702889, -12398634, 10157405, 4858225, 26174527, -11743221, -30269431, -10050502, 25862179, 4744514, 32296603, 6270322, -28198957, 1471820, -13801749, -3295909, 17760181, -12065527}},
point_t{{-28763218, -1114036, 4671232, -1599732, -14823984, -9622687, 15430161, 12840558, 30741788, -11449341, -28556261, 3623611, 25689145, -14680141, -7832784, 14819387, 2481189, -13167197, -28732414, -14312280, -32965162, -7714625, 33268896, -2408169, -10811971, -4363847, -26138329, 5165910, -18544903, -7502120, 10360740, 6034706, 28458994, -5675091, -28036374, -702149, -8660662, -13290682, 9067253, 4344694}}
},
{
point_t{{-5841866, -15636514, 12367718, 16116867, -26645766, 5140632, 33476033, -3893277, -6807986, -6188111, -18150893, -7313585, -22559821, 14208716, -5344811, -581281, 24672694, -6638035, -10808134, -3046, -7472033, -8901879, 15120908, -7133930, 15015498, 12440181, -27737720, 396004, 3105271, 11399924, 12739797, -10781030, -27655617, 10547004, -1517603, -14788397, -16728565, 5538806, 27633091, 5635300}},
point_t{{29738502, -9099722, 18969328, -5041586, -17865763, 3799509, -8535672, 15345696, 760867, -3647512, 21227601, 2877796, 21366975, -5870266, 14750680, 10962526, 10279514, 12394109, -15626344, -10182797, 3199874, -24046, -14148768, -14198371, -29493512, -16221096, -3714752, -8636183, 5751940, -7670476, 1204040, 8561908, -16290929, 13125810, -24274070, -7039328, -21149730, -9157888, -16370207, -4817989}}
},
{
point_t{{5583931, 3584727, 352648, -3282339, -25634902, 4982415, 6570289, -7123343, 28056356, -14753772, 15464638, -10030089, 13934473, 10182538, -32633085, -3344322, 10345546, -6010634, -11737756, 7740657, 12017410, -3538127, -21949796, -16720911, 18521392, -7746707, -25163322, 16438097, -14488853, -11100914, 11664826, -4058927, 13298397, 10849774, 22800849, -8941814, 31033013, 362090, -20721545, 10379502}},
point_t{{-15413065, 10389318, 28684750, 9129051, 13176029, -15599624, 16333382, -15196190, 5299760, 5379067, -11298666, -10943555, 24033630, -10331364, -6271762, 15703052, -6168555, -10342077, -17144019, -3303678, 32460403, 15294706, 19144257, 16248865, 22506488, 5505084, -401821, 9347950, -6513204, 7226066, -26715856, 11994906, -13302883, -8556677, 15797496, -3086516, 23027165, 1637560, -29381930, 12262558}}
},
{
point_t{{-26548919, 11392979, 28773327, 197314, 13888676, 5289903, 14156094, -3215467, 12204802, 11098576, -15494111, 10812748, -11869915, -343850, -20456404, -12577384, -4979562, 15251598, -487043, 11571657, -16066121, -2338179, -16228507, 5602197, 25353942, -7225080, 22718433, -11309476, -10403076, 11326705, -296493, -4563931, 10628858, 16672320, 24967340, 210989, -11332864, -13045242, -32517393, 9220843}},
point_t{{-8809414, 1276711, 5724117, -10893002, 16836911, -10562554, 7928860, 4905731, -30890761, -16272783, 15099435, 7209265, -17062927, -15647371, -26068760, -10022538, 15199805, 11039218, -17427534, -3334404, 9597778, 5993687, -14091491, -6035380, -18428597, -4056089, -14203111, 349297, 20316350, 1399705, 2972501, -1228750, -23459865, -88574, 9071309, 11300857, 9425425, 596628, 3627198, -1613531}}
},
{
point_t{{-15051466, -12717864, -1094059, 9523511, -9851421, 6693669, -6491711, -14360212, -10025337, 5146942, -15213537, -14748468, -16189919, 6643542, -22303813, -6712277, 12722420, 3747576, -11411745, -5170831, 6906842, -3442874, 13923053, 5056698, 14272344, 2297302, 24147707, 1505741, 23445765, 7170090, -14014582, 6539085, -25379082, 15881906, 9955130, -10830876, -6331971, -9745690, 19301861, -3693027}},
point_t{{-23568458, 9628844, -26909663, -2205696, 16765570, 12703337, -19733659, -1311798, 6240000, -3186465, -12848561, -9029739, -21391036, 5644922, 29142361, -8070730, 15491500, 5159583, -15039215, -3782415, 17864864, 13111010, -24101940, 9297110, -23296716, 9763494, -33210081, 12312114, -30144102, 10080914, 31682399, 7452145, 19314287, -7581029, -24620989, -3233342, -25926522, -14260964, 24233736, 13681782}}
},
{
point_t{{19211265, 2757185, 22841428, 4384196, -5344236, -6665958, 13817937, -15401311, 11324591, 13548371, 5920675, -7720845, -26190512, 80906, 11282325, -16150822, 18149158, -15519773, 2721716, -11983296, -14418387, -11153557, 13957160, -3743225, 22506862, -3245854, 4494361, 13510745, -5656988, 5588269, 28354819, -13495704, -13208982, -495328, 17363458, -10857316, -5302126, -7875123, 26008688, -13624830}},
point_t{{9615635, 11456756, -23929642, 1059944, 1030437, -11895019, 12717341, 14376320, 18760933, -13214228, 28877065, 8204034, -13488237, -4234088, -16433228, 12293567, 22065763, 1258393, 20249733, -7792923, -28493355, -10099755, 9817133, 10497183, 7163689, 3742107, -24288334, 7485474, 17332829, 1167562, -7414283, -2724061, 32933754, 3732809, 18401256, 10890894, -28075941, -4870953, 21081310, 10942194}}
},
{
point_t{{15697801, -6534008, 10450035, -1554623, -18762845, 11804480, 30164267, 4203906, 28533676, 10647395, 30633476, 9271811, 8721644, -7564181, 5372849, -11987056, 21870223, -770830, -23302500, 5628035, -12397032, 14456892, 14966767, -4384854, 6238573, 5721532, -3482707, 93803, 17582081, -8642913, 10405075, -7178396, -5588624, 15751945, 21474071, 14634321, 2195436, -9319762, -31171521, 3257219}},
point_t{{-9159868, 13485045, -1816502, 9498441, 12599869, -9143471, -3235081, -7400456, -11042456, 10726811, 30758369, 2034330, -10446636, -12818157, 15789290, 11476501, 12893075, -11738407, 5385991, -11602328, -12578961, -5727994, -3242915, -14123261, 18142422, 9302871, -27881894, 1412251, 13445358, 3794224, 30076600, 12194158, 27928330, -11549668, -21526967, 908741, 7889436, 11312182, 479283, 3079906}}
}
};
TEST(crypto, point_eq_op)
{
for(auto& pp : twin_point_pairs)
{
ASSERT_TRUE((pp.first - pp.second).is_zero());
ASSERT_TRUE((pp.second - pp.first).is_zero());
scalar_t r = scalar_t::random();
ASSERT_TRUE((r * pp.first - r * pp.second).is_zero());
ASSERT_TRUE((r * pp.second - r * pp.first).is_zero());
ASSERT_TRUE (pp.first == pp.second);
ASSERT_FALSE(pp.first != pp.second);
ASSERT_TRUE (pp.second == pp.first);
ASSERT_FALSE(pp.second != pp.first);
}
//// twin points generator
//size_t N = 10000000;
//size_t hits = 0;
//scalar_t r = scalar_t::random();
//point_t R = r * c_point_G;
//for(size_t i = 0; i < N; ++i)
//{
// scalar_t s = scalar_t::random();
// point_t X = (r + s) * c_point_G;
// point_t Y = R + s * c_point_G;
// if (!(X == Y))
// {
// ++hits;
// std::cout << hits << ENDL
// << " X: " << X << " {" << X.to_comma_separated_int32_str() << "}" << ENDL
// << " Y: " << Y << " {" << Y.to_comma_separated_int32_str() << "}" << ENDL;
// }
//}
//std::cout << ENDL << hits << " hits of " << N << ENDL;
return true;
}
TEST(crypto, sc_get_bit)
{
@ -1985,6 +2055,15 @@ TEST(crypto, eth_signature_basics)
////////////////////////////////////////////////////////////////////////////////
// #include "crypto_tests_ml2s.h"
#include "crypto_tests_range_proofs.h"
#include "crypto_tests_clsag.h"
#include "crypto_tests_one_out_of_many_proofs.h"
#include "crypto_tests_performance.h"
////////////////////////////////////////////////////////////////////////////////
//
// test's runner

View file

@ -1,6 +1,8 @@
// Copyright (c) 2021 Zano Project
// Copyright (c) 2021-2024 Zano Project
// Copyright (c) 2021-2024 sowle (val@zano.org, crypto.sowle@gmail.com)
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//
#pragma once
#include <numeric>
@ -1233,3 +1235,106 @@ TEST(perf, generators)
return true;
}
bool old_point_eq_operator_bugous(const point_t& lhs, const point_t& rhs)
{
// convert to xy form, then compare components (because (x, y, z, t) representation is not unique)
fe lrecip, lx, ly;
fe rrecip, rx, ry;
fe_invert(lrecip, lhs.m_p3.Z);
fe_invert(rrecip, rhs.m_p3.Z);
fe_mul(lx, lhs.m_p3.X, lrecip);
fe_mul(rx, rhs.m_p3.X, rrecip);
if (memcmp(&lx, &rx, sizeof lx) != 0)
return false;
fe_mul(ly, lhs.m_p3.Y, lrecip);
fe_mul(ry, rhs.m_p3.Y, rrecip);
if (memcmp(&ly, &ry, sizeof ly) != 0)
return false;
return true;
}
bool old_point_eq_operator(const point_t& lhs, const point_t& rhs)
{
// convert to xy form, then compare components (because (x, y, z, t) representation is not unique)
fe lrecip, lx, ly, dx;
fe rrecip, rx, ry, dy;
fe_invert(lrecip, lhs.m_p3.Z);
fe_invert(rrecip, rhs.m_p3.Z);
fe_mul(lx, lhs.m_p3.X, lrecip);
fe_mul(rx, rhs.m_p3.X, rrecip);
fe_sub(dx, lx, rx);
if (fe_isnonzero(dx) != 0)
return false;
fe_mul(ly, lhs.m_p3.Y, lrecip);
fe_mul(ry, rhs.m_p3.Y, rrecip);
fe_sub(dy, ly, ry);
if (fe_isnonzero(dy) != 0)
return false;
return true;
}
TEST(perf, point_eq_vs_iszero)
{
const size_t warmup_rounds = 20;
const size_t rounds = 200;
const size_t inner_rounds = 64;
std::vector<uint64_t> timings1, timings2;
size_t N = inner_rounds - twin_point_pairs.size() * 2; // number of random points
scalar_vec_t scalars;
scalars.resize_and_make_random(N);
std::vector<point_t> points(N);
std::transform(scalars.cbegin(), scalars.cend(), points.begin(), [](const scalar_t& s){ return s * c_point_G; });
// add twin points
for(auto& p : twin_point_pairs)
points.push_back(p.first), points.push_back(p.second);
ASSERT_EQ(points.size(), inner_rounds);
// and shuffle
std::shuffle(points.begin(), points.end(), crypto::uniform_random_bit_generator{});
for(size_t i = 0; i < rounds + warmup_rounds; ++i)
{
std::vector<uint8_t> results1(inner_rounds), results2(inner_rounds);
TIME_MEASURE_START(t1);
for(size_t j = 0; j < inner_rounds; ++j)
for(size_t k = j + 1; k < inner_rounds; ++k)
results1[j] ^= uint8_t(old_point_eq_operator(points[j], points[k]) ? j : k);
TIME_MEASURE_FINISH(t1);
uint64_t h1 = hash_64(results1.data(), results1.size() * sizeof(results1[0]));
TIME_MEASURE_START(t2);
for(size_t j = 0; j < inner_rounds; ++j)
for(size_t k = j + 1; k < inner_rounds; ++k)
results2[j] ^= uint8_t((points[j] - points[k]).is_zero() ? j : k);
TIME_MEASURE_FINISH(t2);
uint64_t h2 = hash_64(results2.data(), results2.size() * sizeof(results2[0]));
ASSERT_EQ(h1, h2);
if (i >= warmup_rounds)
{
timings1.push_back(t1);
timings2.push_back(t2);
}
}
std::cout << "After " << rounds << " rounds:" << ENDL <<
"point_t operator== : " << epee::misc_utils::median(timings1) << " mcs" << ENDL <<
"point_t is_zero() : " << epee::misc_utils::median(timings2) << " mcs" << ENDL;
return true;
}

View file

@ -197,9 +197,9 @@ uint64_t got_money_in_first_transfers(const tools::transfer_container& incoming_
{
uint64_t summ = 0;
size_t count = 0;
BOOST_FOREACH(const tools::transfer_details& td, incoming_transfers)
for(auto& tr : incoming_transfers)
{
summ += boost::get<tx_out_bare>(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index]).amount;
summ += boost::get<tx_out_bare>(tr.second.m_ptx_wallet_info->m_tx.vout[tr.second.m_internal_output_index]).amount;
if(++count >= n_transfers)
return summ;
}
@ -245,9 +245,9 @@ std::string get_incoming_transfers_str(tools::wallet2& w)
uint64_t spent_count = 0;
uint64_t unspent_count = 0;
for (const auto& td : transfers)
for (const auto& tr : transfers)
{
if (td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_SPENT)
if (tr.second.m_flags&WALLET_TRANSFER_DETAIL_FLAG_SPENT)
{
++spent_count;
}
@ -469,8 +469,9 @@ bool transactions_flow_test(
//lets go!
size_t count = 0;
prepared_transfers = 0;
BOOST_FOREACH(tools::transfer_details& td, incoming_transfers)
for(const auto& tr : incoming_transfers)
{
const tools::transfer_details& td = tr.second;
if (td.is_spent())
continue;

View file

@ -5,21 +5,189 @@
#include "gtest/gtest.h"
#include "common/util.h"
bool check_parse_client_version(const std::string& str, int expected_major, int expected_minor, int expected_revision, int expected_build_number, const std::string& expected_commit_id, bool expected_dirty)
enum class reponse_check_parse_client_version : uint8_t
{
int major = -1, minor = -1, revision = -1, build_number = -1;
std::string commit_id;
bool dirty = false;
if (!tools::parse_client_version(str, major, minor, revision, build_number, commit_id, dirty))
return false;
parsed,
not_parsed,
parsed_unexpect
};
return major == expected_major && minor == expected_minor && revision == expected_revision && build_number == expected_build_number && commit_id == expected_commit_id && dirty == expected_dirty;
reponse_check_parse_client_version check_parse_client_version(const std::string& str, const std::optional<int>& expected_major, const std::optional<int>& expected_minor,
const std::optional<int>& expected_revision, const std::optional<int>& expected_build_number,
const std::optional<std::string>& expected_commit_id, const std::optional<bool>& expected_dirty)
{
enum class version_integer_component : uint8_t { major, minor, revision, build_number };
// 3 not in {0; 1} and low-order bit not equsl to 0.
constexpr uint8_t out_of_logicals_value{3};
std::array<int64_t, 4> out_of_int32_bounds_values{};
{
// (1 ** 32) > INT32_MAX
constexpr auto out_of_int32_bounds_value{static_cast<int64_t>(1) << 32};
if (expected_major.has_value() && expected_major.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::major));
}
if (expected_minor.has_value() && expected_minor.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::minor));
}
if (expected_revision.has_value() && expected_revision.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::revision));
}
if (expected_build_number.has_value() && expected_build_number.value() == 0)
{
++out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::build_number));
}
}
int64_t major_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::major))},
minor_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::minor))},
revision_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::revision))},
build_number_pass{out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::build_number))};
std::string commit_id{};
uint8_t dirty_pass{out_of_logicals_value};
if (!tools::parse_client_version(str, reinterpret_cast<int32_t&>(major_pass), reinterpret_cast<int32_t&>(minor_pass), reinterpret_cast<int32_t&>(revision_pass),
reinterpret_cast<int32_t&>(build_number_pass), commit_id, reinterpret_cast<bool&>(dirty_pass)))
{
return reponse_check_parse_client_version::not_parsed;
}
constexpr uint64_t mask_to_fit_value_int32{0x00000000FFFFFFFF};
const auto major{static_cast<int32_t>(major_pass & mask_to_fit_value_int32)};
const auto minor{static_cast<int32_t>(minor_pass & mask_to_fit_value_int32)};
const auto revision{static_cast<int32_t>(revision_pass & mask_to_fit_value_int32)};
const auto build_number{static_cast<int32_t>(build_number_pass & mask_to_fit_value_int32)};
const bool dirty{dirty_pass != 2 && dirty_pass != out_of_logicals_value};
if (expected_major.has_value())
{
if (major_pass == out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::major)) || major != expected_major.value())
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
else
{
if (major_pass != out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::major)))
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
if (expected_minor.has_value())
{
if (minor_pass == out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::minor)) || minor != expected_minor.value())
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
else
{
if (minor_pass != out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::minor)))
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
if (expected_revision.has_value())
{
if (revision_pass == out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::revision)) || revision != expected_revision.value())
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
else
{
if (revision_pass != out_of_int32_bounds_values.at(static_cast<uint8_t>(version_integer_component::revision)))
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
if (expected_commit_id.has_value())
{
if (commit_id != expected_commit_id.value())
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
else
{
if (!commit_id.empty())
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
if (expected_dirty.has_value())
{
if (dirty != expected_dirty.value())
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
else
{
if (dirty_pass != out_of_logicals_value)
{
return reponse_check_parse_client_version::parsed_unexpect;
}
}
return reponse_check_parse_client_version::parsed;
}
TEST(p2p_client_version, test_0)
{
ASSERT_TRUE(check_parse_client_version("10.101.999.28391[deadbeef31337-dirty]", 10, 101, 999, 28391, "deadbeef31337", true));
ASSERT_EQ(check_parse_client_version("10.101.999.28391[deadbeef31337-dirty]", 10, 101, 999, 28391, "deadbeef31337", true), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("+67.+43.+50.+83", 67, 43, 50, 83, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-12.-90.17.-95", -12, -90, 17, -95, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("54.-100.-76.21[]", 54, -100, -76, 21, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-93.8.-81.75[-dirty]", -93, 8, -81, 75, "", true), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-8.-85.79.24[--dirty]", -8, -85, 79, 24, "-", true), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-62.53.79.80[\\]", -62, 53, 79, 80, "\\", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-27.91.-12.34[-]", -27, 91, -12, 34, "-", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-51.-66.-10.58\0[--dirty]", -51, -66, -10, 58, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-24.27.-81.79[" "\0" "-dirty]", {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
ASSERT_EQ(check_parse_client_version("0.0.0.0", 0, 0, 0, 0, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("27 . 33 . -59 . 47", 27, 33, -59, 47, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-2147483648.-2147483648.-2147483648.-2147483648", INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("2147483647.2147483647.2147483647.2147483647", INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("2147483648.2147483648.2147483648.2147483648", INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("-2147483649.-2147483649.-2147483649.-2147483649", INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("0098.+0096.0081.-0056", 98, 96, 81, -56, "", false), reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version("\0" "38.67.31.-24", 38, 67, 31, -24, "", false), reponse_check_parse_client_version::not_parsed);
ASSERT_EQ(check_parse_client_version({'-', '6', '8', '.', '\0', '2', '9', '.', '5', '9', '.', '-', '7', '9'}, {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
ASSERT_EQ(check_parse_client_version("....", {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
ASSERT_EQ(check_parse_client_version("54.12.-10", {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
ASSERT_EQ(check_parse_client_version("-.-.-.-", {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
ASSERT_EQ(check_parse_client_version(" . . . ", {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
ASSERT_EQ(check_parse_client_version({'-', '2', '3', '.', '6', '.', '-', '1', '8', '.', '-', '1', '1', '[', '\0', ']'}, -23, 6, -18, -11, std::string{'\0'}, false),
reponse_check_parse_client_version::parsed);
ASSERT_EQ(check_parse_client_version({'9', '8', '.', '3', '.', '8', '9', '.', '-', '1', '[', '\0', '-', 'd', 'i','r', 't', 'y', ']'}, 98, 3, 89, -1, std::string{'\0'}, true),
reponse_check_parse_client_version::parsed);
//ASSERT_EQ(check_parse_client_version("5.42.25.-42[].", 5, 42, 25, -42, "", false), reponse_check_parse_client_version::parsed);
//ASSERT_EQ(check_parse_client_version("-84.91.-10.1[-dirty].", 5, 42, 25, -42, "", true), reponse_check_parse_client_version::parsed);
//ASSERT_EQ(check_parse_client_version("33.62.-92.-44.", 33, 62, -92, -44, "", false), reponse_check_parse_client_version::parsed);
//ASSERT_EQ(check_parse_client_version("...", {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
//ASSERT_EQ(check_parse_client_version("-80.28.-6.1[", -80, 28, -6, 1, "", false), reponse_check_parse_client_version::parsed);
//ASSERT_EQ(check_parse_client_version("-88.-36.11.-25[", -80, 28, -6, 1, "", false), reponse_check_parse_client_version::parsed);
//ASSERT_EQ(check_parse_client_version("0.0.0.[]", {}, {}, {}, {}, {}, {}), reponse_check_parse_client_version::not_parsed);
}