diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 6cab65ef..c0b73f7f 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -814,6 +814,17 @@ namespace currency return boost::apply_visitor(input_amount_getter(), v); } //--------------------------------------------------------------- + struct output_amount_getter : public boost::static_visitor + { + template + uint64_t operator()(const out_t&) const { return 0; } + uint64_t operator()(const tx_out_bare& ob) const { return ob.amount; } + }; + inline uint64_t get_amount_from_variant(const tx_out_v& out_v) + { + return boost::apply_visitor(output_amount_getter(), out_v); + } + //--------------------------------------------------------------- inline const tx_out_bare& get_tx_out_bare_from_out_v(const tx_out_v& o) { //this function will throw if type is not matching diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index f100e910..eaeba0a4 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -577,8 +577,9 @@ bool test_generator::build_outputs_indext_for_chain(const blockchain_vector& blo std::vector& coinbase_outs = txs_outs[currency::get_transaction_hash(blocks[h]->b.miner_tx)]; for (size_t out_i = 0; out_i != blocks[h]->b.miner_tx.vout.size(); out_i++) { - coinbase_outs.push_back(index[boost::get(blocks[h]->b.miner_tx.vout[out_i]).amount].size()); - index[boost::get(blocks[h]->b.miner_tx.vout[out_i]).amount].push_back(std::tuple(h, 0, out_i)); + uint64_t amount = get_amount_from_variant(blocks[h]->b.miner_tx.vout[out_i]); + coinbase_outs.push_back(index[amount].size()); + index[amount].push_back(std::tuple(h, 0, out_i)); } for (size_t tx_index = 0; tx_index != blocks[h]->m_transactions.size(); tx_index++) @@ -586,8 +587,9 @@ bool test_generator::build_outputs_indext_for_chain(const blockchain_vector& blo std::vector& tx_outs_indx = txs_outs[currency::get_transaction_hash(blocks[h]->m_transactions[tx_index])]; for (size_t out_i = 0; out_i != blocks[h]->m_transactions[tx_index].vout.size(); out_i++) { - tx_outs_indx.push_back(index[boost::get(blocks[h]->m_transactions[tx_index].vout[out_i]).amount].size()); - index[boost::get(blocks[h]->m_transactions[tx_index].vout[out_i]).amount].push_back(std::tuple(h, tx_index + 1, out_i)); + uint64_t amount = get_amount_from_variant(blocks[h]->m_transactions[tx_index].vout[out_i]); + tx_outs_indx.push_back(index[amount].size()); + index[amount].push_back(std::tuple(h, tx_index + 1, out_i)); } } } diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 8a1e145f..b94f1d1f 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -106,8 +106,9 @@ bool generate_and_play(const char* const genclass_name) { std::vector events; bool generated = false; - bool result = true; - std::cout << ENDL << concolor::bright_white << "#TEST# " << genclass_name << concolor::normal << ENDL << ENDL; + bool result = false; + std::cout << ENDL << concolor::bright_white << "#TEST# >>>> " << genclass_name << " <<<<" << ENDL << ENDL; + LOG_PRINT2("get_object_blobsize.log", "#TEST# " << genclass_name, LOG_LEVEL_3); if (!clean_data_directory()) @@ -118,29 +119,36 @@ bool generate_and_play(const char* const genclass_name) genclass g; try { - generated = g.generate(events);; + generated = g.generate(events); + if (generated) + { + std::cout << concolor::bright_white << std::string(100, '=') << std::endl << + "#TEST# >>>> " << genclass_name << " <<<< start replaying events" << std::endl << + std::string(100, '=') << concolor::normal << std::endl; + + result = do_replay_events(events, g); + } } catch (const std::exception& ex) { - LOG_ERROR(genclass_name << " generation failed: what=" << ex.what()); + LOG_ERROR("got an exception during " << genclass_name << (generated ? " replaying: " : " generation: ") << ex.what()); } catch (...) { - LOG_ERROR(genclass_name << " generation failed: generic exception"); + LOG_ERROR("got an unknown exception during " << genclass_name << (generated ? " replaying" : " generation")); } - std::cout << concolor::bright_white << std::string(100, '=') << std::endl << - "#TEST# >>>> " << genclass_name << " <<<< start replaying events" << std::endl << - std::string(100, '=') << concolor::normal << std::endl; - - if (generated && do_replay_events(events, g)) + if (result) { - std::cout << concolor::green << "#TEST# Succeeded " << genclass_name << concolor::normal << std::endl; + std::cout << concolor::green << std::string(100, '=') << std::endl << + "#TEST# >>>> " << genclass_name << " <<<< Succeeded" << std::endl << + std::string(100, '=') << concolor::normal << std::endl; } else { - std::cout << concolor::magenta << "#TEST# Failed " << genclass_name << concolor::normal << std::endl; - LOG_PRINT_RED_L0("#TEST# Failed " << genclass_name); + std::cout << concolor::red << std::string(100, '=') << std::endl << + "#TEST# >>>> " << genclass_name << " <<<< FAILED" << std::endl << + std::string(100, '=') << concolor::normal << std::endl; result = false; } std::cout << std::endl; diff --git a/tests/core_tests/zarcanum_test.cpp b/tests/core_tests/zarcanum_test.cpp index 571ec459..250c5a85 100644 --- a/tests/core_tests/zarcanum_test.cpp +++ b/tests/core_tests/zarcanum_test.cpp @@ -248,22 +248,20 @@ bool zarcanum_pos_block_math::generate(std::vector& events) co 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); + m_alice_amount = MK_TEST_COINS(1); + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); DO_CALLBACK(events, "configure_core"); // necessary to set m_hardforks REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); - // - // before hardfork 1 - // - std::vector sources; std::vector destinations; - CHECK_AND_ASSERT_MES(fill_tx_sources_and_destinations(events, blk_0r, miner_acc, alice_acc, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations), false, ""); + CHECK_AND_ASSERT_MES(fill_tx_sources_and_destinations(events, blk_0r, miner_acc, alice_acc, m_alice_amount, TESTS_DEFAULT_FEE, 0, sources, destinations), false, ""); std::vector extra; transaction tx_0 = AUTO_VAL_INIT(tx_0); crypto::secret_key tx_sec_key; - r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_0, get_tx_version_from_events(events), tx_sec_key, 0 /* unlock time 1 is zero and thus will not be set */); + r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_0, get_tx_version_from_events(events), tx_sec_key, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); //DO_CALLBACK(events, "mark_invalid_tx"); events.push_back(tx_0); @@ -274,14 +272,19 @@ bool zarcanum_pos_block_math::generate(std::vector& events) co DO_CALLBACK(events, "c1"); + CREATE_TEST_WALLET(alice_wlt, alice_acc, blk_0); + REFRESH_TEST_WALLET_AT_GEN_TIME(events, alice_wlt, blk_1r, 2 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 4); + CHECK_TEST_WALLET_BALANCE_AT_GEN_TIME(alice_wlt, m_alice_amount); + return true; } bool zarcanum_pos_block_math::c1(currency::core& c, size_t ev_index, const std::vector& events) { std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); + alice_wlt->refresh(); - CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", MK_TEST_COINS(1), 0, MK_TEST_COINS(1), 0, 0), false, ""); + CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", m_alice_amount, 0, MK_TEST_COINS(1), 0, 0), false, ""); return true; } diff --git a/tests/core_tests/zarcanum_test.h b/tests/core_tests/zarcanum_test.h index 56e025f1..0e717006 100644 --- a/tests/core_tests/zarcanum_test.h +++ b/tests/core_tests/zarcanum_test.h @@ -25,5 +25,7 @@ struct zarcanum_pos_block_math : public wallet_test zarcanum_pos_block_math(); bool generate(std::vector& events) const; bool c1(currency::core& c, size_t ev_index, const std::vector& events); + + mutable uint64_t m_alice_amount = 0; };