Monero
Loading...
Searching...
No Matches
block_validation.h
Go to the documentation of this file.
1// Copyright (c) 2014-2022, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31#pragma once
32#include "chaingen.h"
33
34template<size_t invalid_block_idx = 0>
36{
37public:
42
44 {
45 if (invalid_block_idx == event_idx)
46 return bvc.m_verifivation_failed;
47 else
48 return !bvc.m_verifivation_failed;
49 }
50
51 bool check_block_purged(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
52 {
53 DEFINE_TESTS_ERROR_CONTEXT("gen_block_verification_base::check_block_purged");
54
55 CHECK_TEST_CONDITION(invalid_block_idx < ev_index);
56 CHECK_EQ(0, c.get_pool_transactions_count());
57 CHECK_EQ(invalid_block_idx, c.get_current_blockchain_height());
58
59 return true;
60 }
61};
62
63template<size_t expected_blockchain_height>
65{
70
71 bool check_block_accepted(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& /*events*/)
72 {
73 DEFINE_TESTS_ERROR_CONTEXT("gen_block_accepted_base::check_block_accepted");
74
75 CHECK_EQ(0, c.get_pool_transactions_count());
76 CHECK_EQ(expected_blockchain_height, c.get_current_blockchain_height());
77
78 return true;
79 }
80};
81
83{
84 bool generate(std::vector<test_event_entry>& events) const;
85};
86
88{
89 bool generate(std::vector<test_event_entry>& events) const;
90};
91
92struct gen_block_ts_not_checked : public gen_block_accepted_base<BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW>
93{
94 bool generate(std::vector<test_event_entry>& events) const;
95};
96
97struct gen_block_ts_in_past : public gen_block_verification_base<BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW>
98{
99 bool generate(std::vector<test_event_entry>& events) const;
100};
101
103{
104 bool generate(std::vector<test_event_entry>& events) const;
105};
106
108{
109 bool generate(std::vector<test_event_entry>& events) const;
110 bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/);
111};
112
114{
115 bool generate(std::vector<test_event_entry>& events) const;
116};
117
119{
120 bool generate(std::vector<test_event_entry>& events) const;
121};
122
124{
125 bool generate(std::vector<test_event_entry>& events) const;
126};
127
129{
130 bool generate(std::vector<test_event_entry>& events) const;
131};
132
134{
135 bool generate(std::vector<test_event_entry>& events) const;
136};
137
139{
140 bool generate(std::vector<test_event_entry>& events) const;
141};
142
144{
145 bool generate(std::vector<test_event_entry>& events) const;
146};
147
149{
150 bool generate(std::vector<test_event_entry>& events) const;
151};
152
154{
155 bool generate(std::vector<test_event_entry>& events) const;
156};
157
158struct gen_block_miner_tx_has_2_in : public gen_block_verification_base<CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW + 1>
159{
160 bool generate(std::vector<test_event_entry>& events) const;
161};
162
163struct gen_block_miner_tx_with_txin_to_key : public gen_block_verification_base<CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW + 2>
164{
165 bool generate(std::vector<test_event_entry>& events) const;
166};
167
169{
170 bool generate(std::vector<test_event_entry>& events) const;
171};
172
174{
175 bool generate(std::vector<test_event_entry>& events) const;
176};
177
179{
180 bool generate(std::vector<test_event_entry>& events) const;
181};
182
184{
185 bool generate(std::vector<test_event_entry>& events) const;
186};
187
189{
190 bool generate(std::vector<test_event_entry>& events) const;
191};
192
194{
195 bool generate(std::vector<test_event_entry>& events) const;
196};
197
199{
201 bool generate(std::vector<test_event_entry>& events) const;
202 bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/);
203 bool check_all_blocks_purged(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
204 bool corrupt_blocks_boundary(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
205
206private:
208};
209
211{
212 bool generate(std::vector<test_event_entry>& events) const;
213};
214template<>
216 const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_MIN_V2_COINBASE_TX, 1), std::make_pair(0, 0)};
220};
221
223{
224 bool generate(std::vector<test_event_entry>& events) const;
225};
226template<>
228 const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_EXACT_COINBASE, 1), std::make_pair(0, 0)};
232};
233
235{
236 bool generate(std::vector<test_event_entry>& events) const;
237};
238
240{
241 bool generate(std::vector<test_event_entry>& events) const;
242};
243template<>
245 const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_VIEW_TAGS+1, 1), std::make_pair(0, 0)};
249};
250
252{
253 bool generate(std::vector<test_event_entry>& events) const;
254};
255
257{
258 bool generate(std::vector<test_event_entry>& events) const;
259};
260template<>
262 const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(HF_VERSION_VIEW_TAGS, 1), std::make_pair(0, 0)};
266};
#define DEFINE_TESTS_ERROR_CONTEXT(text)
Definition chaingen.h:1087
#define CHECK_TEST_CONDITION(cond)
Definition chaingen.h:1088
#define REGISTER_CALLBACK(CB_NAME, CLBACK)
Definition chaingen.h:856
#define CHECK_EQ(v1, v2)
Definition chaingen.h:1089
handles core cryptonote functionality
Definition cryptonote_core.h:87
gen_block_verification_base()
Definition block_validation.h:38
bool check_block_purged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition block_validation.h:51
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition block_validation.h:43
Definition chaingen.h:166
#define HF_VERSION_MIN_V2_COINBASE_TX
Definition cryptonote_config.h:184
#define HF_VERSION_VIEW_TAGS
Definition cryptonote_config.h:193
#define HF_VERSION_EXACT_COINBASE
Definition cryptonote_config.h:189
Definition verification_context.h:66
bool m_verifivation_failed
Definition verification_context.h:68
Definition cryptonote_basic.h:475
Definition cryptonote_core.h:61
bool check_block_accepted(cryptonote::core &c, size_t, const std::vector< test_event_entry > &)
Definition block_validation.h:71
gen_block_accepted_base()
Definition block_validation.h:66
Definition block_validation.h:83
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:77
Definition block_validation.h:88
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:90
Definition block_validation.h:189
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:488
Definition block_validation.h:149
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:294
Definition block_validation.h:144
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:278
bool check_all_blocks_purged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition block_validation.cpp:634
size_t m_corrupt_blocks_begin_idx
Definition block_validation.h:207
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition block_validation.cpp:614
bool corrupt_blocks_boundary(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition block_validation.cpp:628
gen_block_invalid_binary_format()
Definition block_validation.cpp:544
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:551
Definition block_validation.h:114
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:168
Definition block_validation.h:108
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:145
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition block_validation.cpp:160
Definition block_validation.h:194
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:504
Definition block_validation.h:211
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:644
Definition block_validation.h:223
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:659
Definition block_validation.h:159
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:329
Definition block_validation.h:154
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:310
Definition block_validation.h:179
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:443
Definition block_validation.h:184
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:459
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:675
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:702
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:730
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:761
Definition block_validation.h:174
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:427
Definition block_validation.h:169
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:411
Definition block_validation.h:164
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:368
Definition block_validation.h:119
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:198
Definition block_validation.h:103
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:132
Definition block_validation.h:98
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:117
Definition block_validation.h:93
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:103
Definition block_validation.h:129
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:230
Definition block_validation.h:124
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:214
Definition block_validation.h:139
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:262
Definition block_validation.h:134
bool generate(std::vector< test_event_entry > &events) const
Definition block_validation.cpp:246
const cryptonote::test_options test_options
Definition block_validation.h:217
const std::pair< uint8_t, uint64_t > hard_forks[3]
Definition block_validation.h:216
const std::pair< uint8_t, uint64_t > hard_forks[3]
Definition block_validation.h:228
const cryptonote::test_options test_options
Definition block_validation.h:229
const cryptonote::test_options test_options
Definition block_validation.h:246
const std::pair< uint8_t, uint64_t > hard_forks[3]
Definition block_validation.h:245
const cryptonote::test_options test_options
Definition block_validation.h:263
const std::pair< uint8_t, uint64_t > hard_forks[3]
Definition block_validation.h:262