Electroneum
Loading...
Searching...
No Matches
block_validation.h
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, The Monero Project
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without modification, are
7// permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this list of
10// conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13// of conditions and the following disclaimer in the documentation and/or other
14// materials provided with the distribution.
15//
16// 3. Neither the name of the copyright holder nor the names of its contributors may be
17// used to endorse or promote products derived from this software without specific
18// prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31
32#pragma once
33#include "chaingen.h"
34
35template<size_t invalid_block_idx = 0>
37{
38public:
43
45 {
46 if (invalid_block_idx == event_idx)
47 return bvc.m_verification_failed;
48 else
49 return !bvc.m_verification_failed;
50 }
51
52 bool check_block_purged(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
53 {
54 DEFINE_TESTS_ERROR_CONTEXT("gen_block_verification_base::check_block_purged");
55
56 CHECK_TEST_CONDITION(invalid_block_idx < ev_index);
58 CHECK_EQ(invalid_block_idx, c.get_current_blockchain_height());
59
60 return true;
61 }
62};
63
64template<size_t expected_blockchain_height>
66{
71
72 bool check_block_accepted(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& /*events*/)
73 {
74 DEFINE_TESTS_ERROR_CONTEXT("gen_block_accepted_base::check_block_accepted");
75
77 CHECK_EQ(expected_blockchain_height, c.get_current_blockchain_height());
78
79 return true;
80 }
81};
82
84{
85 bool generate(std::vector<test_event_entry>& events) const;
86};
87
89{
90 bool generate(std::vector<test_event_entry>& events) const;
91};
92
93struct gen_block_ts_not_checked : public gen_block_accepted_base<BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW>
94{
95 bool generate(std::vector<test_event_entry>& events) const;
96};
97
98struct gen_block_ts_in_past : public gen_block_verification_base<BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW>
99{
100 bool generate(std::vector<test_event_entry>& events) const;
101};
102
104{
105 bool generate(std::vector<test_event_entry>& events) const;
106};
107
109{
110 bool generate(std::vector<test_event_entry>& events) const;
111 bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/);
112};
113
115{
116 bool generate(std::vector<test_event_entry>& events) const;
117};
118
120{
121 bool generate(std::vector<test_event_entry>& events) const;
122};
123
125{
126 bool generate(std::vector<test_event_entry>& events) const;
127};
128
130{
131 bool generate(std::vector<test_event_entry>& events) const;
132};
133
135{
136 bool generate(std::vector<test_event_entry>& events) const;
137};
138
140{
141 bool generate(std::vector<test_event_entry>& events) const;
142};
143
145{
146 bool generate(std::vector<test_event_entry>& events) const;
147};
148
150{
151 bool generate(std::vector<test_event_entry>& events) const;
152};
153
155{
156 bool generate(std::vector<test_event_entry>& events) const;
157};
158
159struct gen_block_miner_tx_has_2_in : public gen_block_verification_base<CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW + 1>
160{
161 bool generate(std::vector<test_event_entry>& events) const;
162};
163
164struct gen_block_miner_tx_with_txin_to_key : public gen_block_verification_base<CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW + 2>
165{
166 bool generate(std::vector<test_event_entry>& events) const;
167};
168
170{
171 bool generate(std::vector<test_event_entry>& events) const;
172};
173
175{
176 bool generate(std::vector<test_event_entry>& events) const;
177};
178
180{
181 bool generate(std::vector<test_event_entry>& events) const;
182};
183
185{
186 bool generate(std::vector<test_event_entry>& events) const;
187};
188
190{
191 bool generate(std::vector<test_event_entry>& events) const;
192};
193
195{
196 bool generate(std::vector<test_event_entry>& events) const;
197};
198
200{
202 bool generate(std::vector<test_event_entry>& events) const;
203 bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/);
204 bool check_all_blocks_purged(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
205 bool corrupt_blocks_boundary(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
206
207private:
208 size_t m_corrupt_blocks_begin_idx;
209};
#define DEFINE_TESTS_ERROR_CONTEXT(text)
Definition chaingen.h:1056
#define CHECK_TEST_CONDITION(cond)
Definition chaingen.h:1057
#define REGISTER_CALLBACK(CB_NAME, CLBACK)
Definition chaingen.h:827
#define CHECK_EQ(v1, v2)
Definition chaingen.h:1058
handles core cryptonote functionality
size_t get_pool_transactions_count() const
get the total number of transactions in the pool
uint64_t get_current_blockchain_height() const
get the current height of the blockchain
bool check_block_purged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
bool check_block_accepted(cryptonote::core &c, size_t, const std::vector< test_event_entry > &)
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool check_all_blocks_purged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
bool corrupt_blocks_boundary(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const
bool generate(std::vector< test_event_entry > &events) const