From ca094054919662d9e605b4b017cd9006294f1ac3 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 2 Sep 2024 21:44:41 +0400 Subject: [PATCH] core tests working --- src/wallet/wallet2.cpp | 18 +++++++++--------- src/wallet/wallet2.h | 2 +- tests/core_tests/chaingen.cpp | 5 +++-- tests/core_tests/escrow_wallet_tests.cpp | 4 ++-- tests/core_tests/multiassets_test.cpp | 8 ++++---- tests/core_tests/multisig_wallet_tests.cpp | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 844b14e0..cefa36cf 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -802,7 +802,7 @@ namespace tools } ptc.employed_entries.receive.push_back(wallet_public::employed_tx_entry{ o , out.amount , out.asset_id }); - uint64_t new_index = m_transfers.empty() ? 0 : (--m_transfers.end())->first; + uint64_t new_index = m_transfers.empty() ? 0 : (--m_transfers.end())->first+1; auto rsp = m_transfers.insert(std::make_pair(new_index, boost::value_initialized())); transfer_details& td = rsp.first->second; td.m_ptx_wallet_info = pwallet_info; @@ -2995,11 +2995,11 @@ namespace tools // rollback incoming transfers from detaching subchain { - auto it = std::find_if(m_transfers.begin(), m_transfers.end(), [&](const transfer_container::value_type& tr_e){return tr_e.second.m_ptx_wallet_info->m_block_height >= including_height; }); - if (it != m_transfers.end()) + auto it_start = std::find_if(m_transfers.begin(), m_transfers.end(), [&](const transfer_container::value_type& tr_e){return tr_e.second.m_ptx_wallet_info->m_block_height >= including_height; }); + if (it_start != m_transfers.end()) { - for (; it!= m_transfers.end(); it++) + for (auto it = it_start; it!= m_transfers.end(); it++) { uint64_t i = it->first; //check for htlc @@ -3034,7 +3034,7 @@ namespace tools remove_transfer_from_amount_gindex_map(i); ++transfers_detached; } - m_transfers.erase(it, m_transfers.end()); + m_transfers.erase(it_start, m_transfers.end()); } } @@ -4458,10 +4458,10 @@ namespace tools return m_transfer_history.size(); } //---------------------------------------------------------------------------------------------------- - //uint64_t wallet2::get_transfer_entries_count() - //{ - // return m_transfers.size(); - //} + uint64_t wallet2::get_transfer_entries_count() + { + return m_transfers.size(); + } //---------------------------------------------------------------------------------------------------- template diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index b084b7fa..58f119e9 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -401,7 +401,7 @@ namespace tools void get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs = false, bool start_from_end = true); bool is_defragmentation_transaction(const wallet_public::wallet_transfer_info& wti); uint64_t get_recent_transfers_total_count(); - //uint64_t get_transfer_entries_count(); + uint64_t get_transfer_entries_count(); void get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs = false); void init(const std::string& daemon_address = "http://localhost:8080"); bool deinit(); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 750b0474..09092b43 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -2172,12 +2172,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 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(); } diff --git a/tests/core_tests/escrow_wallet_tests.cpp b/tests/core_tests/escrow_wallet_tests.cpp index b4bfaca3..ea32cfd1 100644 --- a/tests/core_tests/escrow_wallet_tests.cpp +++ b/tests/core_tests/escrow_wallet_tests.cpp @@ -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 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 transfers; + tools::transfer_container transfers; alice_wlt->get_transfers(transfers); CHECK_AND_ASSERT_MES(transfers.size() == 1, false, "Incorrect transfers size: " << transfers.size()); diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 94a938d2..afe029e8 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -533,7 +533,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{}; @@ -692,15 +692,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; } } diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index 2801b1fc..ef4f0c34 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -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 transfers; + tools::transfer_container transfers; std::vector unconfirmed_transfers; alice_wlt->scan_tx_pool(stub);