aboutsummaryrefslogtreecommitdiff
path: root/tests/core_tests/chaingen.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core_tests/chaingen.h')
-rw-r--r--tests/core_tests/chaingen.h60
1 files changed, 52 insertions, 8 deletions
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index bbc9edd19..34b205ae5 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -135,7 +135,7 @@ VARIANT_TAG(binary_archive, serialized_block, 0xcd);
VARIANT_TAG(binary_archive, serialized_transaction, 0xce);
VARIANT_TAG(binary_archive, event_visitor_settings, 0xcf);
-typedef boost::variant<cryptonote::block, cryptonote::transaction, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings> test_event_entry;
+typedef boost::variant<cryptonote::block, cryptonote::transaction, std::vector<cryptonote::transaction>, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings> test_event_entry;
typedef std::unordered_map<crypto::hash, const cryptonote::transaction*> map_hash2tx_t;
class test_chain_unit_base
@@ -159,20 +159,20 @@ public:
block_info()
: prev_id()
, already_generated_coins(0)
- , block_size(0)
+ , block_weight(0)
{
}
- block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_size)
+ block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_weight)
: prev_id(a_prev_id)
, already_generated_coins(an_already_generated_coins)
- , block_size(a_block_size)
+ , block_weight(a_block_weight)
{
}
crypto::hash prev_id;
uint64_t already_generated_coins;
- size_t block_size;
+ size_t block_weight;
};
enum block_fields
@@ -190,15 +190,15 @@ public:
};
void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
- void get_last_n_block_sizes(std::vector<size_t>& block_sizes, const crypto::hash& head, size_t n) const;
+ void get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const;
uint64_t get_already_generated_coins(const crypto::hash& blk_id) const;
uint64_t get_already_generated_coins(const cryptonote::block& blk) const;
- void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins,
+ void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_weights, uint64_t already_generated_coins,
uint8_t hf_version = 1);
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,
- std::vector<size_t>& block_sizes, const std::list<cryptonote::transaction>& tx_list);
+ std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list);
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,
const std::list<cryptonote::transaction>& tx_list = std::list<cryptonote::transaction>());
@@ -263,6 +263,30 @@ bool check_tx_verification_context(const cryptonote::tx_verification_context& tv
}
//--------------------------------------------------------------------------
template<class t_test_class>
+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>
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))
{
@@ -339,6 +363,26 @@ public:
return true;
}
+ 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;
+ }
+
bool operator()(const cryptonote::block& b) const
{
log_event("cryptonote::block");