From 91813968aa42214ac970fc29149e413170a46189 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 14 Feb 2024 02:02:13 +0400 Subject: [PATCH] fixes over multiasset tests to fix transfer ownership of asset --- contrib/epee/include/misc_language.h | 4 +++ src/currency_core/currency_format_utils.cpp | 14 +++++++-- src/wallet/wallet2.cpp | 2 +- tests/core_tests/multiassets_test.cpp | 32 +++++++++++---------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h index c1c0c794..5855d977 100644 --- a/contrib/epee/include/misc_language.h +++ b/contrib/epee/include/misc_language.h @@ -509,6 +509,10 @@ namespace misc_utils } } + void UNSUBSCRIBE_ALL() + { + m_callbacks.clear(); + } template void RAISE_DEBUG_EVENT(const param_t& p) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 71312151..9b250d89 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -172,7 +172,16 @@ namespace currency if (is_asset_emitting_transaction(tx, &ado)) { crypto::point_t asset_id_pt = crypto::c_point_0; - calculate_asset_id(ado.descriptor.owner, &asset_id_pt, nullptr); // TODO @#@# optimization: this expensive calculation should be done only once + if (ado.opt_asset_id) + { + //emmit on existing asset, we SHOULD not calculate asset_id, instead we use the one provided + //since the owner might have been changed since creation + asset_id_pt = crypto::point_t(*ado.opt_asset_id); + } + else + { + calculate_asset_id(ado.descriptor.owner, &asset_id_pt, nullptr); // TODO @#@# optimization: this expensive calculation should be done only once + } pseudo_outs_blinded_asset_ids.emplace_back(asset_id_pt); // additional ring member for asset emitting tx } @@ -2711,7 +2720,8 @@ namespace currency else { //generate signature by wallet account - crypto::generate_schnorr_sig(tx_prefix_hash, ftp.ado_current_asset_owner, sender_account_keys.spend_secret_key, aoop.gss); + r = crypto::generate_schnorr_sig(tx_prefix_hash, ftp.ado_current_asset_owner, sender_account_keys.spend_secret_key, aoop.gss); + CHECK_AND_ASSERT_MES(r, false, "Failed to sign ado proof"); } if (ftp.pevents_dispatcher) ftp.pevents_dispatcher->RAISE_DEBUG_EVENT(wde_construct_tx_after_asset_ownership_proof_generated{ &aoop }); tx.proofs.emplace_back(aoop); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c35db921..257646b9 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -916,7 +916,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t //check if there are asset_registration that belong to this wallet const asset_descriptor_operation* pado = get_type_in_variant_container(tx.extra); - if (ptc.employed_entries.receive.size() || ptc.employed_entries.spent.size() || (pado && pado->descriptor.owner == m_account.get_public_address().spend_public_key)) + if (pado && (ptc.employed_entries.receive.size() || ptc.employed_entries.spent.size() || pado->descriptor.owner == m_account.get_public_address().spend_public_key)) { //check if there are asset_registration that belong to this wallet process_ado_in_new_transaction(*pado, ptc); diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 1f5bbe5a..f0b96e6e 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -38,8 +38,8 @@ bool multiassets_basic_test::generate(std::vector& events) con DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks //TODO: Need to make sure REWIND_BLOCKS_N and other coretests codebase are capable of following hardfork4 rules //in this test hardfork4 moment moved to runtime section - REWIND_BLOCKS_N_WITH_TIME(events, blk_2_inital, blk_0, alice_acc, 2); - REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_2_inital, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); + //REWIND_BLOCKS_N_WITH_TIME(events, blk_2_inital, blk_0, alice_acc, 2); + REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); DO_CALLBACK(events, "c1"); @@ -133,7 +133,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v //test update function asset_info.meta_info = "{\"some\": \"info\"}"; miner_wlt->update_asset(asset_id, asset_info, tx); - r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, 2); + r = mine_next_pow_blocks_in_playtime(alice_wlt->get_account().get_public_address(), c, 2); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); asset_descriptor_base asset_info2 = AUTO_VAL_INIT(asset_info2); @@ -192,7 +192,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v c.get_tx_pool().purge_transactions(); miner_wlt->refresh(); - miner_wlt->get_debug_events_dispatcher().UNSUBSCRIBE_DEBUG_EVENT(); + miner_wlt->get_debug_events_dispatcher().UNSUBSCRIBE_ALL(); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count()); @@ -239,17 +239,17 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v // check update_asset() with modified 'owner' - r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info); - CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info"); + //r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info); + //CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info"); - asset_info.owner = currency::keypair::generate().pub; - miner_wlt->update_asset(asset_id, asset_info, tx); - CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(miner_wlt->get_account().get_public_address(), c); - CHECK_AND_ASSERT_MES(!r, false, "block with a bad tx was unexpectedly mined"); - CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count()); // make sure tx was not confirmed - c.get_tx_pool().purge_transactions(); - miner_wlt->refresh(); + //asset_info.owner = currency::keypair::generate().pub; + //miner_wlt->update_asset(asset_id, asset_info, tx); + //CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count()); + //r = mine_next_pow_block_in_playtime(miner_wlt->get_account().get_public_address(), c); + //CHECK_AND_ASSERT_MES(!r, false, "block with a bad tx was unexpectedly mined"); + //CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count()); // make sure tx was not confirmed + //c.get_tx_pool().purge_transactions(); + //miner_wlt->refresh(); // check emmit_asset() with modified 'current_supply' @@ -268,13 +268,14 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v //------------------- tests that trying to break stuff ------------------- //test burn that burns more than tx has - miner_wlt->get_debug_events_dispatcher().UNSUBSCRIBE_DEBUG_EVENT(); + miner_wlt->get_debug_events_dispatcher().UNSUBSCRIBE_ALL(); miner_wlt->get_debug_events_dispatcher().SUBSCIRBE_DEBUG_EVENT([&](const wde_construct_tx_handle_asset_descriptor_operation_before_burn& o) { o.pado->descriptor.current_supply -= 1000000; }); + miner_wlt->burn_asset(asset_id, 10000000000000, tx); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count()); r = mine_next_pow_block_in_playtime(miner_wlt->get_account().get_public_address(), c); @@ -282,6 +283,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count()); // make sure tx was not confirmed c.get_tx_pool().purge_transactions(); miner_wlt->refresh(); + miner_wlt->get_debug_events_dispatcher().UNSUBSCRIBE_ALL(); // miner_wlt->transfer_asset_ownership(asset_id, alice_wlt->get_account().get_public_address().spend_public_key, tx);