Bitcoin Core 30.99.0
P2P Digital Currency
test_kernel.cpp
Go to the documentation of this file.
1// Copyright (c) 2024-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
7
8#define BOOST_TEST_MODULE Bitcoin Kernel Test Suite
9#include <boost/test/included/unit_test.hpp>
10
12
13#include <charconv>
14#include <cstdint>
15#include <cstdlib>
16#include <filesystem>
17#include <format>
18#include <iostream>
19#include <memory>
20#include <optional>
21#include <random>
22#include <ranges>
23#include <span>
24#include <string>
25#include <string_view>
26#include <vector>
27
28using namespace btck;
29
30std::string random_string(uint32_t length)
31{
32 const std::string chars = "0123456789"
33 "abcdefghijklmnopqrstuvwxyz"
34 "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
35
36 static std::random_device rd;
37 static std::default_random_engine dre{rd()};
38 static std::uniform_int_distribution<> distribution(0, chars.size() - 1);
39
40 std::string random;
41 random.reserve(length);
42 for (uint32_t i = 0; i < length; i++) {
43 random += chars[distribution(dre)];
44 }
45 return random;
46}
47
48std::vector<std::byte> hex_string_to_byte_vec(std::string_view hex)
49{
50 std::vector<std::byte> bytes;
51 bytes.reserve(hex.length() / 2);
52
53 for (size_t i{0}; i < hex.length(); i += 2) {
54 uint8_t byte_value;
55 auto [ptr, ec] = std::from_chars(hex.data() + i, hex.data() + i + 2, byte_value, 16);
56
57 if (ec != std::errc{} || ptr != hex.data() + i + 2) {
58 throw std::invalid_argument("Invalid hex character");
59 }
60 bytes.push_back(static_cast<std::byte>(byte_value));
61 }
62 return bytes;
63}
64
65std::string byte_span_to_hex_string_reversed(std::span<const std::byte> bytes)
66{
67 std::ostringstream oss;
68
69 // Iterate in reverse order
70 for (auto it = bytes.rbegin(); it != bytes.rend(); ++it) {
71 oss << std::hex << std::setw(2) << std::setfill('0')
72 << static_cast<unsigned int>(static_cast<uint8_t>(*it));
73 }
74
75 return oss.str();
76}
77
78constexpr auto VERIFY_ALL_PRE_SEGWIT{ScriptVerificationFlags::P2SH | ScriptVerificationFlags::DERSIG |
79 ScriptVerificationFlags::NULLDUMMY | ScriptVerificationFlags::CHECKLOCKTIMEVERIFY |
80 ScriptVerificationFlags::CHECKSEQUENCEVERIFY};
81constexpr auto VERIFY_ALL_PRE_TAPROOT{VERIFY_ALL_PRE_SEGWIT | ScriptVerificationFlags::WITNESS};
82
83void check_equal(std::span<const std::byte> _actual, std::span<const std::byte> _expected, bool equal = true)
84{
85 std::span<const uint8_t> actual{reinterpret_cast<const unsigned char*>(_actual.data()), _actual.size()};
86 std::span<const uint8_t> expected{reinterpret_cast<const unsigned char*>(_expected.data()), _expected.size()};
87 BOOST_CHECK_EQUAL_COLLECTIONS(
88 actual.begin(), actual.end(),
89 expected.begin(), expected.end());
90}
91
93{
94public:
95 void LogMessage(std::string_view message)
96 {
97 std::cout << "kernel: " << message;
98 }
99};
100
102 std::filesystem::path m_directory;
103 TestDirectory(std::string directory_name)
104 : m_directory{std::filesystem::temp_directory_path() / (directory_name + random_string(16))}
105 {
106 std::filesystem::create_directories(m_directory);
107 }
108
110 {
111 std::filesystem::remove_all(m_directory);
112 }
113};
114
116{
117public:
118 void HeaderTipHandler(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override
119 {
120 BOOST_CHECK_GT(timestamp, 0);
121 }
122
123 void WarningSetHandler(Warning warning, std::string_view message) override
124 {
125 std::cout << "Kernel warning is set: " << message << std::endl;
126 }
127
128 void WarningUnsetHandler(Warning warning) override
129 {
130 std::cout << "Kernel warning was unset." << std::endl;
131 }
132
133 void FlushErrorHandler(std::string_view error) override
134 {
135 std::cout << error << std::endl;
136 }
137
138 void FatalErrorHandler(std::string_view error) override
139 {
140 std::cout << error << std::endl;
141 }
142};
143
145{
146public:
147 std::optional<std::vector<std::byte>> m_expected_valid_block = std::nullopt;
148
149 void BlockChecked(Block block, const BlockValidationState state) override
150 {
151 if (m_expected_valid_block.has_value()) {
152 auto ser_block{block.ToBytes()};
153 check_equal(m_expected_valid_block.value(), ser_block);
154 }
155
156 auto mode{state.GetValidationMode()};
157 switch (mode) {
158 case ValidationMode::VALID: {
159 std::cout << "Valid block" << std::endl;
160 return;
161 }
162 case ValidationMode::INVALID: {
163 std::cout << "Invalid block: ";
164 auto result{state.GetBlockValidationResult()};
165 switch (result) {
166 case BlockValidationResult::UNSET:
167 std::cout << "initial value. Block has not yet been rejected" << std::endl;
168 break;
169 case BlockValidationResult::HEADER_LOW_WORK:
170 std::cout << "the block header may be on a too-little-work chain" << std::endl;
171 break;
172 case BlockValidationResult::CONSENSUS:
173 std::cout << "invalid by consensus rules (excluding any below reasons)" << std::endl;
174 break;
175 case BlockValidationResult::CACHED_INVALID:
176 std::cout << "this block was cached as being invalid and we didn't store the reason why" << std::endl;
177 break;
178 case BlockValidationResult::INVALID_HEADER:
179 std::cout << "invalid proof of work or time too old" << std::endl;
180 break;
181 case BlockValidationResult::MUTATED:
182 std::cout << "the block's data didn't match the data committed to by the PoW" << std::endl;
183 break;
184 case BlockValidationResult::MISSING_PREV:
185 std::cout << "We don't have the previous block the checked one is built on" << std::endl;
186 break;
187 case BlockValidationResult::INVALID_PREV:
188 std::cout << "A block this one builds on is invalid" << std::endl;
189 break;
190 case BlockValidationResult::TIME_FUTURE:
191 std::cout << "block timestamp was > 2 hours in the future (or our clock is bad)" << std::endl;
192 break;
193 }
194 return;
195 }
196 case ValidationMode::INTERNAL_ERROR: {
197 std::cout << "Internal error" << std::endl;
198 return;
199 }
200 }
201 }
202
203 void BlockConnected(Block block, BlockTreeEntry entry) override
204 {
205 std::cout << "Block connected." << std::endl;
206 }
207
208 void PowValidBlock(BlockTreeEntry entry, Block block) override
209 {
210 std::cout << "Block passed pow verification" << std::endl;
211 }
212
213 void BlockDisconnected(Block block, BlockTreeEntry entry) override
214 {
215 std::cout << "Block disconnected." << std::endl;
216 }
217};
218
220 const ScriptPubkey& spent_script_pubkey,
221 const Transaction& spending_tx,
222 std::span<TransactionOutput> spent_outputs,
223 int64_t amount,
224 unsigned int input_index,
225 bool taproot)
226{
227 auto status = ScriptVerifyStatus::OK;
228
229 if (taproot) {
230 BOOST_CHECK(spent_script_pubkey.Verify(
231 amount,
232 spending_tx,
233 spent_outputs,
234 input_index,
236 status));
237 BOOST_CHECK(status == ScriptVerifyStatus::OK);
238 } else {
239 BOOST_CHECK(!spent_script_pubkey.Verify(
240 amount,
241 spending_tx,
242 spent_outputs,
243 input_index,
245 status));
246 BOOST_CHECK(status == ScriptVerifyStatus::ERROR_SPENT_OUTPUTS_REQUIRED);
247 }
248
249 BOOST_CHECK(spent_script_pubkey.Verify(
250 amount,
251 spending_tx,
252 spent_outputs,
253 input_index,
255 status));
256 BOOST_CHECK(status == ScriptVerifyStatus::OK);
257
258 BOOST_CHECK(spent_script_pubkey.Verify(
259 0,
260 spending_tx,
261 spent_outputs,
262 input_index,
264 status));
265 BOOST_CHECK(status == ScriptVerifyStatus::OK);
266}
267
268template <typename T>
269concept HasToBytes = requires(T t) {
270 { t.ToBytes() } -> std::convertible_to<std::vector<std::byte>>;
271};
272
273template <typename T>
274void CheckHandle(T object, T distinct_object)
275{
276 BOOST_CHECK(object.get() != nullptr);
277 BOOST_CHECK(distinct_object.get() != nullptr);
278 BOOST_CHECK(object.get() != distinct_object.get());
279
280 if constexpr (HasToBytes<T>) {
281 BOOST_CHECK_NE(object.ToBytes().size(), distinct_object.ToBytes().size());
282 }
283
284 // Copy constructor
285 T object2(distinct_object);
286 BOOST_CHECK_NE(distinct_object.get(), object2.get());
287 if constexpr (HasToBytes<T>) {
288 check_equal(distinct_object.ToBytes(), object2.ToBytes());
289 }
290
291 // Copy assignment
292 T object3{distinct_object};
293 object2 = object3;
294 BOOST_CHECK_NE(object3.get(), object2.get());
295 if constexpr (HasToBytes<T>) {
296 check_equal(object3.ToBytes(), object2.ToBytes());
297 }
298
299 // Move constructor
300 auto* original_ptr = object2.get();
301 T object4{std::move(object2)};
302 BOOST_CHECK_EQUAL(object4.get(), original_ptr);
303 BOOST_CHECK_EQUAL(object2.get(), nullptr); // NOLINT(bugprone-use-after-move)
304 if constexpr (HasToBytes<T>) {
305 check_equal(object4.ToBytes(), object3.ToBytes());
306 }
307
308 // Move assignment
309 original_ptr = object4.get();
310 object2 = std::move(object4);
311 BOOST_CHECK_EQUAL(object2.get(), original_ptr);
312 BOOST_CHECK_EQUAL(object4.get(), nullptr); // NOLINT(bugprone-use-after-move)
313 if constexpr (HasToBytes<T>) {
314 check_equal(object2.ToBytes(), object3.ToBytes());
315 }
316}
317
318template <typename RangeType>
319 requires std::ranges::random_access_range<RangeType>
320void CheckRange(const RangeType& range, size_t expected_size)
321{
322 using value_type = std::ranges::range_value_t<RangeType>;
323
324 BOOST_CHECK_EQUAL(range.size(), expected_size);
325 BOOST_CHECK_EQUAL(range.empty(), (expected_size == 0));
326
327 BOOST_CHECK(range.begin() != range.end());
328 BOOST_CHECK_EQUAL(std::distance(range.begin(), range.end()), static_cast<std::ptrdiff_t>(expected_size));
329 BOOST_CHECK(range.cbegin() == range.begin());
330 BOOST_CHECK(range.cend() == range.end());
331
332 for (size_t i = 0; i < range.size(); ++i) {
333 BOOST_CHECK_EQUAL(range[i].get(), (*(range.begin() + i)).get());
334 }
335
336 BOOST_CHECK_NE(range.at(0).get(), range.at(expected_size - 1).get());
337 BOOST_CHECK_THROW(range.at(expected_size), std::out_of_range);
338
339 BOOST_CHECK_EQUAL(range.front().get(), range[0].get());
340 BOOST_CHECK_EQUAL(range.back().get(), range[expected_size - 1].get());
341
342 auto it = range.begin();
343 auto it_copy = it;
344 ++it;
345 BOOST_CHECK(it != it_copy);
346 --it;
347 BOOST_CHECK(it == it_copy);
348 it = range.begin();
349 auto old_it = it++;
350 BOOST_CHECK(old_it == range.begin());
351 BOOST_CHECK(it == range.begin() + 1);
352 old_it = it--;
353 BOOST_CHECK(old_it == range.begin() + 1);
354 BOOST_CHECK(it == range.begin());
355
356 it = range.begin();
357 it += 2;
358 BOOST_CHECK(it == range.begin() + 2);
359 it -= 2;
360 BOOST_CHECK(it == range.begin());
361
362 BOOST_CHECK(range.begin() < range.end());
363 BOOST_CHECK(range.begin() <= range.end());
364 BOOST_CHECK(range.end() > range.begin());
365 BOOST_CHECK(range.end() >= range.begin());
366 BOOST_CHECK(range.begin() == range.begin());
367
368 BOOST_CHECK_EQUAL(range.begin()[0].get(), range[0].get());
369
370 size_t count = 0;
371 for (auto rit = range.end(); rit != range.begin();) {
372 --rit;
373 ++count;
374 }
375 BOOST_CHECK_EQUAL(count, expected_size);
376
377 std::vector<value_type> collected;
378 for (const auto& elem : range) {
379 collected.push_back(elem);
380 }
381 BOOST_CHECK_EQUAL(collected.size(), expected_size);
382
383 BOOST_CHECK_EQUAL(std::ranges::size(range), expected_size);
384
385 it = range.begin();
386 auto it2 = 1 + it;
387 BOOST_CHECK(it2 == it + 1);
388}
389
390BOOST_AUTO_TEST_CASE(btck_transaction_tests)
391{
392 auto tx_data{hex_string_to_byte_vec("02000000013f7cebd65c27431a90bba7f796914fe8cc2ddfc3f2cbd6f7e5f2fc854534da95000000006b483045022100de1ac3bcdfb0332207c4a91f3832bd2c2915840165f876ab47c5f8996b971c3602201c6c053d750fadde599e6f5c4e1963df0f01fc0d97815e8157e3d59fe09ca30d012103699b464d1d8bc9e47d4fb1cdaa89a1c5783d68363c4dbc4b524ed3d857148617feffffff02836d3c01000000001976a914fc25d6d5c94003bf5b0c7b640a248e2c637fcfb088ac7ada8202000000001976a914fbed3d9b11183209a57999d54d59f67c019e756c88ac6acb0700")};
393 auto tx{Transaction{tx_data}};
394 auto tx_data_2{hex_string_to_byte_vec("02000000000101904f4ee5c87d20090b642f116e458cd6693292ad9ece23e72f15fb6c05b956210500000000fdffffff02e2010000000000002251200839a723933b56560487ec4d67dda58f09bae518ffa7e148313c5696ac837d9f10060000000000002251205826bcdae7abfb1c468204170eab00d887b61ab143464a4a09e1450bdc59a3340140f26e7af574e647355830772946356c27e7bbc773c5293688890f58983499581be84de40be7311a14e6d6422605df086620e75adae84ff06b75ce5894de5e994a00000000")};
395 auto tx2{Transaction{tx_data_2}};
396 CheckHandle(tx, tx2);
397
398 BOOST_CHECK_EQUAL(tx.CountOutputs(), 2);
399 BOOST_CHECK_EQUAL(tx.CountInputs(), 1);
400 auto broken_tx_data{std::span<std::byte>{tx_data.begin(), tx_data.begin() + 10}};
401 BOOST_CHECK_THROW(Transaction{broken_tx_data}, std::runtime_error);
402 auto output{tx.GetOutput(tx.CountOutputs() - 1)};
403 BOOST_CHECK_EQUAL(output.Amount(), 42130042);
404 auto script_pubkey{output.GetScriptPubkey()};
405 {
406 auto tx_new{Transaction{tx_data}};
407 // This is safe, because we now use copy assignment
408 TransactionOutput output = tx_new.GetOutput(tx_new.CountOutputs() - 1);
410
411 TransactionOutputView output2 = tx_new.GetOutput(tx_new.CountOutputs() - 1);
412 BOOST_CHECK_NE(output.get(), output2.get());
413 BOOST_CHECK_EQUAL(output.Amount(), output2.Amount());
414 TransactionOutput output3 = output2;
415 BOOST_CHECK_NE(output3.get(), output2.get());
416 BOOST_CHECK_EQUAL(output3.Amount(), output2.Amount());
417
418 // Non-owned view
419 ScriptPubkeyView script2 = output.GetScriptPubkey();
420 BOOST_CHECK_NE(script.get(), script2.get());
421 check_equal(script.ToBytes(), script2.ToBytes());
422
423 // Non-owned to owned
424 ScriptPubkey script3 = script2;
425 BOOST_CHECK_NE(script3.get(), script2.get());
426 check_equal(script3.ToBytes(), script2.ToBytes());
427 }
428 BOOST_CHECK_EQUAL(output.Amount(), 42130042);
429
430 auto tx_roundtrip{Transaction{tx.ToBytes()}};
431 check_equal(tx_roundtrip.ToBytes(), tx_data);
432
433 // The following code is unsafe, but left here to show limitations of the
434 // API, because we preserve the output view beyond the lifetime of the
435 // transaction. The view type wrapper should make this clear to the user.
436 // auto get_output = [&]() -> TransactionOutputView {
437 // auto tx{Transaction{tx_data}};
438 // return tx.GetOutput(0);
439 // };
440 // auto output_new = get_output();
441 // BOOST_CHECK_EQUAL(output_new.Amount(), 20737411);
442
443 int64_t total_amount{0};
444 for (const auto output : tx.Outputs()) {
445 total_amount += output.Amount();
446 }
447 BOOST_CHECK_EQUAL(total_amount, 62867453);
448
449 auto amount = *(tx.Outputs() | std::ranges::views::filter([](const auto& output) {
450 return output.Amount() == 42130042;
451 }) |
452 std::views::transform([](const auto& output) {
453 return output.Amount();
454 })).begin();
455 BOOST_REQUIRE(amount);
456 BOOST_CHECK_EQUAL(amount, 42130042);
457
458 CheckRange(tx.Outputs(), tx.CountOutputs());
459
460 ScriptPubkey script_pubkey_roundtrip{script_pubkey.ToBytes()};
461 check_equal(script_pubkey_roundtrip.ToBytes(), script_pubkey.ToBytes());
462}
463
464BOOST_AUTO_TEST_CASE(btck_script_pubkey)
465{
466 auto script_data{hex_string_to_byte_vec("76a9144bfbaf6afb76cc5771bc6404810d1cc041a6933988ac")};
467 std::vector<std::byte> script_data_2 = script_data;
468 script_data_2.push_back(std::byte{0x51});
469 ScriptPubkey script{script_data};
470 ScriptPubkey script2{script_data_2};
471 CheckHandle(script, script2);
472}
473
474BOOST_AUTO_TEST_CASE(btck_transaction_output)
475{
476 ScriptPubkey script{hex_string_to_byte_vec("76a9144bfbaf6afb76cc5771bc6404810d1cc041a6933988ac")};
477 TransactionOutput output{script, 1};
478 TransactionOutput output2{script, 2};
479 CheckHandle(output, output2);
480}
481
482BOOST_AUTO_TEST_CASE(btck_transaction_input)
483{
484 Transaction tx{hex_string_to_byte_vec("020000000248c03e66fd371c7033196ce24298628e59ebefa00363026044e0f35e0325a65d000000006a473044022004893432347f39beaa280e99da595681ddb20fc45010176897e6e055d716dbfa022040a9e46648a5d10c33ef7cee5e6cf4b56bd513eae3ae044f0039824b02d0f44c012102982331a52822fd9b62e9b5d120da1d248558fac3da3a3c51cd7d9c8ad3da760efeffffffb856678c6e4c3c84e39e2ca818807049d6fba274b42af3c6d3f9d4b6513212d2000000006a473044022068bcedc7fe39c9f21ad318df2c2da62c2dc9522a89c28c8420ff9d03d2e6bf7b0220132afd752754e5cb1ea2fd0ed6a38ec666781e34b0e93dc9a08f2457842cf5660121033aeb9c079ea3e08ea03556182ab520ce5c22e6b0cb95cee6435ee17144d860cdfeffffff0260d50b00000000001976a914363cc8d55ea8d0500de728ef6d63804ddddbdc9888ac67040f00000000001976a914c303bdc5064bf9c9a8b507b5496bd0987285707988ac6acb0700")};
485 TransactionInput input_0 = tx.GetInput(0);
486 TransactionInput input_1 = tx.GetInput(1);
487 CheckHandle(input_0, input_1);
488 CheckRange(tx.Inputs(), tx.CountInputs());
489 OutPoint point_0 = input_0.OutPoint();
490 OutPoint point_1 = input_1.OutPoint();
491 CheckHandle(point_0, point_1);
492}
493
494BOOST_AUTO_TEST_CASE(btck_script_verify_tests)
495{
496 // Legacy transaction aca326a724eda9a461c10a876534ecd5ae7b27f10f26c3862fb996f80ea2d45d
498 /*spent_script_pubkey*/ ScriptPubkey{hex_string_to_byte_vec("76a9144bfbaf6afb76cc5771bc6404810d1cc041a6933988ac")},
499 /*spending_tx*/ Transaction{hex_string_to_byte_vec("02000000013f7cebd65c27431a90bba7f796914fe8cc2ddfc3f2cbd6f7e5f2fc854534da95000000006b483045022100de1ac3bcdfb0332207c4a91f3832bd2c2915840165f876ab47c5f8996b971c3602201c6c053d750fadde599e6f5c4e1963df0f01fc0d97815e8157e3d59fe09ca30d012103699b464d1d8bc9e47d4fb1cdaa89a1c5783d68363c4dbc4b524ed3d857148617feffffff02836d3c01000000001976a914fc25d6d5c94003bf5b0c7b640a248e2c637fcfb088ac7ada8202000000001976a914fbed3d9b11183209a57999d54d59f67c019e756c88ac6acb0700")},
500 /*spent_outputs*/ {},
501 /*amount*/ 0,
502 /*input_index*/ 0,
503 /*is_taproot*/ false);
504
505 // Segwit transaction 1a3e89644985fbbb41e0dcfe176739813542b5937003c46a07de1e3ee7a4a7f3
507 /*spent_script_pubkey*/ ScriptPubkey{hex_string_to_byte_vec("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d")},
508 /*spending_tx*/ Transaction{hex_string_to_byte_vec("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000")},
509 /*spent_outputs*/ {},
510 /*amount*/ 18393430,
511 /*input_index*/ 0,
512 /*is_taproot*/ false);
513
514 // Taproot transaction 33e794d097969002ee05d336686fc03c9e15a597c1b9827669460fac98799036
515 auto taproot_spent_script_pubkey{ScriptPubkey{hex_string_to_byte_vec("5120339ce7e165e67d93adb3fef88a6d4beed33f01fa876f05a225242b82a631abc0")}};
516 std::vector<TransactionOutput> spent_outputs;
517 spent_outputs.emplace_back(taproot_spent_script_pubkey, 88480);
519 /*spent_script_pubkey*/ taproot_spent_script_pubkey,
520 /*spending_tx*/ Transaction{hex_string_to_byte_vec("01000000000101d1f1c1f8cdf6759167b90f52c9ad358a369f95284e841d7a2536cef31c0549580100000000fdffffff020000000000000000316a2f49206c696b65205363686e6f7272207369677320616e6420492063616e6e6f74206c69652e204062697462756734329e06010000000000225120a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f90140a60c383f71bac0ec919b1d7dbc3eb72dd56e7aa99583615564f9f99b8ae4e837b758773a5b2e4c51348854c8389f008e05029db7f464a5ff2e01d5e6e626174affd30a00")},
521 /*spent_outputs*/ spent_outputs,
522 /*amount*/ 88480,
523 /*input_index*/ 0,
524 /*is_taproot*/ true);
525}
526
528{
529 btck_LoggingOptions logging_options = {
530 .log_timestamps = true,
531 .log_time_micros = true,
532 .log_threadnames = false,
533 .log_sourcelocations = false,
534 .always_print_category_levels = true,
535 };
536
537 logging_set_options(logging_options);
538 logging_set_level_category(LogCategory::BENCH, LogLevel::TRACE_LEVEL);
542
543 // Check that connecting, connecting another, and then disconnecting and connecting a logger again works.
544 {
545 logging_set_level_category(LogCategory::KERNEL, LogLevel::TRACE_LEVEL);
547 Logger logger{std::make_unique<TestLog>()};
548 Logger logger_2{std::make_unique<TestLog>()};
549 }
550 Logger logger{std::make_unique<TestLog>()};
551}
552
553BOOST_AUTO_TEST_CASE(btck_context_tests)
554{
555 { // test default context
556 Context context{};
557 Context context2{};
558 CheckHandle(context, context2);
559 }
560
561 { // test with context options, but not options set
562 ContextOptions options{};
563 Context context{options};
564 }
565
566 { // test with context options
567 ContextOptions options{};
568 ChainParams params{ChainType::MAINNET};
569 ChainParams regtest_params{ChainType::REGTEST};
570 CheckHandle(params, regtest_params);
571 options.SetChainParams(params);
572 options.SetNotifications(std::make_shared<TestKernelNotifications>());
573 Context context{options};
574 }
575}
576
578{
581 CheckHandle(block, block_100);
583 CheckRange(block_tx.Transactions(), block_tx.CountTransactions());
584}
585
586Context create_context(std::shared_ptr<TestKernelNotifications> notifications, ChainType chain_type, std::shared_ptr<TestValidationInterface> validation_interface = nullptr)
587{
588 ContextOptions options{};
589 ChainParams params{chain_type};
590 options.SetChainParams(params);
591 options.SetNotifications(notifications);
592 if (validation_interface) {
593 options.SetValidationInterface(validation_interface);
594 }
595 auto context{Context{options}};
596 return context;
597}
598
599BOOST_AUTO_TEST_CASE(btck_chainman_tests)
600{
601 Logger logger{std::make_unique<TestLog>()};
602 auto test_directory{TestDirectory{"chainman_test_bitcoin_kernel"}};
603
604 { // test with default context
605 Context context{};
606 ChainstateManagerOptions chainman_opts{context, test_directory.m_directory.string(), (test_directory.m_directory / "blocks").string()};
607 ChainMan chainman{context, chainman_opts};
608 }
609
610 { // test with default context options
611 ContextOptions options{};
612 Context context{options};
613 ChainstateManagerOptions chainman_opts{context, test_directory.m_directory.string(), (test_directory.m_directory / "blocks").string()};
614 ChainMan chainman{context, chainman_opts};
615 }
616
617 auto notifications{std::make_shared<TestKernelNotifications>()};
618 auto context{create_context(notifications, ChainType::MAINNET)};
619
620 ChainstateManagerOptions chainman_opts{context, test_directory.m_directory.string(), (test_directory.m_directory / "blocks").string()};
621 chainman_opts.SetWorkerThreads(4);
622 BOOST_CHECK(!chainman_opts.SetWipeDbs(/*wipe_block_tree=*/true, /*wipe_chainstate=*/false));
623 BOOST_CHECK(chainman_opts.SetWipeDbs(/*wipe_block_tree=*/true, /*wipe_chainstate=*/true));
624 BOOST_CHECK(chainman_opts.SetWipeDbs(/*wipe_block_tree=*/false, /*wipe_chainstate=*/true));
625 BOOST_CHECK(chainman_opts.SetWipeDbs(/*wipe_block_tree=*/false, /*wipe_chainstate=*/false));
626 ChainMan chainman{context, chainman_opts};
627}
628
629std::unique_ptr<ChainMan> create_chainman(TestDirectory& test_directory,
630 bool reindex,
631 bool wipe_chainstate,
632 bool block_tree_db_in_memory,
633 bool chainstate_db_in_memory,
634 Context& context)
635{
636 ChainstateManagerOptions chainman_opts{context, test_directory.m_directory.string(), (test_directory.m_directory / "blocks").string()};
637
638 if (reindex) {
639 chainman_opts.SetWipeDbs(/*wipe_block_tree=*/reindex, /*wipe_chainstate=*/reindex);
640 }
641 if (wipe_chainstate) {
642 chainman_opts.SetWipeDbs(/*wipe_block_tree=*/false, /*wipe_chainstate=*/wipe_chainstate);
643 }
644 if (block_tree_db_in_memory) {
645 chainman_opts.UpdateBlockTreeDbInMemory(block_tree_db_in_memory);
646 }
647 if (chainstate_db_in_memory) {
648 chainman_opts.UpdateChainstateDbInMemory(chainstate_db_in_memory);
649 }
650
651 auto chainman{std::make_unique<ChainMan>(context, chainman_opts)};
652 return chainman;
653}
654
656{
657 auto notifications{std::make_shared<TestKernelNotifications>()};
658 auto context{create_context(notifications, ChainType::MAINNET)};
659 auto chainman{create_chainman(test_directory, true, false, false, false, context)};
660
661 std::vector<std::string> import_files;
662 BOOST_CHECK(chainman->ImportBlocks(import_files));
663
664 // Sanity check some block retrievals
665 auto chain{chainman->GetChain()};
666 BOOST_CHECK_THROW(chain.GetByHeight(1000), std::runtime_error);
667 auto genesis_index{chain.Genesis()};
668 BOOST_CHECK(!genesis_index.GetPrevious());
669 auto genesis_block_raw{chainman->ReadBlock(genesis_index).value().ToBytes()};
670 auto first_index{chain.GetByHeight(0)};
671 auto first_block_raw{chainman->ReadBlock(genesis_index).value().ToBytes()};
672 check_equal(genesis_block_raw, first_block_raw);
673 auto height{first_index.GetHeight()};
674 BOOST_CHECK_EQUAL(height, 0);
675
676 auto next_index{chain.GetByHeight(first_index.GetHeight() + 1)};
677 BOOST_CHECK(chain.Contains(next_index));
678 auto next_block_data{chainman->ReadBlock(next_index).value().ToBytes()};
679 auto tip_index{chain.Tip()};
680 auto tip_block_data{chainman->ReadBlock(tip_index).value().ToBytes()};
681 auto second_index{chain.GetByHeight(1)};
682 auto second_block{chainman->ReadBlock(second_index).value()};
683 auto second_block_data{second_block.ToBytes()};
684 auto second_height{second_index.GetHeight()};
685 BOOST_CHECK_EQUAL(second_height, 1);
686 check_equal(next_block_data, tip_block_data);
687 check_equal(next_block_data, second_block_data);
688
689 auto second_hash{second_index.GetHash()};
690 auto another_second_index{chainman->GetBlockTreeEntry(second_hash)};
691 BOOST_CHECK(another_second_index);
692 auto another_second_height{another_second_index->GetHeight()};
693 auto second_block_hash{second_block.GetHash()};
694 check_equal(second_block_hash.ToBytes(), second_hash.ToBytes());
695 BOOST_CHECK_EQUAL(second_height, another_second_height);
696}
697
699{
700 auto notifications{std::make_shared<TestKernelNotifications>()};
701 auto context{create_context(notifications, ChainType::MAINNET)};
702 auto chainman{create_chainman(test_directory, false, true, false, false, context)};
703
704 std::vector<std::string> import_files;
705 import_files.push_back((test_directory.m_directory / "blocks" / "blk00000.dat").string());
706 BOOST_CHECK(chainman->ImportBlocks(import_files));
707}
708
710{
711 auto notifications{std::make_shared<TestKernelNotifications>()};
712 auto validation_interface{std::make_shared<TestValidationInterface>()};
713 auto context{create_context(notifications, ChainType::MAINNET, validation_interface)};
714 auto chainman{create_chainman(test_directory, false, false, false, false, context)};
715
716 {
717 // Process an invalid block
718 auto raw_block = hex_string_to_byte_vec("012300");
719 BOOST_CHECK_THROW(Block{raw_block}, std::runtime_error);
720 }
721 {
722 // Process an empty block
723 auto raw_block = hex_string_to_byte_vec("");
724 BOOST_CHECK_THROW(Block{raw_block}, std::runtime_error);
725 }
726
727 // mainnet block 1
728 auto raw_block = hex_string_to_byte_vec("010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e362990101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000");
729 Block block{raw_block};
730 TransactionView tx{block.GetTransaction(block.CountTransactions() - 1)};
731 BOOST_CHECK_EQUAL(byte_span_to_hex_string_reversed(tx.Txid().ToBytes()), "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098");
732 BOOST_CHECK_EQUAL(tx.CountInputs(), 1);
733 Transaction tx2 = tx;
735 for (auto transaction : block.Transactions()) {
736 BOOST_CHECK_EQUAL(transaction.CountInputs(), 1);
737 }
738 auto output_counts = *(block.Transactions() | std::views::transform([](const auto& tx) {
739 return tx.CountOutputs();
740 })).begin();
741 BOOST_CHECK_EQUAL(output_counts, 1);
742
743 validation_interface->m_expected_valid_block.emplace(raw_block);
744 auto ser_block{block.ToBytes()};
745 check_equal(ser_block, raw_block);
746 bool new_block = false;
747 BOOST_CHECK(chainman->ProcessBlock(block, &new_block));
748 BOOST_CHECK(new_block);
749
750 validation_interface->m_expected_valid_block = std::nullopt;
751 new_block = false;
753 BOOST_CHECK(!chainman->ProcessBlock(invalid_block, &new_block));
754 BOOST_CHECK(!new_block);
755
756 auto chain{chainman->GetChain()};
757 BOOST_CHECK_EQUAL(chain.Height(), 1);
758 auto tip{chain.Tip()};
759 auto read_block{chainman->ReadBlock(tip)};
760 BOOST_REQUIRE(read_block);
761 check_equal(read_block.value().ToBytes(), raw_block);
762
763 // Check that we can read the previous block
764 BlockTreeEntry tip_2{*tip.GetPrevious()};
765 Block read_block_2{*chainman->ReadBlock(tip_2)};
766 BOOST_CHECK_EQUAL(chainman->ReadBlockSpentOutputs(tip_2).Count(), 0);
767 BOOST_CHECK_EQUAL(chainman->ReadBlockSpentOutputs(tip).Count(), 0);
768
769 // It should be an error if we go another block back, since the genesis has no ancestor
770 BOOST_CHECK(!tip_2.GetPrevious());
771
772 // If we try to validate it again, it should be a duplicate
773 BOOST_CHECK(chainman->ProcessBlock(block, &new_block));
774 BOOST_CHECK(!new_block);
775}
776
777BOOST_AUTO_TEST_CASE(btck_chainman_mainnet_tests)
778{
779 auto test_directory{TestDirectory{"mainnet_test_bitcoin_kernel"}};
780 chainman_mainnet_validation_test(test_directory);
781 chainman_reindex_test(test_directory);
782 chainman_reindex_chainstate_test(test_directory);
783}
784
785BOOST_AUTO_TEST_CASE(btck_block_hash_tests)
786{
787 std::array<std::byte, 32> test_hash;
788 std::array<std::byte, 32> test_hash_2;
789 for (int i = 0; i < 32; ++i) {
790 test_hash[i] = static_cast<std::byte>(i);
791 test_hash_2[i] = static_cast<std::byte>(i + 1);
792 }
793 BlockHash block_hash{test_hash};
794 BlockHash block_hash_2{test_hash_2};
795 BOOST_CHECK(block_hash != block_hash_2);
796 BOOST_CHECK(block_hash == block_hash);
797 CheckHandle(block_hash, block_hash_2);
798}
799
800BOOST_AUTO_TEST_CASE(btck_chainman_in_memory_tests)
801{
802 auto in_memory_test_directory{TestDirectory{"in-memory_test_bitcoin_kernel"}};
803
804 auto notifications{std::make_shared<TestKernelNotifications>()};
805 auto context{create_context(notifications, ChainType::REGTEST)};
806 auto chainman{create_chainman(in_memory_test_directory, false, false, true, true, context)};
807
808 for (auto& raw_block : REGTEST_BLOCK_DATA) {
809 Block block{hex_string_to_byte_vec(raw_block)};
810 bool new_block{false};
811 chainman->ProcessBlock(block, &new_block);
812 BOOST_CHECK(new_block);
813 }
814
815 BOOST_CHECK(std::filesystem::exists(in_memory_test_directory.m_directory / "blocks"));
816 BOOST_CHECK(!std::filesystem::exists(in_memory_test_directory.m_directory / "blocks" / "index"));
817 BOOST_CHECK(!std::filesystem::exists(in_memory_test_directory.m_directory / "chainstate"));
818
819 BOOST_CHECK(context.interrupt());
820}
821
822BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
823{
824 auto test_directory{TestDirectory{"regtest_test_bitcoin_kernel"}};
825
826 auto notifications{std::make_shared<TestKernelNotifications>()};
827 auto context{create_context(notifications, ChainType::REGTEST)};
828
829 // Validate 206 regtest blocks in total.
830 // Stop halfway to check that it is possible to continue validating starting
831 // from prior state.
832 const size_t mid{REGTEST_BLOCK_DATA.size() / 2};
833
834 {
835 auto chainman{create_chainman(test_directory, false, false, false, false, context)};
836 for (size_t i{0}; i < mid; i++) {
838 bool new_block{false};
839 BOOST_CHECK(chainman->ProcessBlock(block, &new_block));
840 BOOST_CHECK(new_block);
841 }
842 }
843
844 auto chainman{create_chainman(test_directory, false, false, false, false, context)};
845
846 for (size_t i{mid}; i < REGTEST_BLOCK_DATA.size(); i++) {
848 bool new_block{false};
849 BOOST_CHECK(chainman->ProcessBlock(block, &new_block));
850 BOOST_CHECK(new_block);
851 }
852
853 auto chain = chainman->GetChain();
854 auto tip = chain.Tip();
855 auto read_block = chainman->ReadBlock(tip).value();
857
858 auto tip_2 = tip.GetPrevious().value();
859 auto read_block_2 = chainman->ReadBlock(tip_2).value();
860 check_equal(read_block_2.ToBytes(), hex_string_to_byte_vec(REGTEST_BLOCK_DATA[REGTEST_BLOCK_DATA.size() - 2]));
861
862 Txid txid = read_block.Transactions()[0].Txid();
863 Txid txid_2 = read_block_2.Transactions()[0].Txid();
864 BOOST_CHECK(txid != txid_2);
865 BOOST_CHECK(txid == txid);
866 CheckHandle(txid, txid_2);
867
868 auto find_transaction = [&chainman](const TxidView& target_txid) -> std::optional<Transaction> {
869 auto chain = chainman->GetChain();
870 for (const auto block_tree_entry : chain.Entries()) {
871 auto block{chainman->ReadBlock(block_tree_entry)};
872 for (const TransactionView transaction : block->Transactions()) {
873 if (transaction.Txid() == target_txid) {
874 return Transaction{transaction};
875 }
876 }
877 }
878 return std::nullopt;
879 };
880
881 for (const auto block_tree_entry : chain.Entries()) {
882 auto block{chainman->ReadBlock(block_tree_entry)};
883 for (const auto transaction : block->Transactions()) {
884 std::vector<TransactionInput> inputs;
885 std::vector<TransactionOutput> spent_outputs;
886 for (const auto input : transaction.Inputs()) {
887 OutPointView point = input.OutPoint();
888 if (point.index() == std::numeric_limits<uint32_t>::max()) {
889 continue;
890 }
891 inputs.emplace_back(input);
892 BOOST_CHECK(point.Txid() != transaction.Txid());
893 std::optional<Transaction> tx = find_transaction(point.Txid());
894 BOOST_CHECK(tx.has_value());
895 BOOST_CHECK(point.Txid() == tx->Txid());
896 spent_outputs.emplace_back(tx->GetOutput(point.index()));
897 }
898 BOOST_CHECK(inputs.size() == spent_outputs.size());
899 ScriptVerifyStatus status = ScriptVerifyStatus::OK;
900 for (size_t i{0}; i < inputs.size(); ++i) {
901 BOOST_CHECK(spent_outputs[i].GetScriptPubkey().Verify(spent_outputs[i].Amount(), transaction, spent_outputs, i, ScriptVerificationFlags::ALL, status));
902 }
903 }
904 }
905
906 // Read spent outputs for current tip and its previous block
907 BlockSpentOutputs block_spent_outputs{chainman->ReadBlockSpentOutputs(tip)};
908 BlockSpentOutputs block_spent_outputs_prev{chainman->ReadBlockSpentOutputs(*tip.GetPrevious())};
909 CheckHandle(block_spent_outputs, block_spent_outputs_prev);
910 CheckRange(block_spent_outputs_prev.TxsSpentOutputs(), block_spent_outputs_prev.Count());
911 BOOST_CHECK_EQUAL(block_spent_outputs.Count(), 1);
912
913 // Get transaction spent outputs from the last transaction in the two blocks
914 TransactionSpentOutputsView transaction_spent_outputs{block_spent_outputs.GetTxSpentOutputs(block_spent_outputs.Count() - 1)};
915 TransactionSpentOutputs owned_transaction_spent_outputs{transaction_spent_outputs};
916 TransactionSpentOutputs owned_transaction_spent_outputs_prev{block_spent_outputs_prev.GetTxSpentOutputs(block_spent_outputs_prev.Count() - 1)};
917 CheckHandle(owned_transaction_spent_outputs, owned_transaction_spent_outputs_prev);
918 CheckRange(transaction_spent_outputs.Coins(), transaction_spent_outputs.Count());
919
920 // Get the last coin from the transaction spent outputs
921 CoinView coin{transaction_spent_outputs.GetCoin(transaction_spent_outputs.Count() - 1)};
922 BOOST_CHECK(!coin.IsCoinbase());
923 Coin owned_coin{coin};
924 Coin owned_coin_prev{owned_transaction_spent_outputs_prev.GetCoin(owned_transaction_spent_outputs_prev.Count() - 1)};
925 CheckHandle(owned_coin, owned_coin_prev);
926
927 // Validate coin properties
928 TransactionOutputView output = coin.GetOutput();
929 uint32_t coin_height = coin.GetConfirmationHeight();
930 BOOST_CHECK_EQUAL(coin_height, 205);
931 BOOST_CHECK_EQUAL(output.Amount(), 100000000);
932
933 // Test script pubkey serialization
934 auto script_pubkey = output.GetScriptPubkey();
935 auto script_pubkey_bytes{script_pubkey.ToBytes()};
936 BOOST_CHECK_EQUAL(script_pubkey_bytes.size(), 22);
937 auto round_trip_script_pubkey{ScriptPubkey(script_pubkey_bytes)};
938 BOOST_CHECK_EQUAL(round_trip_script_pubkey.ToBytes().size(), 22);
939
940 for (const auto tx_spent_outputs : block_spent_outputs.TxsSpentOutputs()) {
941 for (const auto coins : tx_spent_outputs.Coins()) {
942 BOOST_CHECK_GT(coins.GetOutput().Amount(), 1);
943 }
944 }
945
946 CheckRange(chain.Entries(), chain.CountEntries());
947
948 for (const BlockTreeEntry entry : chain.Entries()) {
949 std::optional<Block> block{chainman->ReadBlock(entry)};
950 if (block) {
951 for (const TransactionView transaction : block->Transactions()) {
952 for (const TransactionOutputView output : transaction.Outputs()) {
953 // skip data carrier outputs
954 if ((unsigned char)output.GetScriptPubkey().ToBytes()[0] == 0x6a) {
955 continue;
956 }
957 BOOST_CHECK_GT(output.Amount(), 1);
958 }
959 }
960 }
961 }
962
963 int32_t count{0};
964 for (const auto entry : chain.Entries()) {
965 BOOST_CHECK_EQUAL(entry.GetHeight(), count);
966 ++count;
967 }
968 BOOST_CHECK_EQUAL(count, chain.CountEntries());
969
970
971 std::filesystem::remove_all(test_directory.m_directory / "blocks" / "blk00000.dat");
972 BOOST_CHECK(!chainman->ReadBlock(tip_2).has_value());
973 std::filesystem::remove_all(test_directory.m_directory / "blocks" / "rev00000.dat");
974 BOOST_CHECK_THROW(chainman->ReadBlockSpentOutputs(tip), std::runtime_error);
975}
constexpr std::array< std::string_view, 206 > REGTEST_BLOCK_DATA
Definition: block_data.h:5
void HeaderTipHandler(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override
void FlushErrorHandler(std::string_view error) override
void FatalErrorHandler(std::string_view error) override
void WarningUnsetHandler(Warning warning) override
void WarningSetHandler(Warning warning, std::string_view message) override
void LogMessage(std::string_view message)
Definition: test_kernel.cpp:95
void PowValidBlock(BlockTreeEntry entry, Block block) override
void BlockDisconnected(Block block, BlockTreeEntry entry) override
std::optional< std::string > m_expected_valid_block
void BlockChecked(Block block, const BlockValidationState state) override
void BlockConnected(Block block, BlockTreeEntry entry) override
std::vector< std::byte > ToBytes() const
std::optional< BlockTreeEntry > GetPrevious() const
BlockValidationResult GetBlockValidationResult() const
ValidationMode GetValidationMode() const
void SetWorkerThreads(int worker_threads)
uint32_t index() const
bool Verify(int64_t amount, const Transaction &tx_to, std::span< const TransactionOutput > spent_outputs, unsigned int input_index, ScriptVerificationFlags flags, ScriptVerifyStatus &status) const
std::vector< std::byte > ToBytes() const
std::vector< std::byte > ToBytes() const
ScriptPubkeyView GetScriptPubkey() const
Txid(const TxidView &view)
const CType * get() const
#define T(expected, seed, data)
@ ALL
Definition: logging.h:98
@ VALIDATION
Definition: logging.h:87
@ BENCH
Definition: logging.h:70
@ KERNEL
Definition: logging.h:97
void logging_set_options(const btck_LoggingOptions &logging_options)
void logging_set_level_category(LogCategory category, LogLevel level)
void logging_enable_category(LogCategory category)
void logging_disable_category(LogCategory category)
#define BOOST_CHECK_THROW(stmt, excMatch)
Definition: object.cpp:19
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
static bool Verify(const CScript &scriptSig, const CScript &scriptPubKey, bool fStrict, ScriptError &err)
std::filesystem::path m_directory
TestDirectory(std::string directory_name)
Options controlling the format of log messages.
int log_timestamps
Prepend a timestamp to log messages.
std::string byte_span_to_hex_string_reversed(std::span< const std::byte > bytes)
Definition: test_kernel.cpp:65
void chainman_reindex_chainstate_test(TestDirectory &test_directory)
Context create_context(std::shared_ptr< TestKernelNotifications > notifications, ChainType chain_type, std::shared_ptr< TestValidationInterface > validation_interface=nullptr)
void run_verify_test(const ScriptPubkey &spent_script_pubkey, const Transaction &spending_tx, std::span< TransactionOutput > spent_outputs, int64_t amount, unsigned int input_index, bool taproot)
std::vector< std::byte > hex_string_to_byte_vec(std::string_view hex)
Definition: test_kernel.cpp:48
void chainman_reindex_test(TestDirectory &test_directory)
BOOST_AUTO_TEST_CASE(btck_transaction_tests)
void check_equal(std::span< const std::byte > _actual, std::span< const std::byte > _expected, bool equal=true)
Definition: test_kernel.cpp:83
void CheckHandle(T object, T distinct_object)
std::unique_ptr< ChainMan > create_chainman(TestDirectory &test_directory, bool reindex, bool wipe_chainstate, bool block_tree_db_in_memory, bool chainstate_db_in_memory, Context &context)
constexpr auto VERIFY_ALL_PRE_SEGWIT
Definition: test_kernel.cpp:78
void CheckRange(const RangeType &range, size_t expected_size)
void chainman_mainnet_validation_test(TestDirectory &test_directory)
std::string random_string(uint32_t length)
Definition: test_kernel.cpp:30
constexpr auto VERIFY_ALL_PRE_TAPROOT
Definition: test_kernel.cpp:81
static int count