diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f0cfa602..90d4e988 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4879,7 +4879,8 @@ bool wallet2::check_htlc_redeemed(const crypto::hash& htlc_tx_id, std::string& o } return false; } -bool wallet2::create_ionic_swap_proposal(uint64_t wallet_id, const view::ionic_swap_proposal_info& proposal_details, const currency::account_public_address& destination_addr) +//---------------------------------------------------------------------------------------------------- +bool wallet2::create_ionic_swap_proposal(const view::ionic_swap_proposal_info& proposal_details, const currency::account_public_address& destination_addr) { crypto::secret_key one_time_key = AUTO_VAL_INIT(one_time_key); std::vector selected_transfers_for_template; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 49e430b7..ddb69e2e 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -923,7 +923,7 @@ namespace tools bool check_htlc_redeemed(const crypto::hash& htlc_tx_id, std::string& origin, crypto::hash& redeem_tx_id); // ionic swaps: - bool create_ionic_swap_proposal(uint64_t wallet_id, const view::ionic_swap_proposal_info& proposal, const currency::account_public_address& destination_addr); + bool create_ionic_swap_proposal(const view::ionic_swap_proposal_info& proposal, const currency::account_public_address& destination_addr, transaction& tx_template); bool build_ionic_swap_template(const view::ionic_swap_proposal_info& proposal_detais, const currency::account_public_address& destination_addr, currency::transaction& template_tx, std::vector& selected_transfers_for_template, diff --git a/tests/core_tests/ionic_swap_tests.cpp b/tests/core_tests/ionic_swap_tests.cpp index a899ca44..509badd8 100644 --- a/tests/core_tests/ionic_swap_tests.cpp +++ b/tests/core_tests/ionic_swap_tests.cpp @@ -10,6 +10,11 @@ #include "random_helper.h" #include "tx_builder.h" +#define AMOUNT_TO_TRANSFER_MULTIASSETS_BASIC (TESTS_DEFAULT_FEE) + +#define AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC 500000000000000000 + + ionic_swap_basic_test::ionic_swap_basic_test() { @@ -22,7 +27,7 @@ ionic_swap_basic_test::ionic_swap_basic_test() m_hardforks.set_hardfork_height(4, 2); } -bool zarcanum_basic_test::generate(std::vector& events) const +bool ionic_swap_basic_test::generate(std::vector& events) const { uint64_t ts = test_core_time::get_time(); m_accounts.resize(TOTAL_ACCS_COUNT); @@ -44,12 +49,85 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect { bool r = false; std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX); - std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); - std::shared_ptr bob_wlt = init_playtime_test_wallet(events, c, BOB_ACC_IDX); + miner_wlt->get_account().set_createtime(0); + + //std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); + //std::shared_ptr bob_wlt = init_playtime_test_wallet(events, c, BOB_ACC_IDX); // check passing over the hardfork CHECK_AND_ASSERT_MES(!c.get_blockchain_storage().is_hardfork_active(ZANO_HARDFORK_04_ZARCANUM), false, "ZANO_HARDFORK_04_ZARCANUM is active"); + + account_base alice_acc; + alice_acc.generate(); + std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, alice_acc); + alice_wlt->get_account().set_createtime(0); + miner_wlt->refresh(); + + asset_descriptor_base adb = AUTO_VAL_INIT(adb); + adb.total_max_supply = 1000000000000000000; //1M coins + adb.full_name = "Test coins"; + adb.ticker = "TCT"; + adb.decimal_point = 12; + + std::vector destinations(2); + destinations[0].addr.push_back(miner_wlt->get_account().get_public_address()); + destinations[0].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; + destinations[0].asset_id = currency::ffff_hash; + destinations[1].addr.push_back(alice_wlt->get_account().get_public_address()); + destinations[1].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; + destinations[1].asset_id = currency::ffff_hash; + + LOG_PRINT_MAGENTA("destinations[0].asset_id:" << destinations[0].asset_id, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("destinations[1].asset_id:" << destinations[1].asset_id, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("currency::ffff_hash:" << currency::ffff_hash, LOG_LEVEL_0); + + currency::transaction tx = AUTO_VAL_INIT(tx); + crypto::hash asset_id = currency::null_hash; + miner_wlt->publish_new_asset(adb, destinations, tx, asset_id); + LOG_PRINT_L0("Published new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); + + r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + + miner_wlt->refresh(); + alice_wlt->refresh(); + uint64_t mined = 0; + std::unordered_map balances; + miner_wlt->balance(balances, mined); + + auto it_asset = balances.find(asset_id); + auto it_native = balances.find(currency::null_hash); + + + CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native->second.total == uint64_t(17517226)*COIN, false, "Failed to find needed asset in result balances"); + + + balances.clear(); + alice_wlt->balance(balances, mined); + + it_asset = balances.find(asset_id); + it_native = balances.find(currency::null_hash); + + CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native == balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); + + //alice_wlt want to trade with miner_wlt, to exchange 10.0 TCT to 1.0 ZANO + view::ionic_swap_proposal_info proposal_details = AUTO_VAL_INIT(proposal_details); + proposal_details.expiration_time = alice_wlt->get_core_runtime_config().get_core_time() + 10 * 60; + proposal_details.fee = TESTS_DEFAULT_FEE; + proposal_details.mixins = 10; + proposal_details.from.push_back(view::asset_funds{ asset_id , 10 * COIN}); + proposal_details.to.push_back(view::asset_funds{ currency::null_pkey , 1 * COIN }); + + currency::transaction tx_template = AUTO_VAL_INIT(tx_template); + alice_wlt->create_ionic_swap_proposal(proposal_details, miner_wlt->get_account().get_public_address(), tx_template); + + return true; }