1
0
Fork 0
forked from lthn/blockchain

tests fixes:

coretests/random_state_manupulation_test
functional_tests/core_concurrency_test
unit_tests/db_accessor_tests.median_db_cache_test
This commit is contained in:
sowle 2019-09-11 13:38:04 +03:00
parent d742e6ea2d
commit 62af1716af
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 47 additions and 39 deletions

View file

@ -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 <vector>
#include <iostream>
#include <sstream>
@ -1030,44 +1032,46 @@ namespace
bool init_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const std::vector<currency::block>& 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<const transaction*> vtx;
vtx.push_back(&blk.miner_tx);
for (const crypto::hash &h : blk.tx_hashes)
{
std::vector<const transaction*> 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<txin_gen>(*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<txout_to_key>(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<txin_gen>(*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<txout_to_key>(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<currency::block>& blockchain, const map_hash2tx_t& mtx, const currency::account_keys& from)

View file

@ -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;

View file

@ -121,7 +121,7 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_
{
const transaction& tx = boost::get<const currency::transaction>(*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
}

View file

@ -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 <algorithm>
#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<tools::db::i_db_backend>(new tools::db::lmdb_db_backend), m_rw_lock);