1
0
Fork 0
forked from lthn/blockchain

all tests compilation fixed(still a lot of broken tests)

This commit is contained in:
cryptozoidberg 2023-06-13 23:06:55 +02:00
parent c48f840f68
commit b744dfb79b
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
9 changed files with 54 additions and 26 deletions

View file

@ -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)

View file

@ -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<tools::wallet2::transfer_details> 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<tools::wallet2::expiration_entry_info>& 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;
}

View file

@ -724,7 +724,7 @@ bool make_tx_multisig_to_key(const currency::transaction& source_tx,
const std::vector<currency::attachment_v>& attachments = empty_attachment,
const std::vector<currency::extra_v>& 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<tools::wallet2> wallet, uint64_t expected_total,
bool print_transfers = false,

View file

@ -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<currency::wallet_out_info>& 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<currency::wallet_out_info>& 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;
}
}

View file

@ -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());

View file

@ -235,7 +235,7 @@ bool hard_fork_2_tx_payer_in_wallet::c1(currency::core& c, size_t ev_index, cons
std::shared_ptr<wlt_lambda_on_transfer2_wrapper> l2(new wlt_lambda_on_transfer2_wrapper(
[&](const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& 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<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[&](const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& 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<wlt_lambda_on_transfer2_wrapper> l2(new wlt_lambda_on_transfer2_wrapper(
[&](const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& 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");

View file

@ -116,12 +116,12 @@ bool test_transaction_generation_and_ring_signature()
std::vector<wallet_out_info> 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;

View file

@ -1833,7 +1833,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_
std::shared_ptr<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[biggest_alias_reward](const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& 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<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[&callback_is_ok](const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& 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<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[&](const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& 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)

View file

@ -49,7 +49,7 @@ protected:
};
const tools::wallet_public::asset_balance_entry get_native_balance_entry(const std::list<tools::wallet_public::asset_balance_entry>& balances)
inline const tools::wallet_public::asset_balance_entry get_native_balance_entry(const std::list<tools::wallet_public::asset_balance_entry>& balances)
{
for (const auto& b : balances)
{