Bitcoin Core  26.99.0
P2P Digital Currency
streams_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 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 
5 #include <streams.h>
6 #include <test/util/random.h>
8 #include <util/fs.h>
9 #include <util/strencodings.h>
10 
11 #include <boost/test/unit_test.hpp>
12 
13 using namespace std::string_literals;
14 
15 BOOST_FIXTURE_TEST_SUITE(streams_tests, BasicTestingSetup)
16 
18 {
19  fs::path xor_path{m_args.GetDataDirBase() / "test_xor.bin"};
20  auto raw_file{[&](const auto& mode) { return fsbridge::fopen(xor_path, mode); }};
21  const std::vector<uint8_t> test1{1, 2, 3};
22  const std::vector<uint8_t> test2{4, 5};
23  const std::vector<std::byte> xor_pat{std::byte{0xff}, std::byte{0x00}};
24  {
25  // Check errors for missing file
26  AutoFile xor_file{raw_file("rb"), xor_pat};
27  BOOST_CHECK_EXCEPTION(xor_file << std::byte{}, std::ios_base::failure, HasReason{"AutoFile::write: file handle is nullpt"});
28  BOOST_CHECK_EXCEPTION(xor_file >> std::byte{}, std::ios_base::failure, HasReason{"AutoFile::read: file handle is nullpt"});
29  BOOST_CHECK_EXCEPTION(xor_file.ignore(1), std::ios_base::failure, HasReason{"AutoFile::ignore: file handle is nullpt"});
30  }
31  {
32  AutoFile xor_file{raw_file("wbx"), xor_pat};
33  xor_file << test1 << test2;
34  }
35  {
36  // Read raw from disk
37  AutoFile non_xor_file{raw_file("rb")};
38  std::vector<std::byte> raw(7);
39  non_xor_file >> Span{raw};
40  BOOST_CHECK_EQUAL(HexStr(raw), "fc01fd03fd04fa");
41  // Check that no padding exists
42  BOOST_CHECK_EXCEPTION(non_xor_file.ignore(1), std::ios_base::failure, HasReason{"AutoFile::ignore: end of file"});
43  }
44  {
45  AutoFile xor_file{raw_file("rb"), xor_pat};
46  std::vector<std::byte> read1, read2;
47  xor_file >> read1 >> read2;
49  BOOST_CHECK_EQUAL(HexStr(read2), HexStr(test2));
50  // Check that eof was reached
51  BOOST_CHECK_EXCEPTION(xor_file >> std::byte{}, std::ios_base::failure, HasReason{"AutoFile::read: end of file"});
52  }
53  {
54  AutoFile xor_file{raw_file("rb"), xor_pat};
55  std::vector<std::byte> read2;
56  // Check that ignore works
57  xor_file.ignore(4);
58  xor_file >> read2;
59  BOOST_CHECK_EQUAL(HexStr(read2), HexStr(test2));
60  // Check that ignore and read fail now
61  BOOST_CHECK_EXCEPTION(xor_file.ignore(1), std::ios_base::failure, HasReason{"AutoFile::ignore: end of file"});
62  BOOST_CHECK_EXCEPTION(xor_file >> std::byte{}, std::ios_base::failure, HasReason{"AutoFile::read: end of file"});
63  }
64 }
65 
66 BOOST_AUTO_TEST_CASE(streams_vector_writer)
67 {
68  unsigned char a(1);
69  unsigned char b(2);
70  unsigned char bytes[] = { 3, 4, 5, 6 };
71  std::vector<unsigned char> vch;
72 
73  // Each test runs twice. Serializing a second time at the same starting
74  // point should yield the same results, even if the first test grew the
75  // vector.
76 
77  VectorWriter{vch, 0, a, b};
78  BOOST_CHECK((vch == std::vector<unsigned char>{{1, 2}}));
79  VectorWriter{vch, 0, a, b};
80  BOOST_CHECK((vch == std::vector<unsigned char>{{1, 2}}));
81  vch.clear();
82 
83  VectorWriter{vch, 2, a, b};
84  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2}}));
85  VectorWriter{vch, 2, a, b};
86  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2}}));
87  vch.clear();
88 
89  vch.resize(5, 0);
90  VectorWriter{vch, 2, a, b};
91  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2, 0}}));
92  VectorWriter{vch, 2, a, b};
93  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 1, 2, 0}}));
94  vch.clear();
95 
96  vch.resize(4, 0);
97  VectorWriter{vch, 3, a, b};
98  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 1, 2}}));
99  VectorWriter{vch, 3, a, b};
100  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 1, 2}}));
101  vch.clear();
102 
103  vch.resize(4, 0);
104  VectorWriter{vch, 4, a, b};
105  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 0, 1, 2}}));
106  VectorWriter{vch, 4, a, b};
107  BOOST_CHECK((vch == std::vector<unsigned char>{{0, 0, 0, 0, 1, 2}}));
108  vch.clear();
109 
110  VectorWriter{vch, 0, bytes};
111  BOOST_CHECK((vch == std::vector<unsigned char>{{3, 4, 5, 6}}));
112  VectorWriter{vch, 0, bytes};
113  BOOST_CHECK((vch == std::vector<unsigned char>{{3, 4, 5, 6}}));
114  vch.clear();
115 
116  vch.resize(4, 8);
117  VectorWriter{vch, 2, a, bytes, b};
118  BOOST_CHECK((vch == std::vector<unsigned char>{{8, 8, 1, 3, 4, 5, 6, 2}}));
119  VectorWriter{vch, 2, a, bytes, b};
120  BOOST_CHECK((vch == std::vector<unsigned char>{{8, 8, 1, 3, 4, 5, 6, 2}}));
121  vch.clear();
122 }
123 
124 BOOST_AUTO_TEST_CASE(streams_vector_reader)
125 {
126  std::vector<unsigned char> vch = {1, 255, 3, 4, 5, 6};
127 
128  SpanReader reader{vch};
129  BOOST_CHECK_EQUAL(reader.size(), 6U);
130  BOOST_CHECK(!reader.empty());
131 
132  // Read a single byte as an unsigned char.
133  unsigned char a;
134  reader >> a;
135  BOOST_CHECK_EQUAL(a, 1);
136  BOOST_CHECK_EQUAL(reader.size(), 5U);
137  BOOST_CHECK(!reader.empty());
138 
139  // Read a single byte as a signed char.
140  signed char b;
141  reader >> b;
142  BOOST_CHECK_EQUAL(b, -1);
143  BOOST_CHECK_EQUAL(reader.size(), 4U);
144  BOOST_CHECK(!reader.empty());
145 
146  // Read a 4 bytes as an unsigned int.
147  unsigned int c;
148  reader >> c;
149  BOOST_CHECK_EQUAL(c, 100992003U); // 3,4,5,6 in little-endian base-256
150  BOOST_CHECK_EQUAL(reader.size(), 0U);
151  BOOST_CHECK(reader.empty());
152 
153  // Reading after end of byte vector throws an error.
154  signed int d;
155  BOOST_CHECK_THROW(reader >> d, std::ios_base::failure);
156 
157  // Read a 4 bytes as a signed int from the beginning of the buffer.
158  SpanReader new_reader{vch};
159  new_reader >> d;
160  BOOST_CHECK_EQUAL(d, 67370753); // 1,255,3,4 in little-endian base-256
161  BOOST_CHECK_EQUAL(new_reader.size(), 2U);
162  BOOST_CHECK(!new_reader.empty());
163 
164  // Reading after end of byte vector throws an error even if the reader is
165  // not totally empty.
166  BOOST_CHECK_THROW(new_reader >> d, std::ios_base::failure);
167 }
168 
169 BOOST_AUTO_TEST_CASE(streams_vector_reader_rvalue)
170 {
171  std::vector<uint8_t> data{0x82, 0xa7, 0x31};
172  SpanReader reader{data};
173  uint32_t varint = 0;
174  // Deserialize into r-value
175  reader >> VARINT(varint);
176  BOOST_CHECK_EQUAL(varint, 54321U);
177  BOOST_CHECK(reader.empty());
178 }
179 
180 BOOST_AUTO_TEST_CASE(bitstream_reader_writer)
181 {
182  DataStream data{};
183 
184  BitStreamWriter bit_writer{data};
185  bit_writer.Write(0, 1);
186  bit_writer.Write(2, 2);
187  bit_writer.Write(6, 3);
188  bit_writer.Write(11, 4);
189  bit_writer.Write(1, 5);
190  bit_writer.Write(32, 6);
191  bit_writer.Write(7, 7);
192  bit_writer.Write(30497, 16);
193  bit_writer.Flush();
194 
195  DataStream data_copy{data};
196  uint32_t serialized_int1;
197  data >> serialized_int1;
198  BOOST_CHECK_EQUAL(serialized_int1, uint32_t{0x7700C35A}); // NOTE: Serialized as LE
199  uint16_t serialized_int2;
200  data >> serialized_int2;
201  BOOST_CHECK_EQUAL(serialized_int2, uint16_t{0x1072}); // NOTE: Serialized as LE
202 
203  BitStreamReader bit_reader{data_copy};
204  BOOST_CHECK_EQUAL(bit_reader.Read(1), 0U);
205  BOOST_CHECK_EQUAL(bit_reader.Read(2), 2U);
206  BOOST_CHECK_EQUAL(bit_reader.Read(3), 6U);
207  BOOST_CHECK_EQUAL(bit_reader.Read(4), 11U);
208  BOOST_CHECK_EQUAL(bit_reader.Read(5), 1U);
209  BOOST_CHECK_EQUAL(bit_reader.Read(6), 32U);
210  BOOST_CHECK_EQUAL(bit_reader.Read(7), 7U);
211  BOOST_CHECK_EQUAL(bit_reader.Read(16), 30497U);
212  BOOST_CHECK_THROW(bit_reader.Read(8), std::ios_base::failure);
213 }
214 
215 BOOST_AUTO_TEST_CASE(streams_serializedata_xor)
216 {
217  std::vector<std::byte> in;
218 
219  // Degenerate case
220  {
221  DataStream ds{in};
222  ds.Xor({0x00, 0x00});
223  BOOST_CHECK_EQUAL(""s, ds.str());
224  }
225 
226  in.push_back(std::byte{0x0f});
227  in.push_back(std::byte{0xf0});
228 
229  // Single character key
230  {
231  DataStream ds{in};
232  ds.Xor({0xff});
233  BOOST_CHECK_EQUAL("\xf0\x0f"s, ds.str());
234  }
235 
236  // Multi character key
237 
238  in.clear();
239  in.push_back(std::byte{0xf0});
240  in.push_back(std::byte{0x0f});
241 
242  {
243  DataStream ds{in};
244  ds.Xor({0xff, 0x0f});
245  BOOST_CHECK_EQUAL("\x0f\x00"s, ds.str());
246  }
247 }
248 
249 BOOST_AUTO_TEST_CASE(streams_buffered_file)
250 {
251  fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
252  AutoFile file{fsbridge::fopen(streams_test_filename, "w+b")};
253 
254  // The value at each offset is the offset.
255  for (uint8_t j = 0; j < 40; ++j) {
256  file << j;
257  }
258  std::rewind(file.Get());
259 
260  // The buffer size (second arg) must be greater than the rewind
261  // amount (third arg).
262  try {
263  BufferedFile bfbad{file, 25, 25};
264  BOOST_CHECK(false);
265  } catch (const std::exception& e) {
266  BOOST_CHECK(strstr(e.what(),
267  "Rewind limit must be less than buffer size") != nullptr);
268  }
269 
270  // The buffer is 25 bytes, allow rewinding 10 bytes.
271  BufferedFile bf{file, 25, 10};
272  BOOST_CHECK(!bf.eof());
273 
274  uint8_t i;
275  bf >> i;
276  BOOST_CHECK_EQUAL(i, 0);
277  bf >> i;
278  BOOST_CHECK_EQUAL(i, 1);
279 
280  // After reading bytes 0 and 1, we're positioned at 2.
281  BOOST_CHECK_EQUAL(bf.GetPos(), 2U);
282 
283  // Rewind to offset 0, ok (within the 10 byte window).
284  BOOST_CHECK(bf.SetPos(0));
285  bf >> i;
286  BOOST_CHECK_EQUAL(i, 0);
287 
288  // We can go forward to where we've been, but beyond may fail.
289  BOOST_CHECK(bf.SetPos(2));
290  bf >> i;
291  BOOST_CHECK_EQUAL(i, 2);
292 
293  // If you know the maximum number of bytes that should be
294  // read to deserialize the variable, you can limit the read
295  // extent. The current file offset is 3, so the following
296  // SetLimit() allows zero bytes to be read.
297  BOOST_CHECK(bf.SetLimit(3));
298  try {
299  bf >> i;
300  BOOST_CHECK(false);
301  } catch (const std::exception& e) {
302  BOOST_CHECK(strstr(e.what(),
303  "Attempt to position past buffer limit") != nullptr);
304  }
305  // The default argument removes the limit completely.
306  BOOST_CHECK(bf.SetLimit());
307  // The read position should still be at 3 (no change).
308  BOOST_CHECK_EQUAL(bf.GetPos(), 3U);
309 
310  // Read from current offset, 3, forward until position 10.
311  for (uint8_t j = 3; j < 10; ++j) {
312  bf >> i;
313  BOOST_CHECK_EQUAL(i, j);
314  }
315  BOOST_CHECK_EQUAL(bf.GetPos(), 10U);
316 
317  // We're guaranteed (just barely) to be able to rewind to zero.
318  BOOST_CHECK(bf.SetPos(0));
319  BOOST_CHECK_EQUAL(bf.GetPos(), 0U);
320  bf >> i;
321  BOOST_CHECK_EQUAL(i, 0);
322 
323  // We can set the position forward again up to the farthest
324  // into the stream we've been, but no farther. (Attempting
325  // to go farther may succeed, but it's not guaranteed.)
326  BOOST_CHECK(bf.SetPos(10));
327  bf >> i;
328  BOOST_CHECK_EQUAL(i, 10);
329  BOOST_CHECK_EQUAL(bf.GetPos(), 11U);
330 
331  // Now it's only guaranteed that we can rewind to offset 1
332  // (current read position, 11, minus rewind amount, 10).
333  BOOST_CHECK(bf.SetPos(1));
334  BOOST_CHECK_EQUAL(bf.GetPos(), 1U);
335  bf >> i;
336  BOOST_CHECK_EQUAL(i, 1);
337 
338  // We can stream into large variables, even larger than
339  // the buffer size.
340  BOOST_CHECK(bf.SetPos(11));
341  {
342  uint8_t a[40 - 11];
343  bf >> a;
344  for (uint8_t j = 0; j < sizeof(a); ++j) {
345  BOOST_CHECK_EQUAL(a[j], 11 + j);
346  }
347  }
348  BOOST_CHECK_EQUAL(bf.GetPos(), 40U);
349 
350  // We've read the entire file, the next read should throw.
351  try {
352  bf >> i;
353  BOOST_CHECK(false);
354  } catch (const std::exception& e) {
355  BOOST_CHECK(strstr(e.what(),
356  "BufferedFile::Fill: end of file") != nullptr);
357  }
358  // Attempting to read beyond the end sets the EOF indicator.
359  BOOST_CHECK(bf.eof());
360 
361  // Still at offset 40, we can go back 10, to 30.
362  BOOST_CHECK_EQUAL(bf.GetPos(), 40U);
363  BOOST_CHECK(bf.SetPos(30));
364  bf >> i;
365  BOOST_CHECK_EQUAL(i, 30);
366  BOOST_CHECK_EQUAL(bf.GetPos(), 31U);
367 
368  // We're too far to rewind to position zero.
369  BOOST_CHECK(!bf.SetPos(0));
370  // But we should now be positioned at least as far back as allowed
371  // by the rewind window (relative to our farthest read position, 40).
372  BOOST_CHECK(bf.GetPos() <= 30U);
373 
374  // We can explicitly close the file, or the destructor will do it.
375  file.fclose();
376 
377  fs::remove(streams_test_filename);
378 }
379 
380 BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
381 {
382  fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
383  AutoFile file{fsbridge::fopen(streams_test_filename, "w+b")};
384  // The value at each offset is the byte offset (e.g. byte 1 in the file has the value 0x01).
385  for (uint8_t j = 0; j < 40; ++j) {
386  file << j;
387  }
388  std::rewind(file.Get());
389 
390  // The buffer is 25 bytes, allow rewinding 10 bytes.
391  BufferedFile bf{file, 25, 10};
392 
393  uint8_t i;
394  // This is like bf >> (7-byte-variable), in that it will cause data
395  // to be read from the file into memory, but it's not copied to us.
396  bf.SkipTo(7);
397  BOOST_CHECK_EQUAL(bf.GetPos(), 7U);
398  bf >> i;
399  BOOST_CHECK_EQUAL(i, 7);
400 
401  // The bytes in the buffer up to offset 7 are valid and can be read.
402  BOOST_CHECK(bf.SetPos(0));
403  bf >> i;
404  BOOST_CHECK_EQUAL(i, 0);
405  bf >> i;
406  BOOST_CHECK_EQUAL(i, 1);
407 
408  bf.SkipTo(11);
409  bf >> i;
410  BOOST_CHECK_EQUAL(i, 11);
411 
412  // SkipTo() honors the transfer limit; we can't position beyond the limit.
413  bf.SetLimit(13);
414  try {
415  bf.SkipTo(14);
416  BOOST_CHECK(false);
417  } catch (const std::exception& e) {
418  BOOST_CHECK(strstr(e.what(), "Attempt to position past buffer limit") != nullptr);
419  }
420 
421  // We can position exactly to the transfer limit.
422  bf.SkipTo(13);
423  BOOST_CHECK_EQUAL(bf.GetPos(), 13U);
424 
425  file.fclose();
426  fs::remove(streams_test_filename);
427 }
428 
429 BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
430 {
431  // Make this test deterministic.
433 
434  fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
435  for (int rep = 0; rep < 50; ++rep) {
436  AutoFile file{fsbridge::fopen(streams_test_filename, "w+b")};
437  size_t fileSize = InsecureRandRange(256);
438  for (uint8_t i = 0; i < fileSize; ++i) {
439  file << i;
440  }
441  std::rewind(file.Get());
442 
443  size_t bufSize = InsecureRandRange(300) + 1;
444  size_t rewindSize = InsecureRandRange(bufSize);
445  BufferedFile bf{file, bufSize, rewindSize};
446  size_t currentPos = 0;
447  size_t maxPos = 0;
448  for (int step = 0; step < 100; ++step) {
449  if (currentPos >= fileSize)
450  break;
451 
452  // We haven't read to the end of the file yet.
453  BOOST_CHECK(!bf.eof());
454  BOOST_CHECK_EQUAL(bf.GetPos(), currentPos);
455 
456  // Pretend the file consists of a series of objects of varying
457  // sizes; the boundaries of the objects can interact arbitrarily
458  // with the CBufferFile's internal buffer. These first three
459  // cases simulate objects of various sizes (1, 2, 5 bytes).
460  switch (InsecureRandRange(6)) {
461  case 0: {
462  uint8_t a[1];
463  if (currentPos + 1 > fileSize)
464  continue;
465  bf.SetLimit(currentPos + 1);
466  bf >> a;
467  for (uint8_t i = 0; i < 1; ++i) {
468  BOOST_CHECK_EQUAL(a[i], currentPos);
469  currentPos++;
470  }
471  break;
472  }
473  case 1: {
474  uint8_t a[2];
475  if (currentPos + 2 > fileSize)
476  continue;
477  bf.SetLimit(currentPos + 2);
478  bf >> a;
479  for (uint8_t i = 0; i < 2; ++i) {
480  BOOST_CHECK_EQUAL(a[i], currentPos);
481  currentPos++;
482  }
483  break;
484  }
485  case 2: {
486  uint8_t a[5];
487  if (currentPos + 5 > fileSize)
488  continue;
489  bf.SetLimit(currentPos + 5);
490  bf >> a;
491  for (uint8_t i = 0; i < 5; ++i) {
492  BOOST_CHECK_EQUAL(a[i], currentPos);
493  currentPos++;
494  }
495  break;
496  }
497  case 3: {
498  // SkipTo is similar to the "read" cases above, except
499  // we don't receive the data.
500  size_t skip_length{static_cast<size_t>(InsecureRandRange(5))};
501  if (currentPos + skip_length > fileSize) continue;
502  bf.SetLimit(currentPos + skip_length);
503  bf.SkipTo(currentPos + skip_length);
504  currentPos += skip_length;
505  break;
506  }
507  case 4: {
508  // Find a byte value (that is at or ahead of the current position).
509  size_t find = currentPos + InsecureRandRange(8);
510  if (find >= fileSize)
511  find = fileSize - 1;
512  bf.FindByte(std::byte(find));
513  // The value at each offset is the offset.
514  BOOST_CHECK_EQUAL(bf.GetPos(), find);
515  currentPos = find;
516 
517  bf.SetLimit(currentPos + 1);
518  uint8_t i;
519  bf >> i;
520  BOOST_CHECK_EQUAL(i, currentPos);
521  currentPos++;
522  break;
523  }
524  case 5: {
525  size_t requestPos = InsecureRandRange(maxPos + 4);
526  bool okay = bf.SetPos(requestPos);
527  // The new position may differ from the requested position
528  // because we may not be able to rewind beyond the rewind
529  // window, and we may not be able to move forward beyond the
530  // farthest position we've reached so far.
531  currentPos = bf.GetPos();
532  BOOST_CHECK_EQUAL(okay, currentPos == requestPos);
533  // Check that we can position within the rewind window.
534  if (requestPos <= maxPos &&
535  maxPos > rewindSize &&
536  requestPos >= maxPos - rewindSize) {
537  // We requested a position within the rewind window.
538  BOOST_CHECK(okay);
539  }
540  break;
541  }
542  }
543  if (maxPos < currentPos)
544  maxPos = currentPos;
545  }
546  }
547  fs::remove(streams_test_filename);
548 }
549 
550 BOOST_AUTO_TEST_CASE(streams_hashed)
551 {
552  DataStream stream{};
553  HashedSourceWriter hash_writer{stream};
554  const std::string data{"bitcoin"};
555  hash_writer << data;
556 
557  HashVerifier hash_verifier{stream};
558  std::string result;
559  hash_verifier >> result;
560  BOOST_CHECK_EQUAL(data, result);
561  BOOST_CHECK_EQUAL(hash_writer.GetHash(), hash_verifier.GetHash());
562 }
563 
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:389
void ignore(size_t nSize)
Definition: streams.cpp:31
void Write(uint64_t data, int nbits)
Write the nbits least significant bits of a 64-bit int to the output stream.
Definition: streams.h:351
Wrapper around an AutoFile& that implements a ring buffer to deserialize from.
Definition: streams.h:467
void SkipTo(const uint64_t file_pos)
Move the read position ahead in the stream to the given position.
Definition: streams.h:540
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
void Xor(const std::vector< unsigned char > &key)
XOR the contents of this stream with a certain key.
Definition: streams.h:276
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Definition: setup_common.h:238
Reads data from an underlying stream, while hashing the read data.
Definition: hash.h:151
Writes data to an underlying source stream, while hashing the written data.
Definition: hash.h:185
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:97
Minimal stream for reading from an existing byte array by Span.
Definition: streams.h:101
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
const std::string test1
BOOST_AUTO_TEST_SUITE_END()
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:25
#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
#define VARINT(obj)
Definition: serialize.h:511
BOOST_AUTO_TEST_CASE(xor_file)
Basic testing setup.
Definition: setup_common.h:49
@ ZEROS
Seed with a compile time constant of zeros.
static uint64_t InsecureRandRange(uint64_t range)
Definition: random.h:60
static void SeedInsecureRand(SeedRand seed=SeedRand::SEED)
Definition: random.h:36
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.