From f0d5bc94cd28d3bebd49f90370d1b11cb6d48417 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 9 Mar 2023 19:49:40 +0100 Subject: [PATCH] Core tests for basic ionic swaps scenario: inital code --- src/wallet/wallet2.cpp | 6 ++- tests/core_tests/ionic_swap_tests.cpp | 55 +++++++++++++++++++++++++++ tests/core_tests/ionic_swap_tests.h | 15 ++++++++ tests/core_tests/zarcanum_test.cpp | 1 - tests/core_tests/zarcanum_test.h | 1 - 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 tests/core_tests/ionic_swap_tests.cpp create mode 100644 tests/core_tests/ionic_swap_tests.h diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 13db244b..f0cfa602 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5069,7 +5069,6 @@ bool wallet2::accept_ionic_swap_proposal(std::string&raw_tx_template, currency:: throw; } - return true; } //---------------------------------------------------------------------------------------------------- @@ -6056,7 +6055,10 @@ void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx if (ctp.flags & TX_FLAG_SIGNATURE_MODE_SEPARATE && tx_for_mode_separate.vout.size() ) { WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(get_tx_flags(tx_for_mode_separate) & TX_FLAG_SIGNATURE_MODE_SEPARATE, "tx_param.flags differs from tx.flags"); - needed_money_map[currency::null_hash].needed_amount += (currency::get_outs_money_amount(tx_for_mode_separate) - get_inputs_money_amount(tx_for_mode_separate)); + for (const auto& el : mode_separatemode_separate.proposal.to) + { + needed_money_map[el.asset_id].needed_amount += el.amount; + } } TIME_MEASURE_FINISH_MS(get_needed_money_time); diff --git a/tests/core_tests/ionic_swap_tests.cpp b/tests/core_tests/ionic_swap_tests.cpp new file mode 100644 index 00000000..a899ca44 --- /dev/null +++ b/tests/core_tests/ionic_swap_tests.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2014-2022 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chaingen.h" +#include "ionic_swap_tests.h" +#include "wallet_test_core_proxy.h" + +#include "random_helper.h" +#include "tx_builder.h" + + +ionic_swap_basic_test::ionic_swap_basic_test() +{ + REGISTER_CALLBACK_METHOD(ionic_swap_basic_test, configure_core); + REGISTER_CALLBACK_METHOD(ionic_swap_basic_test, c1); + + m_hardforks.set_hardfork_height(1, 1); + m_hardforks.set_hardfork_height(2, 1); + m_hardforks.set_hardfork_height(3, 1); + m_hardforks.set_hardfork_height(4, 2); +} + +bool zarcanum_basic_test::generate(std::vector& events) const +{ + uint64_t ts = test_core_time::get_time(); + m_accounts.resize(TOTAL_ACCS_COUNT); + account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts); + account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts); + account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts); + //account_base& carol_acc = m_accounts[CAROL_ACC_IDX]; carol_acc.generate(); carol_acc.set_createtime(ts); + + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); + DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks + REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); + + DO_CALLBACK(events, "c1"); + + return true; +} + +bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + 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); + + // 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"); + + return true; +} + diff --git a/tests/core_tests/ionic_swap_tests.h b/tests/core_tests/ionic_swap_tests.h new file mode 100644 index 00000000..389191ae --- /dev/null +++ b/tests/core_tests/ionic_swap_tests.h @@ -0,0 +1,15 @@ +// Copyright (c) 2014-2022 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#pragma once +#include "chaingen.h" +#include "wallet_tests_basic.h" + + +struct ionic_swap_basic_test : public wallet_test +{ + ionic_swap_basic_test(); + bool generate(std::vector& events) const; + bool c1(currency::core& c, size_t ev_index, const std::vector& events); +}; + diff --git a/tests/core_tests/zarcanum_test.cpp b/tests/core_tests/zarcanum_test.cpp index 1d04d39a..3f1209af 100644 --- a/tests/core_tests/zarcanum_test.cpp +++ b/tests/core_tests/zarcanum_test.cpp @@ -1,5 +1,4 @@ // Copyright (c) 2014-2022 Zano Project -// Copyright (c) 2014-2018 The Louisdor Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/tests/core_tests/zarcanum_test.h b/tests/core_tests/zarcanum_test.h index 6b7e575b..4afa4eea 100644 --- a/tests/core_tests/zarcanum_test.h +++ b/tests/core_tests/zarcanum_test.h @@ -1,5 +1,4 @@ // Copyright (c) 2014-2022 Zano Project -// Copyright (c) 2014-2018 The Louisdor Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #pragma once