From 62af1716afcb68d0e06c800c8d6f8d0c36f2a074 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 11 Sep 2019 13:38:04 +0300 Subject: [PATCH] tests fixes: coretests/random_state_manupulation_test functional_tests/core_concurrency_test unit_tests/db_accessor_tests.median_db_cache_test --- tests/core_tests/chaingen.cpp | 74 ++++++++++--------- tests/core_tests/random_helper.cpp | 2 +- .../core_concurrency_test.cpp | 2 +- tests/unit_tests/db_accessors.cpp | 8 +- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index b03d2b9b..bc10214f 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -4,6 +4,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#define USE_INSECURE_RANDOM_RPNG_ROUTINES // turns on pseudorandom number generator manupulations for tests + #include #include #include @@ -1030,44 +1032,46 @@ namespace bool init_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const std::vector& blockchain, const map_hash2tx_t& mtx, const currency::account_keys& acc_keys) { - for(const block& blk : blockchain) + for (const block& blk : blockchain) + { + volatile uint64_t height = get_block_height(blk); + + std::vector vtx; + vtx.push_back(&blk.miner_tx); + + for (const crypto::hash &h : blk.tx_hashes) { - std::vector vtx; - vtx.push_back(&blk.miner_tx); - - for(const crypto::hash &h : blk.tx_hashes) - { - const map_hash2tx_t::const_iterator cit = mtx.find(h); - CHECK_AND_ASSERT_MES(cit != mtx.end(), false, "block at height " << get_block_height(blk) << " contains a reference to unknown tx " << h); - vtx.push_back(cit->second); - } - - for (size_t i = 0; i < vtx.size(); i++) - { - const transaction &tx = *vtx[i]; - crypto::key_derivation derivation; - bool r = generate_key_derivation(get_tx_pub_key_from_extra(tx), acc_keys.m_view_secret_key, derivation); - CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed"); - - for (size_t j = 0; j < tx.vout.size(); ++j) - { - const tx_out &out = tx.vout[j]; - output_index oi(out.target, out.amount, boost::get(*blk.miner_tx.vin.begin()).height, i, j, &blk, vtx[i]); - - if (out.target.type() == typeid(txout_to_key)) - { - outs[out.amount].push_back(oi); - size_t tx_global_idx = outs[out.amount].size() - 1; - outs[out.amount][tx_global_idx].idx = tx_global_idx; - // Is out to me? - if (is_out_to_acc(acc_keys, boost::get(out.target), derivation, j)) - outs_mine[out.amount].push_back(tx_global_idx); - } - } - } + const map_hash2tx_t::const_iterator cit = mtx.find(h); + CHECK_AND_ASSERT_MES(cit != mtx.end(), false, "block at height " << get_block_height(blk) << " contains a reference to unknown tx " << h); + vtx.push_back(cit->second); } - return true; + for (size_t i = 0; i < vtx.size(); i++) + { + const transaction &tx = *vtx[i]; + crypto::key_derivation derivation; + bool r = generate_key_derivation(get_tx_pub_key_from_extra(tx), acc_keys.m_view_secret_key, derivation); + CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed"); + + for (size_t j = 0; j < tx.vout.size(); ++j) + { + const tx_out &out = tx.vout[j]; + output_index oi(out.target, out.amount, boost::get(*blk.miner_tx.vin.begin()).height, i, j, &blk, vtx[i]); + + if (out.target.type() == typeid(txout_to_key)) + { + outs[out.amount].push_back(oi); + size_t tx_global_idx = outs[out.amount].size() - 1; + outs[out.amount][tx_global_idx].idx = tx_global_idx; + // Is out to me? + if (is_out_to_acc(acc_keys, boost::get(out.target), derivation, j)) + outs_mine[out.amount].push_back(tx_global_idx); + } + } + } + } + + return true; } bool init_spent_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const std::vector& blockchain, const map_hash2tx_t& mtx, const currency::account_keys& from) diff --git a/tests/core_tests/random_helper.cpp b/tests/core_tests/random_helper.cpp index 6f1f7396..eac32896 100644 --- a/tests/core_tests/random_helper.cpp +++ b/tests/core_tests/random_helper.cpp @@ -60,7 +60,7 @@ bool random_state_manupulation_test() // NOTE: If the test fails, it's most likely that random state permutation procedure was changed OR the state can't be correctly stored/loaded. static const uint64_t my_own_random_seed = 4669201609102990671; - static const char* my_random_str = "18b79ebb56744e9bafa462631c6f7d760af2b788"; + static const char* my_random_str = "760af2b78894c6a441731e2b354011da6ac98ddc"; static const size_t rnd_buf_len = 20; uint64_t first_random_after_state_saved = 0; diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 6da67324..dbd48447 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -121,7 +121,7 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_ { const transaction& tx = boost::get(*it); uint64_t max_used_block_height = 0; - r = bcs.check_tx_inputs(tx, get_transaction_hash(tx), &max_used_block_height); + r = bcs.check_tx_inputs(tx, get_transaction_hash(tx), max_used_block_height); if (r && max_used_block_height <= prev_block.height) txs.push_back(&tx); // filter out tx that are using too recent outputs -- yep, some txs will be dropped forever } diff --git a/tests/unit_tests/db_accessors.cpp b/tests/unit_tests/db_accessors.cpp index 826eb0a6..c2be6870 100644 --- a/tests/unit_tests/db_accessors.cpp +++ b/tests/unit_tests/db_accessors.cpp @@ -1,5 +1,10 @@ +// Copyright (c) 2019 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#define USE_INSECURE_RANDOM_RPNG_ROUTINES // turns on random manupulation for tests + #include "gtest/gtest.h" #include "currency_core/currency_format_utils.h" #include "common/db_abstract_accessor.h" @@ -8,7 +13,6 @@ #include "common/util.h" #include "misc_log_ex.h" #include "crypto/crypto.h" -#include "../core_tests/random_helper.h" #include "serialization/serialization.h" #include "file_io_utils.h" @@ -311,7 +315,7 @@ struct bcs_stub_t TEST(db_accessor_tests, median_db_cache_test) { - random_state_test_restorer::reset_random(); // make this test deterministic (the same crypto::rand() sequence) + crypto::random_prng_initialize_with_seed(0); // make this test deterministic (the same crypto::rand() sequence) epee::shared_recursive_mutex m_rw_lock; tools::db::basic_db_accessor m_db(std::shared_ptr(new tools::db::lmdb_db_backend), m_rw_lock);