From b744dfb79b6c11464bebd2571d241e76a90915eb Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 13 Jun 2023 23:06:55 +0200 Subject: [PATCH] all tests compilation fixed(still a lot of broken tests) --- src/wallet/wallet_public_structs_defs.h | 18 ++++++++++++++++++ tests/core_tests/chaingen.cpp | 14 +------------- tests/core_tests/chaingen.h | 2 +- tests/core_tests/chaingen_helpers.h | 18 ++++++++++++++++++ tests/core_tests/escrow_wallet_tests.cpp | 4 ++-- tests/core_tests/hard_fork_2.cpp | 8 ++++---- tests/core_tests/transaction_tests.cpp | 4 ++-- tests/core_tests/wallet_tests.cpp | 10 +++++++--- tests/core_tests/wallet_tests_basic.h | 2 +- 9 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 23529d13..279fc41a 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -210,6 +210,24 @@ namespace wallet_public } return 0; } + uint64_t get_native_amount() const + { + for (const auto& st : subtransfers) + { + if (st.asset_id == currency::native_coin_asset_id ) + return st.amount; + } + return 0; + } + bool get_native_is_income() const + { + for (const auto& st : subtransfers) + { + if (st.asset_id == currency::native_coin_asset_id) + return st.is_income; + } + return false; + } uint64_t& get_native_income_amount() { for (auto& st : subtransfers) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 45b51919..1990ead4 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -2067,7 +2067,7 @@ bool make_tx_multisig_to_key(const currency::transaction& source_tx, return true; } -bool estimate_wallet_balance_blocked_for_escrow(const tools::wallet2& w, uint64_t& result, bool substruct_change_from_result /* = true */, uint64_t* p_change /* = nullptr */) +bool estimate_wallet_balance_blocked_for_escrow(const tools::wallet2& w, uint64_t& result) { std::deque transfers; w.get_transfers(transfers); @@ -2078,18 +2078,6 @@ bool estimate_wallet_balance_blocked_for_escrow(const tools::wallet2& w, uint64_ if (td.m_flags == (WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION)) result += td.amount(); } - if (substruct_change_from_result || p_change != nullptr) - { - const std::list& ee = w.get_expiration_entries(); - for (auto &e : ee) - { - CHECK_AND_ASSERT_MES(result >= e.change_amount, false, "wrong transfers: result: " << print_money(result) << " is expected to be NOT LESS than change_amount: " << print_money(e.change_amount)); - if (substruct_change_from_result) - result -= e.change_amount; - if (p_change != nullptr) - *p_change += e.change_amount; - } - } return true; } diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 936e422a..6ab7b76b 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -724,7 +724,7 @@ bool make_tx_multisig_to_key(const currency::transaction& source_tx, const std::vector& attachments = empty_attachment, const std::vector& extra = empty_extra); -bool estimate_wallet_balance_blocked_for_escrow(const tools::wallet2& w, uint64_t& result, bool substruct_change_from_result = true, uint64_t* p_change = nullptr); +bool estimate_wallet_balance_blocked_for_escrow(const tools::wallet2& w, uint64_t& result); bool check_wallet_balance_blocked_for_escrow(const tools::wallet2& w, const char* wallet_name, uint64_t expected_amount); bool refresh_wallet_and_check_balance(const char* intro_log_message, const char* wallet_name, std::shared_ptr wallet, uint64_t expected_total, bool print_transfers = false, diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index 82208abd..b984fde7 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -323,6 +323,7 @@ namespace currency //this lookup_acc_outs overload is mostly for backward compatibility for tests, ineffective from performance perspective, should not be used in wallet inline bool lookup_acc_outs(const currency::account_keys& acc, const currency::transaction& tx, std::vector& outs, uint64_t& sum_of_native_outs, crypto::key_derivation& derivation) { + outs.clear(); sum_of_native_outs = 0; bool res = currency::lookup_acc_outs(acc, tx, outs, derivation); for (const auto& o : outs) @@ -334,4 +335,21 @@ namespace currency } return res; } + + //this lookup_acc_outs overload is mostly for backward compatibility for tests, ineffective from performance perspective, should not be used in wallet + inline bool lookup_acc_outs(const currency::account_keys& acc, const currency::transaction& tx, const crypto::public_key& /*tx_onetime_pubkey*/, std::vector& outs, uint64_t& sum_of_native_outs, crypto::key_derivation& derivation) + { + sum_of_native_outs = 0; + bool res = currency::lookup_acc_outs(acc, tx, outs, derivation); + for (const auto& o : outs) + { + if (o.asset_id == currency::native_coin_asset_id) + { + sum_of_native_outs += o.amount; + } + } + return res; + } + + } diff --git a/tests/core_tests/escrow_wallet_tests.cpp b/tests/core_tests/escrow_wallet_tests.cpp index 49521201..472a2ab5 100644 --- a/tests/core_tests/escrow_wallet_tests.cpp +++ b/tests/core_tests/escrow_wallet_tests.cpp @@ -2601,7 +2601,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in crypto::hash contract_id = contracts.begin()->first; uint64_t alice_blocked_transfers_sum = 0; - CHECK_AND_ASSERT_MES(estimate_wallet_balance_blocked_for_escrow(*alice_wlt.get(), alice_blocked_transfers_sum, false), false, ""); + CHECK_AND_ASSERT_MES(estimate_wallet_balance_blocked_for_escrow(*alice_wlt.get(), alice_blocked_transfers_sum), false, ""); // mine a block, containing escrow proposal tx CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2622,7 +2622,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in bob_wlt->accept_proposal(contract_id, TESTS_DEFAULT_FEE); uint64_t bob_blocked_transfers_sum = 0; - CHECK_AND_ASSERT_MES(estimate_wallet_balance_blocked_for_escrow(*bob_wlt.get(), bob_blocked_transfers_sum, false), false, ""); + CHECK_AND_ASSERT_MES(estimate_wallet_balance_blocked_for_escrow(*bob_wlt.get(), bob_blocked_transfers_sum), false, ""); // mine a block containing contract acceptance CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index 3f5b3c83..92d2d130 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -235,7 +235,7 @@ bool hard_fork_2_tx_payer_in_wallet::c1(currency::core& c, size_t ev_index, cons std::shared_ptr l2(new wlt_lambda_on_transfer2_wrapper( [&](const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) -> bool { - CHECK_AND_ASSERT_THROW_MES(wti.amount == MK_TEST_COINS(2), "incorrect wti.amount = " << print_money_brief(wti.amount)); + CHECK_AND_ASSERT_THROW_MES(wti.get_native_amount() == MK_TEST_COINS(2), "incorrect wti.amount = " << print_money_brief(wti.get_native_amount())); CHECK_AND_ASSERT_THROW_MES(wti.show_sender, "show_sender is false"); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.size() == 1, "incorrect wti.remote_addresses.size() = " << wti.remote_addresses.size()); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.front() == m_accounts[MINER_ACC_IDX].get_public_address_str(), "wti.remote_addresses.front is incorrect"); @@ -368,7 +368,7 @@ bool hard_fork_2_tx_receiver_in_wallet::c1(currency::core& c, size_t ev_index, c std::shared_ptr l(new wlt_lambda_on_transfer2_wrapper( [&](const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) -> bool { - CHECK_AND_ASSERT_THROW_MES(!wti.is_income, "wti.is_income is " << wti.is_income); + CHECK_AND_ASSERT_THROW_MES(!wti.get_native_is_income(), "wti.is_income is " << wti.get_native_is_income()); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.size() == 2, "incorrect wti.remote_addresses.size() = " << wti.remote_addresses.size()); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.front() == m_accounts[MINER_ACC_IDX].get_public_address_str(), "wti.remote_addresses.front is incorrect"); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.back() == m_accounts[BOB_ACC_IDX].get_public_address_str(), "wti.remote_addresses.back is incorrect"); @@ -410,8 +410,8 @@ bool hard_fork_2_tx_receiver_in_wallet::c1(currency::core& c, size_t ev_index, c std::shared_ptr l2(new wlt_lambda_on_transfer2_wrapper( [&](const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) -> bool { - CHECK_AND_ASSERT_THROW_MES(!wti.is_income, "wti.is_income is " << wti.is_income); - CHECK_AND_ASSERT_THROW_MES(wti.amount == MK_TEST_COINS(4), "incorrect wti.amount = " << print_money_brief(wti.amount)); + CHECK_AND_ASSERT_THROW_MES(!wti.get_native_is_income(), "wti.is_income is " << wti.get_native_is_income()); + CHECK_AND_ASSERT_THROW_MES(wti.get_native_amount() == MK_TEST_COINS(4), "incorrect wti.amount = " << print_money_brief(wti.get_native_amount())); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.size() == 2, "incorrect wti.remote_addresses.size() = " << wti.remote_addresses.size()); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.front() == m_accounts[MINER_ACC_IDX].get_public_address_str(), "wti.remote_addresses.front is incorrect"); CHECK_AND_ASSERT_THROW_MES(wti.remote_addresses.back() == m_accounts[BOB_ACC_IDX].get_public_address_str(), "wti.remote_addresses.back is incorrect"); diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index 150ec14a..7ad10ec1 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -116,12 +116,12 @@ bool test_transaction_generation_and_ring_signature() std::vector outs; uint64_t money = 0; crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); - r = lookup_acc_outs(rv_acc.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), outs, money, derivation); + r = lookup_acc_outs(rv_acc.get_keys(), tx_rc1, outs, money, derivation); CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs"); CHECK_AND_ASSERT_MES(td.amount == money, false, "wrong money amount in new transaction"); money = 0; derivation = AUTO_VAL_INIT(derivation); - r = lookup_acc_outs(rv_acc2.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), outs, money, derivation); + r = lookup_acc_outs(rv_acc2.get_keys(), tx_rc1, outs, money, derivation); CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs"); CHECK_AND_ASSERT_MES(0 == money, false, "wrong money amount in new transaction"); return true; diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 306b01d0..b4540fcf 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -1833,7 +1833,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_ std::shared_ptr l(new wlt_lambda_on_transfer2_wrapper( [biggest_alias_reward](const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) -> bool { return std::count(wti.remote_aliases.begin(), wti.remote_aliases.end(), "minerminer") == 1 && - wti.amount == biggest_alias_reward; + wti.get_native_amount() == biggest_alias_reward; } )); alice_wlt->callback(l); @@ -3309,6 +3309,10 @@ bool wallet_unconfimed_tx_balance::c1(currency::core& c, size_t ev_index, const std::shared_ptr l(new wlt_lambda_on_transfer2_wrapper( [&callback_is_ok](const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) -> bool { + tools::wallet_public::asset_balance_entry abe = get_native_balance_entry(balances); + uint64_t balance = abe.total; + uint64_t unlocked_balance = abe.unlocked; + CHECK_AND_ASSERT_MES(balance == MK_TEST_COINS(70), false, "invalid balance: " << print_money_brief(balance)); CHECK_AND_ASSERT_MES(unlocked_balance == MK_TEST_COINS(50), false, "invalid unlocked_balance: " << print_money_brief(unlocked_balance)); CHECK_AND_ASSERT_MES(total_mined == 0, false, "invalid total_mined: " << print_money_brief(total_mined)); @@ -3458,7 +3462,7 @@ bool wallet_sending_to_integrated_address::c1(currency::core& c, size_t ev_index bool callback_succeded = false; std::shared_ptr l(new wlt_lambda_on_transfer2_wrapper( [&](const tools::wallet_public::wallet_transfer_info& wti, const std::list& balances, uint64_t total_mined) -> bool { - LOG_PRINT_YELLOW("on_transfer: " << print_money_brief(wti.amount) << " pid len: " << wti.payment_id.size() << " remote addr: " << (wti.remote_addresses.size() > 0 ? wti.remote_addresses[0] : ""), LOG_LEVEL_0); + LOG_PRINT_YELLOW("on_transfer: " << print_money_brief(wti.get_native_amount()) << " pid len: " << wti.payment_id.size() << " remote addr: " << (wti.remote_addresses.size() > 0 ? wti.remote_addresses[0] : ""), LOG_LEVEL_0); if (wti.payment_id.empty()) return true; // skip another outputs CHECK_AND_ASSERT_MES(wti.payment_id == payment_id, false, "incorrect payment id"); @@ -3669,7 +3673,7 @@ bool wallet_spend_form_auditable_and_track::c1(currency::core& c, size_t ev_inde r = false; bool r_comment = false; bob_wlt->enumerate_transfers_history([&](const tools::wallet_public::wallet_transfer_info& wti) { - if (wti.amount == MK_TEST_COINS(5)) + if (wti.get_native_amount() == MK_TEST_COINS(5)) { r_comment = (wti.comment == m_comment); if (!r_comment) diff --git a/tests/core_tests/wallet_tests_basic.h b/tests/core_tests/wallet_tests_basic.h index 6fc66a99..0329e0a2 100644 --- a/tests/core_tests/wallet_tests_basic.h +++ b/tests/core_tests/wallet_tests_basic.h @@ -49,7 +49,7 @@ protected: }; -const tools::wallet_public::asset_balance_entry get_native_balance_entry(const std::list& balances) +inline const tools::wallet_public::asset_balance_entry get_native_balance_entry(const std::list& balances) { for (const auto& b : balances) {