2019-03-05 16:05:34 -05:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
2014-07-23 09:03:52 -04:00
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <boost/archive/binary_oarchive.hpp>
|
|
|
|
#include <boost/archive/binary_iarchive.hpp>
|
|
|
|
#include <boost/program_options.hpp>
|
2018-11-20 08:40:51 -05:00
|
|
|
#include <boost/optional.hpp>
|
2014-03-03 17:07:58 -05:00
|
|
|
#include <boost/serialization/vector.hpp>
|
|
|
|
#include <boost/serialization/variant.hpp>
|
2018-11-20 08:40:51 -05:00
|
|
|
#include <boost/serialization/optional.hpp>
|
|
|
|
#include <boost/serialization/unordered_map.hpp>
|
|
|
|
#include <boost/functional/hash.hpp>
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
#include "include_base_utils.h"
|
|
|
|
#include "common/boost_serialization_helper.h"
|
|
|
|
#include "common/command_line.h"
|
|
|
|
|
2017-01-26 10:07:23 -05:00
|
|
|
#include "cryptonote_basic/account_boost_serialization.h"
|
|
|
|
#include "cryptonote_basic/cryptonote_basic.h"
|
|
|
|
#include "cryptonote_basic/cryptonote_basic_impl.h"
|
|
|
|
#include "cryptonote_basic/cryptonote_format_utils.h"
|
2014-03-03 17:07:58 -05:00
|
|
|
#include "cryptonote_core/cryptonote_core.h"
|
2017-01-26 10:07:23 -05:00
|
|
|
#include "cryptonote_basic/cryptonote_boost_serialization.h"
|
2014-03-03 17:07:58 -05:00
|
|
|
#include "misc_language.h"
|
|
|
|
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
|
|
|
#define MONERO_DEFAULT_LOG_CATEGORY "tests.core"
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct callback_entry
|
|
|
|
{
|
|
|
|
std::string callback_name;
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
FIELD(callback_name)
|
|
|
|
END_SERIALIZE()
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
template<class Archive>
|
|
|
|
void serialize(Archive & ar, const unsigned int /*version*/)
|
|
|
|
{
|
|
|
|
ar & callback_name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct serialized_object
|
|
|
|
{
|
|
|
|
serialized_object() { }
|
|
|
|
|
|
|
|
serialized_object(const cryptonote::blobdata& a_data)
|
|
|
|
: data(a_data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cryptonote::blobdata data;
|
|
|
|
BEGIN_SERIALIZE_OBJECT()
|
|
|
|
FIELD(data)
|
|
|
|
END_SERIALIZE()
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
template<class Archive>
|
|
|
|
void serialize(Archive & ar, const unsigned int /*version*/)
|
|
|
|
{
|
|
|
|
ar & data;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef serialized_object<cryptonote::block> serialized_block;
|
|
|
|
typedef serialized_object<cryptonote::transaction> serialized_transaction;
|
|
|
|
|
|
|
|
struct event_visitor_settings
|
|
|
|
{
|
|
|
|
int valid_mask;
|
|
|
|
bool txs_keeped_by_block;
|
|
|
|
|
|
|
|
enum settings
|
|
|
|
{
|
|
|
|
set_txs_keeped_by_block = 1 << 0
|
|
|
|
};
|
|
|
|
|
|
|
|
event_visitor_settings(int a_valid_mask = 0, bool a_txs_keeped_by_block = false)
|
|
|
|
: valid_mask(a_valid_mask)
|
|
|
|
, txs_keeped_by_block(a_txs_keeped_by_block)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
template<class Archive>
|
|
|
|
void serialize(Archive & ar, const unsigned int /*version*/)
|
|
|
|
{
|
|
|
|
ar & valid_mask;
|
|
|
|
ar & txs_keeped_by_block;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
typedef std::vector<std::pair<uint8_t, uint64_t>> v_hardforks_t;
|
|
|
|
struct event_replay_settings
|
|
|
|
{
|
|
|
|
boost::optional<v_hardforks_t> hard_forks;
|
|
|
|
|
|
|
|
event_replay_settings() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
template<class Archive>
|
|
|
|
void serialize(Archive & ar, const unsigned int /*version*/)
|
|
|
|
{
|
|
|
|
ar & hard_forks;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
VARIANT_TAG(binary_archive, callback_entry, 0xcb);
|
|
|
|
VARIANT_TAG(binary_archive, cryptonote::account_base, 0xcc);
|
|
|
|
VARIANT_TAG(binary_archive, serialized_block, 0xcd);
|
|
|
|
VARIANT_TAG(binary_archive, serialized_transaction, 0xce);
|
|
|
|
VARIANT_TAG(binary_archive, event_visitor_settings, 0xcf);
|
2018-11-20 08:40:51 -05:00
|
|
|
VARIANT_TAG(binary_archive, event_replay_settings, 0xda);
|
2014-03-03 17:07:58 -05:00
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
typedef boost::variant<cryptonote::block, cryptonote::transaction, std::vector<cryptonote::transaction>, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings, event_replay_settings> test_event_entry;
|
2014-03-03 17:07:58 -05:00
|
|
|
typedef std::unordered_map<crypto::hash, const cryptonote::transaction*> map_hash2tx_t;
|
|
|
|
|
|
|
|
class test_chain_unit_base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef boost::function<bool (cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)> verify_callback;
|
|
|
|
typedef std::map<std::string, verify_callback> callbacks_map;
|
|
|
|
|
|
|
|
void register_callback(const std::string& cb_name, verify_callback cb);
|
|
|
|
bool verify(const std::string& cb_name, cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events);
|
|
|
|
private:
|
|
|
|
callbacks_map m_callbacks;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class test_generator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct block_info
|
|
|
|
{
|
|
|
|
block_info()
|
|
|
|
: prev_id()
|
|
|
|
, already_generated_coins(0)
|
2018-07-18 17:24:53 -04:00
|
|
|
, block_weight(0)
|
2014-03-03 17:07:58 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:24:53 -04:00
|
|
|
block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_weight)
|
2014-03-03 17:07:58 -05:00
|
|
|
: prev_id(a_prev_id)
|
|
|
|
, already_generated_coins(an_already_generated_coins)
|
2018-07-18 17:24:53 -04:00
|
|
|
, block_weight(a_block_weight)
|
2014-03-03 17:07:58 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
crypto::hash prev_id;
|
|
|
|
uint64_t already_generated_coins;
|
2018-07-18 17:24:53 -04:00
|
|
|
size_t block_weight;
|
2018-11-20 08:40:51 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
template<class Archive>
|
|
|
|
void serialize(Archive & ar, const unsigned int /*version*/)
|
|
|
|
{
|
|
|
|
ar & prev_id;
|
|
|
|
ar & already_generated_coins;
|
|
|
|
ar & block_weight;
|
|
|
|
}
|
2014-03-03 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
enum block_fields
|
|
|
|
{
|
|
|
|
bf_none = 0,
|
|
|
|
bf_major_ver = 1 << 0,
|
|
|
|
bf_minor_ver = 1 << 1,
|
|
|
|
bf_timestamp = 1 << 2,
|
|
|
|
bf_prev_id = 1 << 3,
|
|
|
|
bf_miner_tx = 1 << 4,
|
|
|
|
bf_tx_hashes = 1 << 5,
|
2016-02-08 13:47:02 -05:00
|
|
|
bf_diffic = 1 << 6,
|
2016-06-27 13:56:19 -04:00
|
|
|
bf_max_outs = 1 << 7,
|
|
|
|
bf_hf_version= 1 << 8
|
2014-03-03 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
test_generator() {}
|
|
|
|
test_generator(const test_generator &other): m_blocks_info(other.m_blocks_info) {}
|
2014-03-03 17:07:58 -05:00
|
|
|
void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
|
2018-07-18 17:24:53 -04:00
|
|
|
void get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const;
|
2014-03-03 17:07:58 -05:00
|
|
|
uint64_t get_already_generated_coins(const crypto::hash& blk_id) const;
|
|
|
|
uint64_t get_already_generated_coins(const cryptonote::block& blk) const;
|
|
|
|
|
2018-07-18 17:24:53 -04:00
|
|
|
void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_weights, uint64_t already_generated_coins,
|
2016-06-27 13:56:19 -04:00
|
|
|
uint8_t hf_version = 1);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
|
|
|
|
const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
|
2018-11-20 08:40:51 -05:00
|
|
|
std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list,
|
|
|
|
const boost::optional<uint8_t>& hf_ver = boost::none);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool construct_block(cryptonote::block& blk, const cryptonote::account_base& miner_acc, uint64_t timestamp);
|
|
|
|
bool construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev, const cryptonote::account_base& miner_acc,
|
2018-11-20 08:40:51 -05:00
|
|
|
const std::list<cryptonote::transaction>& tx_list = std::list<cryptonote::transaction>(),
|
|
|
|
const boost::optional<uint8_t>& hf_ver = boost::none);
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
bool construct_block_manually(cryptonote::block& blk, const cryptonote::block& prev_block,
|
|
|
|
const cryptonote::account_base& miner_acc, int actual_params = bf_none, uint8_t major_ver = 0,
|
|
|
|
uint8_t minor_ver = 0, uint64_t timestamp = 0, const crypto::hash& prev_id = crypto::hash(),
|
|
|
|
const cryptonote::difficulty_type& diffic = 1, const cryptonote::transaction& miner_tx = cryptonote::transaction(),
|
2016-06-27 13:56:19 -04:00
|
|
|
const std::vector<crypto::hash>& tx_hashes = std::vector<crypto::hash>(), size_t txs_sizes = 0, size_t max_outs = 999,
|
|
|
|
uint8_t hf_version = 1);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool construct_block_manually_tx(cryptonote::block& blk, const cryptonote::block& prev_block,
|
|
|
|
const cryptonote::account_base& miner_acc, const std::vector<crypto::hash>& tx_hashes, size_t txs_size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unordered_map<crypto::hash, block_info> m_blocks_info;
|
2018-11-20 08:40:51 -05:00
|
|
|
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
template<class Archive>
|
|
|
|
void serialize(Archive & ar, const unsigned int /*version*/)
|
|
|
|
{
|
|
|
|
ar & m_blocks_info;
|
|
|
|
}
|
2014-03-03 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
template<typename T>
|
|
|
|
std::string dump_keys(T * buff32)
|
|
|
|
{
|
|
|
|
std::ostringstream ss;
|
|
|
|
char buff[10];
|
|
|
|
|
|
|
|
ss << "[";
|
|
|
|
for(int i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
snprintf(buff, 10, "0x%02x", ((uint8_t)buff32[i] & 0xff));
|
|
|
|
ss << buff;
|
|
|
|
if (i < 31)
|
|
|
|
ss << ",";
|
|
|
|
}
|
|
|
|
ss << "]";
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct output_index {
|
|
|
|
const cryptonote::txout_target_v out;
|
|
|
|
uint64_t amount;
|
|
|
|
size_t blk_height; // block height
|
|
|
|
size_t tx_no; // index of transaction in block
|
|
|
|
size_t out_no; // index of out in transaction
|
|
|
|
size_t idx;
|
|
|
|
uint64_t unlock_time;
|
|
|
|
bool is_coin_base;
|
|
|
|
bool spent;
|
|
|
|
bool rct;
|
|
|
|
rct::key comm;
|
|
|
|
const cryptonote::block *p_blk;
|
|
|
|
const cryptonote::transaction *p_tx;
|
|
|
|
|
|
|
|
output_index(const cryptonote::txout_target_v &_out, uint64_t _a, size_t _h, size_t tno, size_t ono, const cryptonote::block *_pb, const cryptonote::transaction *_pt)
|
|
|
|
: out(_out), amount(_a), blk_height(_h), tx_no(tno), out_no(ono), idx(0), unlock_time(0),
|
|
|
|
is_coin_base(false), spent(false), rct(false), p_blk(_pb), p_tx(_pt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
output_index(const output_index &other)
|
|
|
|
: out(other.out), amount(other.amount), blk_height(other.blk_height), tx_no(other.tx_no), rct(other.rct),
|
|
|
|
out_no(other.out_no), idx(other.idx), unlock_time(other.unlock_time), is_coin_base(other.is_coin_base),
|
|
|
|
spent(other.spent), comm(other.comm), p_blk(other.p_blk), p_tx(other.p_tx) { }
|
|
|
|
|
|
|
|
void set_rct(bool arct) {
|
|
|
|
rct = arct;
|
|
|
|
if (rct && p_tx->rct_signatures.outPk.size() > out_no)
|
|
|
|
comm = p_tx->rct_signatures.outPk[out_no].mask;
|
|
|
|
else
|
|
|
|
comm = rct::commit(amount, rct::identity());
|
|
|
|
}
|
|
|
|
|
|
|
|
rct::key commitment() const {
|
|
|
|
return comm;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string toString() const {
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
ss << "output_index{blk_height=" << blk_height
|
|
|
|
<< " tx_no=" << tx_no
|
|
|
|
<< " out_no=" << out_no
|
|
|
|
<< " amount=" << amount
|
|
|
|
<< " idx=" << idx
|
|
|
|
<< " unlock_time=" << unlock_time
|
|
|
|
<< " spent=" << spent
|
|
|
|
<< " is_coin_base=" << is_coin_base
|
|
|
|
<< " rct=" << rct
|
|
|
|
<< " comm=" << dump_keys(comm.bytes)
|
|
|
|
<< "}";
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
output_index& operator=(const output_index& other)
|
|
|
|
{
|
|
|
|
new(this) output_index(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
|
|
|
|
typedef std::pair<crypto::hash, size_t> output_hasher;
|
|
|
|
typedef boost::hash<output_hasher> output_hasher_hasher;
|
|
|
|
typedef std::map<uint64_t, std::vector<size_t> > map_output_t;
|
|
|
|
typedef std::map<uint64_t, std::vector<output_index> > map_output_idx_t;
|
|
|
|
typedef std::unordered_map<crypto::hash, cryptonote::block> map_block_t;
|
|
|
|
typedef std::unordered_map<output_hasher, output_index, output_hasher_hasher> map_txid_output_t;
|
|
|
|
typedef std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses_t;
|
|
|
|
typedef std::pair<uint64_t, size_t> outloc_t;
|
|
|
|
|
|
|
|
typedef boost::variant<cryptonote::account_public_address, cryptonote::account_keys, cryptonote::account_base, cryptonote::tx_destination_entry> var_addr_t;
|
|
|
|
typedef struct {
|
|
|
|
const var_addr_t addr;
|
|
|
|
bool is_subaddr;
|
|
|
|
uint64_t amount;
|
|
|
|
} dest_wrapper_t;
|
|
|
|
|
|
|
|
// Daemon functionality
|
|
|
|
class block_tracker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
map_output_idx_t m_outs;
|
|
|
|
map_txid_output_t m_map_outs; // mapping (txid, out) -> output_index
|
|
|
|
map_block_t m_blocks;
|
|
|
|
|
|
|
|
block_tracker() = default;
|
|
|
|
block_tracker(const block_tracker &bt): m_outs(bt.m_outs), m_map_outs(bt.m_map_outs), m_blocks(bt.m_blocks) {};
|
|
|
|
map_txid_output_t::iterator find_out(const crypto::hash &txid, size_t out);
|
|
|
|
map_txid_output_t::iterator find_out(const output_hasher &id);
|
|
|
|
void process(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
|
|
|
|
void process(const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t& mtx);
|
|
|
|
void process(const cryptonote::block* blk, const cryptonote::transaction * tx, size_t i);
|
|
|
|
void global_indices(const cryptonote::transaction *tx, std::vector<uint64_t> &indices);
|
|
|
|
void get_fake_outs(size_t num_outs, uint64_t amount, uint64_t global_index, uint64_t cur_height, std::vector<get_outs_entry> &outs);
|
|
|
|
|
|
|
|
std::string dump_data();
|
|
|
|
void dump_data(const std::string & fname);
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
template<class Archive>
|
|
|
|
void serialize(Archive & ar, const unsigned int /*version*/)
|
|
|
|
{
|
|
|
|
ar & m_outs;
|
|
|
|
ar & m_map_outs;
|
|
|
|
ar & m_blocks;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string dump_data(const cryptonote::transaction &tx);
|
|
|
|
cryptonote::account_public_address get_address(const var_addr_t& inp);
|
|
|
|
cryptonote::account_public_address get_address(const cryptonote::account_public_address& inp);
|
|
|
|
cryptonote::account_public_address get_address(const cryptonote::account_keys& inp);
|
|
|
|
cryptonote::account_public_address get_address(const cryptonote::account_base& inp);
|
|
|
|
cryptonote::account_public_address get_address(const cryptonote::tx_destination_entry& inp);
|
|
|
|
|
|
|
|
inline cryptonote::difficulty_type get_test_difficulty(const boost::optional<uint8_t>& hf_ver=boost::none) {return !hf_ver || hf_ver.get() <= 1 ? 1 : 2;}
|
|
|
|
inline uint64_t current_difficulty_window(const boost::optional<uint8_t>& hf_ver=boost::none){ return !hf_ver || hf_ver.get() <= 1 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2; }
|
2014-03-03 17:07:58 -05:00
|
|
|
void fill_nonce(cryptonote::block& blk, const cryptonote::difficulty_type& diffic, uint64_t height);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
cryptonote::tx_destination_entry build_dst(const var_addr_t& to, bool is_subaddr=false, uint64_t amount=0);
|
|
|
|
std::vector<cryptonote::tx_destination_entry> build_dsts(const var_addr_t& to1, bool sub1=false, uint64_t am1=0);
|
|
|
|
std::vector<cryptonote::tx_destination_entry> build_dsts(std::initializer_list<dest_wrapper_t> inps);
|
|
|
|
uint64_t sum_amount(const std::vector<cryptonote::tx_destination_entry>& destinations);
|
|
|
|
uint64_t sum_amount(const std::vector<cryptonote::tx_source_entry>& sources);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins,
|
|
|
|
const cryptonote::account_public_address& miner_address, cryptonote::transaction& tx,
|
2018-11-20 08:40:51 -05:00
|
|
|
uint64_t fee, cryptonote::keypair* p_txkey = nullptr);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx,
|
2018-11-20 08:40:51 -05:00
|
|
|
const cryptonote::block& blk_head, const cryptonote::account_base& from, const var_addr_t& to, uint64_t amount,
|
|
|
|
uint64_t fee, size_t nmix, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
|
|
|
|
|
|
|
|
bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx, const cryptonote::block& blk_head,
|
|
|
|
const cryptonote::account_base& from, std::vector<cryptonote::tx_destination_entry> destinations,
|
|
|
|
uint64_t fee, size_t nmix, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
|
|
|
|
|
|
|
|
bool construct_tx_to_key(cryptonote::transaction& tx, const cryptonote::account_base& from, const var_addr_t& to, uint64_t amount,
|
|
|
|
std::vector<cryptonote::tx_source_entry> &sources,
|
|
|
|
uint64_t fee, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
|
|
|
|
|
|
|
|
bool construct_tx_to_key(cryptonote::transaction& tx, const cryptonote::account_base& from, const std::vector<cryptonote::tx_destination_entry>& destinations,
|
|
|
|
std::vector<cryptonote::tx_source_entry> &sources,
|
|
|
|
uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version = 0);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
cryptonote::transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
|
2018-11-20 08:40:51 -05:00
|
|
|
const cryptonote::account_base& acc_from, const var_addr_t& to,
|
2014-03-03 17:07:58 -05:00
|
|
|
uint64_t amount, uint64_t fee);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
bool construct_tx_rct(const cryptonote::account_keys& sender_account_keys,
|
|
|
|
std::vector<cryptonote::tx_source_entry>& sources,
|
|
|
|
const std::vector<cryptonote::tx_destination_entry>& destinations,
|
|
|
|
const boost::optional<cryptonote::account_public_address>& change_addr,
|
|
|
|
std::vector<uint8_t> extra, cryptonote::transaction& tx, uint64_t unlock_time,
|
|
|
|
bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t num_blocks(const std::vector<test_event_entry>& events);
|
|
|
|
cryptonote::block get_head_block(const std::vector<test_event_entry>& events);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
void get_confirmed_txs(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs);
|
2018-11-20 08:40:51 -05:00
|
|
|
bool trim_block_chain(std::vector<cryptonote::block>& blockchain, const crypto::hash& tail);
|
|
|
|
bool trim_block_chain(std::vector<const cryptonote::block*>& blockchain, const crypto::hash& tail);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<cryptonote::block>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);
|
2018-11-20 08:40:51 -05:00
|
|
|
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<const cryptonote::block*>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);
|
|
|
|
|
|
|
|
void fill_tx_destinations(const var_addr_t& from, const cryptonote::account_public_address& to,
|
|
|
|
uint64_t amount, uint64_t fee,
|
|
|
|
const std::vector<cryptonote::tx_source_entry> &sources,
|
|
|
|
std::vector<cryptonote::tx_destination_entry>& destinations, bool always_change=false);
|
|
|
|
|
|
|
|
void fill_tx_destinations(const var_addr_t& from, const std::vector<cryptonote::tx_destination_entry>& dests,
|
|
|
|
uint64_t fee,
|
|
|
|
const std::vector<cryptonote::tx_source_entry> &sources,
|
|
|
|
std::vector<cryptonote::tx_destination_entry>& destinations,
|
|
|
|
bool always_change);
|
|
|
|
|
|
|
|
void fill_tx_destinations(const var_addr_t& from, const cryptonote::account_public_address& to,
|
|
|
|
uint64_t amount, uint64_t fee,
|
|
|
|
const std::vector<cryptonote::tx_source_entry> &sources,
|
|
|
|
std::vector<cryptonote::tx_destination_entry>& destinations,
|
|
|
|
std::vector<cryptonote::tx_destination_entry>& destinations_pure,
|
|
|
|
bool always_change=false);
|
|
|
|
|
|
|
|
|
|
|
|
void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
|
|
|
|
const cryptonote::account_base& from, const cryptonote::account_public_address& to,
|
|
|
|
uint64_t amount, uint64_t fee, size_t nmix,
|
|
|
|
std::vector<cryptonote::tx_source_entry>& sources,
|
|
|
|
std::vector<cryptonote::tx_destination_entry>& destinations);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
|
|
|
|
const cryptonote::account_base& from, const cryptonote::account_base& to,
|
|
|
|
uint64_t amount, uint64_t fee, size_t nmix,
|
|
|
|
std::vector<cryptonote::tx_source_entry>& sources,
|
|
|
|
std::vector<cryptonote::tx_destination_entry>& destinations);
|
2018-11-20 08:40:51 -05:00
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
auto do_check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_index, const cryptonote::transaction& tx, t_test_class& validator, int)
|
|
|
|
-> decltype(validator.check_tx_verification_context(tvc, tx_added, event_index, tx))
|
|
|
|
{
|
|
|
|
return validator.check_tx_verification_context(tvc, tx_added, event_index, tx);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
bool do_check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t /*event_index*/, const cryptonote::transaction& /*tx*/, t_test_class&, long)
|
|
|
|
{
|
|
|
|
// Default block verification context check
|
|
|
|
if (tvc.m_verifivation_failed)
|
2016-03-21 06:12:12 -04:00
|
|
|
throw std::runtime_error("Transaction verification failed");
|
2014-03-03 17:07:58 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_index, const cryptonote::transaction& tx, t_test_class& validator)
|
|
|
|
{
|
|
|
|
// SFINAE in action
|
|
|
|
return do_check_tx_verification_context(tvc, tx_added, event_index, tx, validator, 0);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
2018-03-30 15:29:42 -04:00
|
|
|
auto do_check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_index, const std::vector<cryptonote::transaction>& txs, t_test_class& validator, int)
|
|
|
|
-> decltype(validator.check_tx_verification_context(tvcs, tx_added, event_index, txs))
|
|
|
|
{
|
|
|
|
return validator.check_tx_verification_context(tvcs, tx_added, event_index, txs);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
bool do_check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t /*event_index*/, const std::vector<cryptonote::transaction>& /*txs*/, t_test_class&, long)
|
|
|
|
{
|
|
|
|
// Default block verification context check
|
|
|
|
for (const cryptonote::tx_verification_context &tvc: tvcs)
|
|
|
|
if (tvc.m_verifivation_failed)
|
|
|
|
throw std::runtime_error("Transaction verification failed");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
bool check_tx_verification_context(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t tx_added, size_t event_index, const std::vector<cryptonote::transaction>& txs, t_test_class& validator)
|
|
|
|
{
|
|
|
|
// SFINAE in action
|
|
|
|
return do_check_tx_verification_context(tvcs, tx_added, event_index, txs, validator, 0);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
2014-03-03 17:07:58 -05:00
|
|
|
auto do_check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_index, const cryptonote::block& blk, t_test_class& validator, int)
|
|
|
|
-> decltype(validator.check_block_verification_context(bvc, event_index, blk))
|
|
|
|
{
|
|
|
|
return validator.check_block_verification_context(bvc, event_index, blk);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
bool do_check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t /*event_index*/, const cryptonote::block& /*blk*/, t_test_class&, long)
|
|
|
|
{
|
|
|
|
// Default block verification context check
|
|
|
|
if (bvc.m_verifivation_failed)
|
2016-03-21 06:12:12 -04:00
|
|
|
throw std::runtime_error("Block verification failed");
|
2014-03-03 17:07:58 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_index, const cryptonote::block& blk, t_test_class& validator)
|
|
|
|
{
|
|
|
|
// SFINAE in action
|
|
|
|
return do_check_block_verification_context(bvc, event_index, blk, validator, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* */
|
|
|
|
/************************************************************************/
|
|
|
|
template<class t_test_class>
|
|
|
|
struct push_core_event_visitor: public boost::static_visitor<bool>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
cryptonote::core& m_c;
|
|
|
|
const std::vector<test_event_entry>& m_events;
|
|
|
|
t_test_class& m_validator;
|
|
|
|
size_t m_ev_index;
|
|
|
|
|
|
|
|
bool m_txs_keeped_by_block;
|
|
|
|
|
|
|
|
public:
|
|
|
|
push_core_event_visitor(cryptonote::core& c, const std::vector<test_event_entry>& events, t_test_class& validator)
|
|
|
|
: m_c(c)
|
|
|
|
, m_events(events)
|
|
|
|
, m_validator(validator)
|
|
|
|
, m_ev_index(0)
|
|
|
|
, m_txs_keeped_by_block(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void event_index(size_t ev_index)
|
|
|
|
{
|
|
|
|
m_ev_index = ev_index;
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
bool operator()(const event_replay_settings& settings)
|
|
|
|
{
|
|
|
|
log_event("event_replay_settings");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
bool operator()(const event_visitor_settings& settings)
|
|
|
|
{
|
|
|
|
log_event("event_visitor_settings");
|
|
|
|
|
|
|
|
if (settings.valid_mask & event_visitor_settings::set_txs_keeped_by_block)
|
|
|
|
{
|
|
|
|
m_txs_keeped_by_block = settings.txs_keeped_by_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(const cryptonote::transaction& tx) const
|
|
|
|
{
|
|
|
|
log_event("cryptonote::transaction");
|
|
|
|
|
|
|
|
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
|
|
|
|
size_t pool_size = m_c.get_pool_transactions_count();
|
2017-01-14 08:01:21 -05:00
|
|
|
m_c.handle_incoming_tx(t_serializable_object_to_blob(tx), tvc, m_txs_keeped_by_block, false, false);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool tx_added = pool_size + 1 == m_c.get_pool_transactions_count();
|
|
|
|
bool r = check_tx_verification_context(tvc, tx_added, m_ev_index, tx, m_validator);
|
|
|
|
CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-30 15:29:42 -04:00
|
|
|
bool operator()(const std::vector<cryptonote::transaction>& txs) const
|
|
|
|
{
|
|
|
|
log_event("cryptonote::transaction");
|
|
|
|
|
|
|
|
std::vector<cryptonote::blobdata> tx_blobs;
|
|
|
|
std::vector<cryptonote::tx_verification_context> tvcs;
|
|
|
|
cryptonote::tx_verification_context tvc0 = AUTO_VAL_INIT(tvc0);
|
|
|
|
for (const auto &tx: txs)
|
|
|
|
{
|
|
|
|
tx_blobs.push_back(t_serializable_object_to_blob(tx));
|
|
|
|
tvcs.push_back(tvc0);
|
|
|
|
}
|
|
|
|
size_t pool_size = m_c.get_pool_transactions_count();
|
|
|
|
m_c.handle_incoming_txs(tx_blobs, tvcs, m_txs_keeped_by_block, false, false);
|
|
|
|
size_t tx_added = m_c.get_pool_transactions_count() - pool_size;
|
|
|
|
bool r = check_tx_verification_context(tvcs, tx_added, m_ev_index, txs, m_validator);
|
|
|
|
CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
bool operator()(const cryptonote::block& b) const
|
|
|
|
{
|
|
|
|
log_event("cryptonote::block");
|
|
|
|
|
|
|
|
cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc);
|
2019-04-05 05:28:30 -04:00
|
|
|
cryptonote::blobdata bd = t_serializable_object_to_blob(b);
|
|
|
|
std::vector<cryptonote::block> pblocks;
|
|
|
|
if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, {bd, {}}), pblocks))
|
|
|
|
{
|
|
|
|
m_c.handle_incoming_block(bd, &b, bvc);
|
|
|
|
m_c.cleanup_handle_incoming_blocks();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bvc.m_verifivation_failed = true;
|
2014-03-03 17:07:58 -05:00
|
|
|
bool r = check_block_verification_context(bvc, m_ev_index, b, m_validator);
|
|
|
|
CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(const callback_entry& cb) const
|
|
|
|
{
|
|
|
|
log_event(std::string("callback_entry ") + cb.callback_name);
|
|
|
|
return m_validator.verify(cb.callback_name, m_c, m_ev_index, m_events);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(const cryptonote::account_base& ab) const
|
|
|
|
{
|
|
|
|
log_event("cryptonote::account_base");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(const serialized_block& sr_block) const
|
|
|
|
{
|
|
|
|
log_event("serialized_block");
|
|
|
|
|
|
|
|
cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc);
|
2019-04-05 05:28:30 -04:00
|
|
|
std::vector<cryptonote::block> pblocks;
|
|
|
|
if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, {sr_block.data, {}}), pblocks))
|
|
|
|
{
|
|
|
|
m_c.handle_incoming_block(sr_block.data, NULL, bvc);
|
|
|
|
m_c.cleanup_handle_incoming_blocks();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bvc.m_verifivation_failed = true;
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
cryptonote::block blk;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << sr_block.data;
|
|
|
|
binary_archive<false> ba(ss);
|
|
|
|
::serialization::serialize(ba, blk);
|
|
|
|
if (!ss.good())
|
|
|
|
{
|
|
|
|
blk = cryptonote::block();
|
|
|
|
}
|
|
|
|
bool r = check_block_verification_context(bvc, m_ev_index, blk, m_validator);
|
|
|
|
CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(const serialized_transaction& sr_tx) const
|
|
|
|
{
|
|
|
|
log_event("serialized_transaction");
|
|
|
|
|
|
|
|
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
|
|
|
|
size_t pool_size = m_c.get_pool_transactions_count();
|
2017-01-14 08:01:21 -05:00
|
|
|
m_c.handle_incoming_tx(sr_tx.data, tvc, m_txs_keeped_by_block, false, false);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool tx_added = pool_size + 1 == m_c.get_pool_transactions_count();
|
|
|
|
|
|
|
|
cryptonote::transaction tx;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << sr_tx.data;
|
|
|
|
binary_archive<false> ba(ss);
|
|
|
|
::serialization::serialize(ba, tx);
|
|
|
|
if (!ss.good())
|
|
|
|
{
|
|
|
|
tx = cryptonote::transaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool r = check_tx_verification_context(tvc, tx_added, m_ev_index, tx, m_validator);
|
|
|
|
CHECK_AND_NO_ASSERT_MES(r, false, "transaction verification context check failed");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void log_event(const std::string& event_type) const
|
|
|
|
{
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MGINFO_YELLOW("=== EVENT # " << m_ev_index << ": " << event_type);
|
2014-03-03 17:07:58 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
inline bool replay_events_through_core(cryptonote::core& cr, const std::vector<test_event_entry>& events, t_test_class& validator)
|
2018-11-20 08:40:51 -05:00
|
|
|
{
|
|
|
|
return replay_events_through_core_plain(cr, events, validator, true);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
inline bool replay_events_through_core_plain(cryptonote::core& cr, const std::vector<test_event_entry>& events, t_test_class& validator, bool reinit=true)
|
2014-03-03 17:07:58 -05:00
|
|
|
{
|
|
|
|
TRY_ENTRY();
|
|
|
|
|
|
|
|
//init core here
|
2018-11-20 08:40:51 -05:00
|
|
|
if (reinit) {
|
|
|
|
CHECK_AND_ASSERT_MES(typeid(cryptonote::block) == events[0].type(), false,
|
|
|
|
"First event must be genesis block creation");
|
|
|
|
cr.set_genesis_block(boost::get<cryptonote::block>(events[0]));
|
|
|
|
}
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
bool r = true;
|
|
|
|
push_core_event_visitor<t_test_class> visitor(cr, events, validator);
|
|
|
|
for(size_t i = 1; i < events.size() && r; ++i)
|
|
|
|
{
|
|
|
|
visitor.event_index(i);
|
|
|
|
r = boost::apply_visitor(visitor, events[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
CATCH_ENTRY_L0("replay_events_through_core", false);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
2016-04-02 17:00:55 -04:00
|
|
|
template<typename t_test_class>
|
2016-02-08 13:47:56 -05:00
|
|
|
struct get_test_options {
|
2016-08-14 05:13:44 -04:00
|
|
|
const std::pair<uint8_t, uint64_t> hard_forks[2];
|
2016-02-08 13:47:56 -05:00
|
|
|
const cryptonote::test_options test_options = {
|
2019-04-07 12:15:20 -04:00
|
|
|
hard_forks, 0
|
2016-02-08 13:47:56 -05:00
|
|
|
};
|
2016-08-14 05:13:44 -04:00
|
|
|
get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0), std::make_pair((uint8_t)0, (uint64_t)0)}{}
|
2016-02-08 13:47:56 -05:00
|
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
2019-02-27 10:55:31 -05:00
|
|
|
inline bool do_replay_events_get_core(std::vector<test_event_entry>& events, cryptonote::core *core)
|
2014-03-03 17:07:58 -05:00
|
|
|
{
|
|
|
|
boost::program_options::options_description desc("Allowed options");
|
|
|
|
cryptonote::core::init_options(desc);
|
|
|
|
boost::program_options::variables_map vm;
|
|
|
|
bool r = command_line::handle_error_helper(desc, [&]()
|
|
|
|
{
|
|
|
|
boost::program_options::store(boost::program_options::basic_parsed_options<char>(&desc), vm);
|
|
|
|
boost::program_options::notify(vm);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if (!r)
|
|
|
|
return false;
|
|
|
|
|
2019-02-27 10:55:31 -05:00
|
|
|
auto & c = *core;
|
2018-11-20 08:40:51 -05:00
|
|
|
|
2015-02-05 07:21:14 -05:00
|
|
|
// FIXME: make sure that vm has arg_testnet_on set to true or false if
|
|
|
|
// this test needs for it to be so.
|
2016-02-13 14:49:36 -05:00
|
|
|
get_test_options<t_test_class> gto;
|
2018-11-20 08:40:51 -05:00
|
|
|
|
|
|
|
// Hardforks can be specified in events.
|
|
|
|
v_hardforks_t hardforks;
|
2019-04-07 12:15:20 -04:00
|
|
|
cryptonote::test_options test_options_tmp{nullptr, 0};
|
2018-11-20 08:40:51 -05:00
|
|
|
const cryptonote::test_options * test_options_ = >o.test_options;
|
|
|
|
if (extract_hard_forks(events, hardforks)){
|
|
|
|
hardforks.push_back(std::make_pair((uint8_t)0, (uint64_t)0)); // terminator
|
|
|
|
test_options_tmp.hard_forks = hardforks.data();
|
|
|
|
test_options_ = &test_options_tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!c.init(vm, test_options_))
|
2014-03-03 17:07:58 -05:00
|
|
|
{
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR("Failed to init core");
|
2014-03-03 17:07:58 -05:00
|
|
|
return false;
|
|
|
|
}
|
2017-06-09 15:49:59 -04:00
|
|
|
c.get_blockchain_storage().get_db().set_batch_transactions(true);
|
2017-05-14 09:06:55 -04:00
|
|
|
|
|
|
|
// start with a clean pool
|
|
|
|
std::vector<crypto::hash> pool_txs;
|
|
|
|
if (!c.get_pool_transaction_hashes(pool_txs))
|
|
|
|
{
|
|
|
|
MERROR("Failed to flush txpool");
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-15 19:16:02 -04:00
|
|
|
c.get_blockchain_storage().flush_txes_from_pool(pool_txs);
|
2017-05-14 09:06:55 -04:00
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
t_test_class validator;
|
2015-12-30 11:05:52 -05:00
|
|
|
bool ret = replay_events_through_core<t_test_class>(c, events, validator);
|
2018-11-20 08:40:51 -05:00
|
|
|
// c.deinit();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
inline bool replay_events_through_core_validate(std::vector<test_event_entry>& events, cryptonote::core & c)
|
|
|
|
{
|
|
|
|
std::vector<crypto::hash> pool_txs;
|
|
|
|
if (!c.get_pool_transaction_hashes(pool_txs))
|
|
|
|
{
|
|
|
|
MERROR("Failed to flush txpool");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
c.get_blockchain_storage().flush_txes_from_pool(pool_txs);
|
|
|
|
|
|
|
|
t_test_class validator;
|
|
|
|
return replay_events_through_core_plain<t_test_class>(c, events, validator, false);
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
inline bool do_replay_events(std::vector<test_event_entry>& events)
|
|
|
|
{
|
2019-02-27 10:55:31 -05:00
|
|
|
cryptonote::core core(nullptr);
|
2018-11-20 08:40:51 -05:00
|
|
|
bool ret = do_replay_events_get_core<t_test_class>(events, &core);
|
2019-02-27 10:55:31 -05:00
|
|
|
core.deinit();
|
2015-12-30 11:05:52 -05:00
|
|
|
return ret;
|
2014-03-03 17:07:58 -05:00
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
template<class t_test_class>
|
|
|
|
inline bool do_replay_file(const std::string& filename)
|
|
|
|
{
|
|
|
|
std::vector<test_event_entry> events;
|
|
|
|
if (!tools::unserialize_obj_from_file(events, filename))
|
|
|
|
{
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR("Failed to deserialize data from file: ");
|
2014-03-03 17:07:58 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return do_replay_events<t_test_class>(events);
|
|
|
|
}
|
2018-07-17 05:44:46 -04:00
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
//--------------------------------------------------------------------------
|
2018-11-20 08:40:51 -05:00
|
|
|
#define DEFAULT_HARDFORKS(HARDFORKS) do { \
|
|
|
|
HARDFORKS.push_back(std::make_pair((uint8_t)1, (uint64_t)0)); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define ADD_HARDFORK(HARDFORKS, FORK, HEIGHT) HARDFORKS.push_back(std::make_pair((uint8_t)FORK, (uint64_t)HEIGHT))
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
#define GENERATE_ACCOUNT(account) \
|
|
|
|
cryptonote::account_base account; \
|
|
|
|
account.generate();
|
|
|
|
|
2017-09-26 18:16:25 -04:00
|
|
|
#define GENERATE_MULTISIG_ACCOUNT(account, threshold, total) \
|
|
|
|
CHECK_AND_ASSERT_MES(threshold >= 2 && threshold <= total, false, "Invalid multisig scheme"); \
|
|
|
|
std::vector<cryptonote::account_base> account(total); \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
for (size_t msidx = 0; msidx < total; ++msidx) \
|
|
|
|
account[msidx].generate(); \
|
2018-07-17 05:44:46 -04:00
|
|
|
make_multisig_accounts(account, threshold); \
|
2017-09-26 18:16:25 -04:00
|
|
|
} while(0)
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
#define MAKE_ACCOUNT(VEC_EVENTS, account) \
|
|
|
|
cryptonote::account_base account; \
|
|
|
|
account.generate(); \
|
|
|
|
VEC_EVENTS.push_back(account);
|
|
|
|
|
|
|
|
#define DO_CALLBACK(VEC_EVENTS, CB_NAME) \
|
|
|
|
{ \
|
|
|
|
callback_entry CALLBACK_ENTRY; \
|
|
|
|
CALLBACK_ENTRY.callback_name = CB_NAME; \
|
|
|
|
VEC_EVENTS.push_back(CALLBACK_ENTRY); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define REGISTER_CALLBACK(CB_NAME, CLBACK) \
|
|
|
|
register_callback(CB_NAME, boost::bind(&CLBACK, this, _1, _2, _3));
|
|
|
|
|
|
|
|
#define REGISTER_CALLBACK_METHOD(CLASS, METHOD) \
|
|
|
|
register_callback(#METHOD, boost::bind(&CLASS::METHOD, this, _1, _2, _3));
|
|
|
|
|
|
|
|
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS) \
|
|
|
|
test_generator generator; \
|
|
|
|
cryptonote::block BLK_NAME; \
|
|
|
|
generator.construct_block(BLK_NAME, MINER_ACC, TS); \
|
|
|
|
VEC_EVENTS.push_back(BLK_NAME);
|
|
|
|
|
|
|
|
#define MAKE_NEXT_BLOCK(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC) \
|
|
|
|
cryptonote::block BLK_NAME; \
|
|
|
|
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC); \
|
|
|
|
VEC_EVENTS.push_back(BLK_NAME);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define MAKE_NEXT_BLOCK_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, HF) \
|
|
|
|
cryptonote::block BLK_NAME; \
|
|
|
|
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, std::list<cryptonote::transaction>(), HF); \
|
|
|
|
VEC_EVENTS.push_back(BLK_NAME);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
#define MAKE_NEXT_BLOCK_TX1(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1) \
|
|
|
|
cryptonote::block BLK_NAME; \
|
|
|
|
{ \
|
|
|
|
std::list<cryptonote::transaction> tx_list; \
|
|
|
|
tx_list.push_back(TX1); \
|
|
|
|
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list); \
|
|
|
|
} \
|
|
|
|
VEC_EVENTS.push_back(BLK_NAME);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define MAKE_NEXT_BLOCK_TX1_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1, HF) \
|
|
|
|
cryptonote::block BLK_NAME; \
|
|
|
|
{ \
|
|
|
|
std::list<cryptonote::transaction> tx_list; \
|
|
|
|
tx_list.push_back(TX1); \
|
|
|
|
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list, HF); \
|
|
|
|
} \
|
|
|
|
VEC_EVENTS.push_back(BLK_NAME);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
#define MAKE_NEXT_BLOCK_TX_LIST(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST) \
|
|
|
|
cryptonote::block BLK_NAME; \
|
|
|
|
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST); \
|
|
|
|
VEC_EVENTS.push_back(BLK_NAME);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define MAKE_NEXT_BLOCK_TX_LIST_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST, HF) \
|
2014-03-03 17:07:58 -05:00
|
|
|
cryptonote::block BLK_NAME; \
|
2018-11-20 08:40:51 -05:00
|
|
|
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST, HF); \
|
|
|
|
VEC_EVENTS.push_back(BLK_NAME);
|
|
|
|
|
|
|
|
#define REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT, HF) \
|
|
|
|
cryptonote::block BLK_NAME; \
|
2014-03-03 17:07:58 -05:00
|
|
|
{ \
|
2018-11-20 08:40:51 -05:00
|
|
|
cryptonote::block blk_last = PREV_BLOCK; \
|
2014-03-03 17:07:58 -05:00
|
|
|
for (size_t i = 0; i < COUNT; ++i) \
|
|
|
|
{ \
|
2018-11-20 08:40:51 -05:00
|
|
|
MAKE_NEXT_BLOCK_HF(VEC_EVENTS, blk, blk_last, MINER_ACC, HF); \
|
2014-03-03 17:07:58 -05:00
|
|
|
blk_last = blk; \
|
|
|
|
} \
|
|
|
|
BLK_NAME = blk_last; \
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define REWIND_BLOCKS_N(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT) REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT, boost::none)
|
2014-03-03 17:07:58 -05:00
|
|
|
#define REWIND_BLOCKS(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC) REWIND_BLOCKS_N(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW)
|
2018-11-20 08:40:51 -05:00
|
|
|
#define REWIND_BLOCKS_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, HF) REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW, HF)
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
#define MAKE_TX_MIX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
|
|
|
|
cryptonote::transaction TX_NAME; \
|
|
|
|
construct_tx_to_key(VEC_EVENTS, TX_NAME, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX); \
|
|
|
|
VEC_EVENTS.push_back(TX_NAME);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define MAKE_TX_MIX_RCT(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
|
|
|
|
cryptonote::transaction TX_NAME; \
|
|
|
|
construct_tx_to_key(VEC_EVENTS, TX_NAME, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX, true, rct::RangeProofPaddedBulletproof); \
|
|
|
|
VEC_EVENTS.push_back(TX_NAME);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
#define MAKE_TX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, HEAD) MAKE_TX_MIX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, 0, HEAD)
|
|
|
|
|
|
|
|
#define MAKE_TX_MIX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
|
|
|
|
{ \
|
2018-11-20 08:40:51 -05:00
|
|
|
cryptonote::transaction t; \
|
2014-03-03 17:07:58 -05:00
|
|
|
construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX); \
|
|
|
|
SET_NAME.push_back(t); \
|
|
|
|
VEC_EVENTS.push_back(t); \
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define MAKE_TX_MIX_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
|
|
|
|
MAKE_TX_MIX_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD, rct::RangeProofPaddedBulletproof, 1)
|
|
|
|
#define MAKE_TX_MIX_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD, RCT_TYPE, BP_VER) \
|
|
|
|
{ \
|
|
|
|
cryptonote::transaction t; \
|
|
|
|
construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX, true, RCT_TYPE, BP_VER); \
|
|
|
|
SET_NAME.push_back(t); \
|
|
|
|
VEC_EVENTS.push_back(t); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAKE_TX_MIX_DEST_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD) \
|
|
|
|
MAKE_TX_MIX_DEST_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD, rct::RangeProofPaddedBulletproof, 1)
|
|
|
|
#define MAKE_TX_MIX_DEST_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD, RCT_TYPE, BP_VER) \
|
|
|
|
{ \
|
|
|
|
cryptonote::transaction t; \
|
|
|
|
construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, TESTS_DEFAULT_FEE, NMIX, true, RCT_TYPE, BP_VER); \
|
|
|
|
SET_NAME.push_back(t); \
|
|
|
|
VEC_EVENTS.push_back(t); \
|
|
|
|
}
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
#define MAKE_TX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD) MAKE_TX_MIX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, 0, HEAD)
|
|
|
|
|
|
|
|
#define MAKE_TX_LIST_START(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD) \
|
|
|
|
std::list<cryptonote::transaction> SET_NAME; \
|
|
|
|
MAKE_TX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD);
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define MAKE_TX_LIST_START_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
|
|
|
|
std::list<cryptonote::transaction> SET_NAME; \
|
|
|
|
MAKE_TX_MIX_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD);
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
#define MAKE_MINER_TX_AND_KEY_MANUALLY(TX, BLK, KEY) \
|
|
|
|
transaction TX; \
|
|
|
|
if (!construct_miner_tx_manually(get_block_height(BLK) + 1, generator.get_already_generated_coins(BLK), \
|
|
|
|
miner_account.get_keys().m_account_address, TX, 0, KEY)) \
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#define MAKE_MINER_TX_MANUALLY(TX, BLK) MAKE_MINER_TX_AND_KEY_MANUALLY(TX, BLK, 0)
|
|
|
|
|
|
|
|
#define SET_EVENT_VISITOR_SETT(VEC_EVENTS, SETT, VAL) VEC_EVENTS.push_back(event_visitor_settings(SETT, VAL));
|
|
|
|
|
|
|
|
#define GENERATE(filename, genclass) \
|
|
|
|
{ \
|
|
|
|
std::vector<test_event_entry> events; \
|
|
|
|
genclass g; \
|
|
|
|
g.generate(events); \
|
|
|
|
if (!tools::serialize_obj_to_file(events, filename)) \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR("Failed to serialize data to file: " << filename); \
|
2016-03-21 06:12:12 -04:00
|
|
|
throw std::runtime_error("Failed to serialize data to file"); \
|
2014-03-03 17:07:58 -05:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define PLAY(filename, genclass) \
|
|
|
|
if(!do_replay_file<genclass>(filename)) \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR("Failed to pass test : " << #genclass); \
|
2014-03-03 17:07:58 -05:00
|
|
|
return 1; \
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:40:51 -05:00
|
|
|
#define CATCH_REPLAY(genclass) \
|
2014-03-03 17:07:58 -05:00
|
|
|
catch (const std::exception& ex) \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR(#genclass << " generation failed: what=" << ex.what()); \
|
2014-03-03 17:07:58 -05:00
|
|
|
} \
|
|
|
|
catch (...) \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR(#genclass << " generation failed: generic exception"); \
|
2018-11-20 08:40:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#define REPLAY_CORE(genclass) \
|
2014-03-03 17:07:58 -05:00
|
|
|
if (generated && do_replay_events< genclass >(events)) \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MGINFO_GREEN("#TEST# Succeeded " << #genclass); \
|
2014-03-03 17:07:58 -05:00
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR("#TEST# Failed " << #genclass); \
|
2014-03-03 17:07:58 -05:00
|
|
|
failed_tests.push_back(#genclass); \
|
2018-11-20 08:40:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#define REPLAY_WITH_CORE(genclass, CORE) \
|
|
|
|
if (generated && replay_events_through_core_validate< genclass >(events, CORE)) \
|
|
|
|
{ \
|
|
|
|
MGINFO_GREEN("#TEST# Succeeded " << #genclass); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
MERROR("#TEST# Failed " << #genclass); \
|
|
|
|
failed_tests.push_back(#genclass); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CATCH_GENERATE_REPLAY(genclass) \
|
|
|
|
CATCH_REPLAY(genclass); \
|
|
|
|
REPLAY_CORE(genclass);
|
|
|
|
|
|
|
|
#define CATCH_GENERATE_REPLAY_CORE(genclass, CORE) \
|
|
|
|
CATCH_REPLAY(genclass); \
|
|
|
|
REPLAY_WITH_CORE(genclass, CORE);
|
|
|
|
|
|
|
|
#define GENERATE_AND_PLAY(genclass) \
|
|
|
|
if (list_tests) \
|
|
|
|
std::cout << #genclass << std::endl; \
|
|
|
|
else if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \
|
|
|
|
{ \
|
|
|
|
std::vector<test_event_entry> events; \
|
|
|
|
++tests_count; \
|
|
|
|
bool generated = false; \
|
|
|
|
try \
|
|
|
|
{ \
|
|
|
|
genclass g; \
|
|
|
|
generated = g.generate(events); \
|
|
|
|
} \
|
|
|
|
CATCH_GENERATE_REPLAY(genclass); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GENERATE_AND_PLAY_INSTANCE(genclass, ins, CORE) \
|
|
|
|
if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \
|
|
|
|
{ \
|
|
|
|
std::vector<test_event_entry> events; \
|
|
|
|
++tests_count; \
|
|
|
|
bool generated = false; \
|
|
|
|
try \
|
|
|
|
{ \
|
|
|
|
generated = ins.generate(events); \
|
2014-03-03 17:07:58 -05:00
|
|
|
} \
|
2018-11-20 08:40:51 -05:00
|
|
|
CATCH_GENERATE_REPLAY_CORE(genclass, CORE); \
|
2014-03-03 17:07:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CALL_TEST(test_name, function) \
|
|
|
|
{ \
|
|
|
|
if(!function()) \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MERROR("#TEST# Failed " << test_name); \
|
2014-03-03 17:07:58 -05:00
|
|
|
return 1; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MGINFO_GREEN("#TEST# Succeeded " << test_name); \
|
2014-03-03 17:07:58 -05:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define QUOTEME(x) #x
|
|
|
|
#define DEFINE_TESTS_ERROR_CONTEXT(text) const char* perr_context = text;
|
|
|
|
#define CHECK_TEST_CONDITION(cond) CHECK_AND_ASSERT_MES(cond, false, "[" << perr_context << "] failed: \"" << QUOTEME(cond) << "\"")
|
|
|
|
#define CHECK_EQ(v1, v2) CHECK_AND_ASSERT_MES(v1 == v2, false, "[" << perr_context << "] failed: \"" << QUOTEME(v1) << " == " << QUOTEME(v2) << "\", " << v1 << " != " << v2)
|
|
|
|
#define CHECK_NOT_EQ(v1, v2) CHECK_AND_ASSERT_MES(!(v1 == v2), false, "[" << perr_context << "] failed: \"" << QUOTEME(v1) << " != " << QUOTEME(v2) << "\", " << v1 << " == " << v2)
|
|
|
|
#define MK_COINS(amount) (UINT64_C(amount) * COIN)
|
2015-12-13 08:56:15 -05:00
|
|
|
#define TESTS_DEFAULT_FEE ((uint64_t)20000000000) // 2 * pow(10, 10)
|