15#include <boost/test/unit_test.hpp>
17using namespace std::string_literals;
27 for (
size_t offset{0}; offset <
target.size();) {
34 for (
size_t test{0}; test < 100; ++test) {
35 const size_t write_size{1 + m_rng.randrange(100U)};
36 const std::vector original{m_rng.randbytes<std::byte>(
write_size)};
43 for (
size_t i{0}; i < original.size(); ++i) {
111 fs::path
xor_path{m_args.GetDataDirBase() /
"test_xor.bin"};
113 const std::vector<uint8_t>
test1{1, 2, 3};
114 const std::vector<uint8_t>
test2{4, 5};
134 std::vector<std::byte>
raw(7);
153 std::vector<std::byte>
read2;
169 unsigned char bytes[] = {3, 4, 5, 6};
170 std::vector<unsigned char> vch;
177 BOOST_CHECK((vch == std::vector<unsigned char>{{1, 2}}));
179 BOOST_CHECK((vch == std::vector<unsigned char>{{1, 2}}));
183 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2}}));
185 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2}}));
190 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2, 0}}));
192 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2, 0}}));
197 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 1, 2}}));
199 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 1, 2}}));
204 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 0, 1, 2}}));
206 BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 0, 1, 2}}));
210 BOOST_CHECK((vch == std::vector<unsigned char>{{3, 4, 5, 6}}));
212 BOOST_CHECK((vch == std::vector<unsigned char>{{3, 4, 5, 6}}));
217 BOOST_CHECK((vch == std::vector<unsigned char>{{8, 8, 1, 3, 4, 5, 6, 2}}));
219 BOOST_CHECK((vch == std::vector<unsigned char>{{8, 8, 1, 3, 4, 5, 6, 2}}));
227 unsigned char bytes[] = {3, 4, 5, 6};
228 std::array<std::byte, 8>
arr{};
240 std::array<std::byte, 1>
small{};
247 std::vector<unsigned char> vch = {1, 255, 3, 4, 5, 6};
292 std::vector<uint8_t>
data{0x82, 0xa7, 0x31};
525 size_t fileSize = m_rng.randrange(256);
531 size_t bufSize = m_rng.randrange(300) + 1;
548 switch (m_rng.randrange(6)) {
555 for (
uint8_t i = 0; i < 1; ++i) {
567 for (
uint8_t i = 0; i < 2; ++i) {
579 for (
uint8_t i = 0; i < 5; ++i) {
588 size_t skip_length{
static_cast<size_t>(m_rng.randrange(5))};
597 size_t find =
currentPos + m_rng.randrange(8);
600 bf.FindByte(std::byte(find));
641 const size_t file_size{1 + m_rng.randrange<
size_t>(1 << 17)};
695 const size_t file_size{1 + m_rng.randrange<
size_t>(1 << 17)};
756 const uint32_t v1{m_rng.rand32()}, v2{m_rng.rand32()}, v3{m_rng.rand32()};
757 const fs::path
test_file{m_args.GetDataDirBase() /
"test_buffered_write_read.bin"};
764 f.write(std::as_bytes(std::span{&v3, 1}));
772 BufferedReader f(std::move(file),
sizeof(v1) +
sizeof(v2) +
sizeof(v3));
774 f.read(std::as_writable_bytes(std::span{&
_v3, 1}));
790 const std::string
data{
"bitcoin"};
802 const fs::path path = m_args.GetDataDirBase() /
"size_pos_test.bin";
#define Assert(val)
Identity function.
Non-refcounted RAII wrapper for FILE*.
void ignore(size_t nSize)
void seek(int64_t offset, int origin)
Wrapper around fseek().
void write(std::span< const std::byte > src)
void read(std::span< std::byte > dst)
void Write(uint64_t data, int nbits)
Write the nbits least significant bits of a 64-bit int to the output stream.
Wrapper around an AutoFile& that implements a ring buffer to deserialize from.
void SkipTo(const uint64_t file_pos)
Move the read position ahead in the stream to the given position.
Wrapper that buffers reads from an underlying stream.
void read(std::span< std::byte > dst)
Wrapper that buffers writes to an underlying stream.
void write(std::span< const std::byte > src)
Double ended buffer combining vector and stream-like interfaces.
FlatFileSeq represents a sequence of numbered files storing raw data.
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Reads data from an underlying stream, while hashing the read data.
Writes data to an underlying source stream, while hashing the written data.
static constexpr size_t KEY_SIZE
Minimal stream for reading from an existing byte array by std::span.
Minimal stream for writing to an existing span of bytes.
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
BOOST_CHECK_GT(excessive_headers.size(), MAX_HEADERS_SIZE)
BOOST_CHECK_EXCEPTION(HTTPHeaders{}.Read(reader), std::runtime_error, HasReason{"Empty HTTP header name"})
FILE * fopen(const fs::path &p, const char *mode)
constexpr uint64_t BLOCKFILE_CHUNK_SIZE
The pre-allocation chunk size for blk?????.dat files (since 0.8)
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
std::vector< std::byte > DataBuffer
BOOST_AUTO_TEST_CASE(xor_random_chunks)
Utilities for converting data from/to strings.
@ ZEROS
Seed with a compile time constant of zeros.
BOOST_CHECK_EQUAL_COLLECTIONS(R1L.begin(), R1L.end(), R1Array, R1Array+uint256::size())
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.