coretests: check_ionic_swap_tx_outs added, some improvements

This commit is contained in:
sowle 2023-10-19 14:37:57 +02:00
parent 146bf51021
commit 43b41fec3d
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 66 additions and 6 deletions

View file

@ -359,6 +359,8 @@ namespace currency
bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key, crypto::key_derivation& derivation);
bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key);
bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::secret_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index = 0);
uint16_t get_derivation_hint(const crypto::key_derivation& derivation);
tx_derivation_hint make_tx_derivation_hint_from_uint16(uint16_t hint);
std::string short_hash_str(const crypto::hash& h);
bool is_mixattr_applicable_for_fake_outs_counter(uint8_t mix_attr, uint64_t fake_attr_count);

View file

@ -5427,7 +5427,7 @@ bool wallet2::build_ionic_swap_template(const wallet_public::ionic_swap_proposal
return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info)
bool wallet2::get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const
{
wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal);
bool r = t_unserializable_object_from_blob(proposal, raw_proposal);
@ -5435,13 +5435,13 @@ bool wallet2::get_ionic_swap_proposal_info(const std::string&raw_proposal, walle
return get_ionic_swap_proposal_info(proposal, proposal_info);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info)
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const
{
wallet_public::ionic_swap_proposal_context ionic_context = AUTO_VAL_INIT(ionic_context);
return get_ionic_swap_proposal_info(proposal, proposal_info, ionic_context);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context)
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context) const
{
const transaction& tx = proposal.tx_template;
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);

View file

@ -1026,9 +1026,9 @@ namespace tools
bool build_ionic_swap_template(const wallet_public::ionic_swap_proposal_info& proposal_detais, const currency::account_public_address& destination_addr,
wallet_public::ionic_swap_proposal& proposal,
std::vector<uint64_t>& selected_transfers_for_template);
bool get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info);
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info);
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context);
bool get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const;
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const;
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context) const;
bool accept_ionic_swap_proposal(const std::string& raw_proposal, currency::transaction& result_tx);
bool accept_ionic_swap_proposal(const wallet_public::ionic_swap_proposal& proposal, currency::transaction& result_tx);

View file

@ -10,6 +10,64 @@
#include "random_helper.h"
#include "tx_builder.h"
using namespace currency;
// Helpers
bool check_ionic_swap_tx_outs(const std::vector<currency::account_base>& accounts, const currency::transaction& tx, std::shared_ptr<const tools::wallet2> w, const tools::wallet_public::ionic_swap_proposal& proposal)
{
tools::mode_separate_context msc = AUTO_VAL_INIT(msc);
msc.tx_for_mode_separate = proposal.tx_template;
tools::wallet_public::ionic_swap_proposal_context ionic_context = AUTO_VAL_INIT(ionic_context);
bool r = w->get_ionic_swap_proposal_info(proposal, msc.proposal_info, ionic_context);
CHECK_AND_ASSERT_MES(r, false, "get_ionic_swap_proposal_info failed");
// decode all outputs amounts and asset_ids
std::vector<std::pair<uint64_t, crypto::public_key>> outs_amounts_and_asset_ids;
outs_amounts_and_asset_ids.resize(tx.vout.size());
//ionic_context.one_time_skey
const crypto::public_key& tx_pub_key = get_tx_pub_key_from_extra(tx);
for(size_t i = 0; i < tx.vout.size(); ++i)
{
VARIANT_SWITCH_BEGIN(tx.vout[i])
VARIANT_CASE_CONST(currency::tx_out_zarcanum, oz)
for(size_t k = 0; k < accounts.size(); ++k)
{
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);
bool r = crypto::generate_key_derivation(tx_pub_key, accounts[k].get_keys().view_secret_key, derivation);
CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed");
uint64_t decoded_amount = 0;
crypto::public_key decoded_asset_id{};
crypto::scalar_t amount_blinding_mask{};
crypto::scalar_t asset_id_blinding_mask{};
if (decode_output_amount_and_asset_id(oz, derivation, i, decoded_amount, decoded_asset_id, amount_blinding_mask, asset_id_blinding_mask))
{
outs_amounts_and_asset_ids[i] = std::make_pair(decoded_amount, decoded_asset_id);
break;
}
}
VARIANT_SWITCH_END()
}
static_assert(CURRENCY_TX_MIN_ALLOWED_OUTS >= 2);
const size_t expected_number_of_zero_amount_outputs = CURRENCY_TX_MIN_ALLOWED_OUTS - 2;
size_t zero_amount_outputs = 0;
for(auto& oaai : outs_amounts_and_asset_ids)
{
CHECK_AND_ASSERT_MES(oaai.second != null_pkey, false, "Not all outputs were decoded");
if (oaai.first == 0)
++zero_amount_outputs;
}
CHECK_AND_ASSERT_MES(zero_amount_outputs <= expected_number_of_zero_amount_outputs, false, "zero_amount_outputs: " << zero_amount_outputs << ", expected_number_of_zero_amount_outputs: " << expected_number_of_zero_amount_outputs);
return true;
}
//----------------------------------------------------------------------------------------------------
ionic_swap_basic_test::ionic_swap_basic_test()
{