47#include <boost/test/unit_test.hpp>
49using namespace std::literals;
75 explicit NoCopyOrMove(
int i) : i{i} { }
77 NoCopyOrMove() =
delete;
78 NoCopyOrMove(
const NoCopyOrMove&) =
delete;
79 NoCopyOrMove(NoCopyOrMove&&) =
delete;
80 NoCopyOrMove& operator=(
const NoCopyOrMove&) =
delete;
81 NoCopyOrMove& operator=(NoCopyOrMove&&) =
delete;
83 operator bool()
const {
return i != 0; }
85 int get_ip1() {
return i + 1; }
89 [&]() {
Assume(get_ip1()); }();
90 return Assume(get_ip1() != 5);
98 const std::unique_ptr<int> p_two =
Assert(std::make_unique<int>(2));
100 const int two = *
Assert(p_two);
104 const bool result{
Assume(two == 2)};
117 const int nine{*
Assert(std::optional<int>{9})};
129 BOOST_ERROR(
"break was swallowed!");
139 BOOST_ERROR(
"break was swallowed!");
143constexpr char HEX_PARSE_INPUT[] =
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f";
145 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7,
146 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde,
147 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12,
148 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d,
154 std::vector<unsigned char> result;
158 constexpr std::array<std::byte, 65> hex_literal_array{
operator""_hex<util::detail::Hex(HEX_PARSE_INPUT)>()};
160 BOOST_CHECK_EQUAL_COLLECTIONS(hex_literal_span.begin(), hex_literal_span.end(), expected.begin(), expected.end());
162 const std::vector<std::byte> hex_literal_vector{
operator""_hex_v<util::detail::Hex(HEX_PARSE_INPUT)>()};
163 auto hex_literal_vec_span =
MakeUCharSpan(hex_literal_vector);
164 BOOST_CHECK_EQUAL_COLLECTIONS(hex_literal_vec_span.begin(), hex_literal_vec_span.end(), expected.begin(), expected.end());
166 constexpr std::array<uint8_t, 65> hex_literal_array_uint8{
operator""_hex_u8<util::detail::Hex(HEX_PARSE_INPUT)>()};
167 BOOST_CHECK_EQUAL_COLLECTIONS(hex_literal_array_uint8.begin(), hex_literal_array_uint8.end(), expected.begin(), expected.end());
169 result =
operator""_hex_v_u8<util::detail::Hex(HEX_PARSE_INPUT)>();
170 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
173 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
176 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
179 expected = {0x12, 0x34, 0x56, 0x78};
181 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
182 result = TryParseHex<uint8_t>(
"12 34 56 78").value();
183 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
186 expected = {0x89, 0x34, 0x56, 0x78};
188 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
189 result = TryParseHex<uint8_t>(
" 89 34 56 78").value();
190 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
193 expected = {0xff, 0xaa};
195 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
196 result = TryParseHex<uint8_t>(
" Ff aA ").value();
197 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
200 static_assert(
""_hex.empty());
201 static_assert(
""_hex_u8.empty());
212 const std::string with_embedded_null{
" 11 "s
243 constexpr std::string_view out_exp{
"04678afdb0"};
246 const std::span<const std::byte> in_b{
MakeByteSpan(in_s)};
254 auto input = std::string();
255 for (
size_t i=0; i<256; ++i) {
256 input.push_back(
static_cast<char>(i));
260 BOOST_TEST_REQUIRE(hex.size() == 512);
261 static constexpr auto hexmap = std::string_view(
"0123456789abcdef");
262 for (
size_t i = 0; i < 256; ++i) {
263 auto upper = hexmap.find(hex[i * 2]);
264 auto lower = hexmap.find(hex[i * 2 + 1]);
265 BOOST_TEST_REQUIRE(upper != std::string_view::npos);
266 BOOST_TEST_REQUIRE(lower != std::string_view::npos);
267 BOOST_TEST_REQUIRE(i == upper*16 + lower);
274 std::array mut_arr{uint8_t{0xaa}, uint8_t{0xbb}};
276 mut_bytes[1] = std::byte{0x11};
289 const auto op_upper = [](
const std::string&
s) {
return ToUpper(
s); };
297 const std::string original(
"A test \"%s\" string '%s'.");
298 auto test_replaceall = [&original](
const std::string& search,
const std::string& substitute,
const std::string& expected) {
299 auto test = original;
304 test_replaceall(
"",
"foo", original);
305 test_replaceall(original,
"foo",
"foo");
306 test_replaceall(
"%s",
"foo",
"A test \"foo\" string 'foo'.");
307 test_replaceall(
"\"",
"foo",
"A test foo%sfoo string '%s'.");
308 test_replaceall(
"'",
"foo",
"A test \"%s\" string foo%sfoo.");
323 BOOST_CHECK_EQUAL(
TrimString(std::string(
"\x05\x04\x03\x02\x01\x00", 6), std::string(
"\x05\x04\x03\x02\x01", 5)), std::string(
"\0", 1));
356 const std::string valid{
"2000-01-01T00:00:01Z"};
358 for (
auto mut{0U}; mut < valid.size(); ++mut) {
359 std::string invalid{valid};
510 for (
int mod=2;mod<11;mod++)
514 int err = 30*10000./mod*sqrt((1./mod*(1-1./mod))/10000.);
516 while(mask<mod-1)mask=(mask<<1)+1;
520 for (
int i = 0; i < 10000; i++) {
523 rval=m_rng.rand32()&mask;
524 }
while(rval>=(uint32_t)mod);
545#define B "check_prefix"
546#define E "check_postfix"
549 int64_t s64t = -9223372036854775807LL;
550 uint64_t u64t = 18446744073709551615ULL;
555 size_t st = 12345678;
556 ssize_t sst = -12345678;
561 ptrdiff_t pt = 87654321;
562 ptrdiff_t spt = -87654321;
574 for (
const auto& num_sleep : {0ms, 1ms}) {
607 constexpr T MAXI{std::numeric_limits<T>::max()};
627 TestAddMatrixOverflow<T>();
628 constexpr T MINI{std::numeric_limits<T>::min()};
629 constexpr T MAXI{std::numeric_limits<T>::max()};
647 TestAddMatrixOverflow<unsigned>();
648 TestAddMatrix<signed>();
676 BOOST_CHECK(!ToIntegral<T>(
"-32482348723847471234"));
677 BOOST_CHECK(!ToIntegral<T>(
"32482348723847471234"));
692 RunToIntegralTests<uint64_t>();
693 RunToIntegralTests<int64_t>();
694 RunToIntegralTests<uint32_t>();
695 RunToIntegralTests<int32_t>();
696 RunToIntegralTests<uint16_t>();
697 RunToIntegralTests<int16_t>();
698 RunToIntegralTests<uint8_t>();
699 RunToIntegralTests<int8_t>();
701 BOOST_CHECK(!ToIntegral<int64_t>(
"-9223372036854775809"));
702 BOOST_CHECK_EQUAL(ToIntegral<int64_t>(
"-9223372036854775808").value(), -9'223'372'036'854'775'807LL - 1LL);
703 BOOST_CHECK_EQUAL(ToIntegral<int64_t>(
"9223372036854775807").value(), 9'223'372'036'854'775'807);
704 BOOST_CHECK(!ToIntegral<int64_t>(
"9223372036854775808"));
708 BOOST_CHECK_EQUAL(ToIntegral<uint64_t>(
"18446744073709551615").value(), 18'446'744'073'709'551'615ULL);
709 BOOST_CHECK(!ToIntegral<uint64_t>(
"18446744073709551616"));
744 return strtoll(str.c_str(),
nullptr, 10);
774 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(
"-32482348723847471234"), -2'147'483'647 - 1);
775 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(
"32482348723847471234"), 2'147'483'647);
777 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(
"-9223372036854775809"), -9'223'372'036'854'775'807LL - 1LL);
778 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(
"-9223372036854775808"), -9'223'372'036'854'775'807LL - 1LL);
779 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(
"9223372036854775807"), 9'223'372'036'854'775'807);
780 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(
"9223372036854775808"), 9'223'372'036'854'775'807);
782 std::map<std::string, int64_t> atoi64_test_pairs = {
783 {
"-9223372036854775809", std::numeric_limits<int64_t>::min()},
784 {
"-9223372036854775808", -9'223'372'036'854'775'807LL - 1LL},
785 {
"9223372036854775807", 9'223'372'036'854'775'807},
786 {
"9223372036854775808", std::numeric_limits<int64_t>::max()},
793 for (
const auto& pair : atoi64_test_pairs) {
798 for (
const auto& pair : atoi64_test_pairs) {
804 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>(
"18446744073709551615"), 18'446'744'073'709'551'615ULL);
805 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>(
"18446744073709551616"), 18'446'744'073'709'551'615ULL);
807 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(
"-2147483649"), -2'147'483'648LL);
808 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(
"-2147483648"), -2'147'483'648LL);
814 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>(
"4294967295"), 4'294'967'295U);
815 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>(
"4294967296"), 4'294'967'295U);
851 BOOST_CHECK_EQUAL(
FormatParagraph(
"This_is_a_very_long_test_string_without_any_spaces_so_it_should_just_get_returned_as_is_despite_the_length until it gets here", 79),
"This_is_a_very_long_test_string_without_any_spaces_so_it_should_just_get_returned_as_is_despite_the_length\nuntil it gets here");
854 BOOST_CHECK_EQUAL(
FormatParagraph(
"a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de f g h i j k l m n o p", 79),
"a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de\nf g h i j k l m n o p");
855 BOOST_CHECK_EQUAL(
FormatParagraph(
"x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de f g h i j k l m n o p", 79),
"x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de\nf g h i j k l m n o p");
857 BOOST_CHECK_EQUAL(
FormatParagraph(
"x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e fg h i j k", 79, 4),
"x\na b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c de\n f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e fg\n h i j k");
859 BOOST_CHECK_EQUAL(
FormatParagraph(
"This is a very long test string. This is a second sentence in the very long test string.", 79),
"This is a very long test string. This is a second sentence in the very long\ntest string.");
860 BOOST_CHECK_EQUAL(
FormatParagraph(
"This is a very long test string.\nThis is a second sentence in the very long test string. This is a third sentence in the very long test string.", 79),
"This is a very long test string.\nThis is a second sentence in the very long test string. This is a third\nsentence in the very long test string.");
861 BOOST_CHECK_EQUAL(
FormatParagraph(
"This is a very long test string.\n\nThis is a second sentence in the very long test string. This is a third sentence in the very long test string.", 79),
"This is a very long test string.\n\nThis is a second sentence in the very long test string. This is a third\nsentence in the very long test string.");
862 BOOST_CHECK_EQUAL(
FormatParagraph(
"Testing that normal newlines do not get indented.\nLike here.", 79),
"Testing that normal newlines do not get indented.\nLike here.");
867 std::vector<std::string> comments;
868 comments.emplace_back(
"comment1");
869 std::vector<std::string> comments2;
870 comments2.emplace_back(
"comment1");
966 int rv = read(fd, &ch, 1);
978 rv = write(fd, &ch, 1);
984 rv = write(fd, &ch, 1);
999 fs::path dirname = m_args.GetDataDirBase() /
"lock_dir";
1000 const fs::path lockname =
".lock";
1083 fs::remove_all(dirname);
1121static std::string
SpanToStr(
const std::span<const char>& span)
1123 return std::string(span.begin(), span.end());
1130 std::span<const char> sp;
1134 input =
"MilkToastHoney";
1136 success =
Const(
"", sp);
1140 success =
Const(
"Milk", sp);
1144 success =
Const(
"Bread", sp);
1147 success =
Const(
"Toast", sp);
1151 success =
Const(
"Honeybadger", sp);
1154 success =
Const(
"Honey", sp);
1159 input =
"Foo(Bar(xy,z()))";
1162 success =
Func(
"FooBar", sp);
1165 success =
Func(
"Foo(", sp);
1168 success =
Func(
"Foo", sp);
1172 success =
Func(
"Bar", sp);
1176 success =
Func(
"xy", sp);
1180 std::span<const char> result;
1182 input =
"(n*(n-1))/2";
1194 input =
"(aaaaa,bbbbb()),c";
1206 input =
"((a),(b),(c)),xxx";
1213 std::vector<std::span<const char>> results;
1216 results =
Split(input,
'x');
1223 input =
"one#two#three";
1224 results =
Split(input,
'-');
1228 input =
"one#two#three";
1229 results =
Split(input,
'#');
1235 input =
"*foo*bar*";
1236 results =
Split(input,
'*');
1248 std::vector<std::string> result =
SplitString(
"",
'-');
1255 std::vector<std::string> result =
SplitString(
"-",
'-');
1263 std::vector<std::string> result =
SplitString(
"--",
'-');
1272 std::vector<std::string> result =
SplitString(
"abc",
'-');
1279 std::vector<std::string> result =
SplitString(
"a-b",
'-');
1287 std::vector<std::string> result =
SplitString(
"AAA",
'a');
1294 using V = std::vector<std::string>;
1295 BOOST_TEST(
SplitString(
"a,b.c:d;e",
",;") == V({
"a",
"b.c:d",
"e"}));
1296 BOOST_TEST(
SplitString(
"a,b.c:d;e",
",;:.") == V({
"a",
"b",
"c",
"d",
"e"}));
1297 BOOST_TEST(
SplitString(
"a,b.c:d;e",
"") == V({
"a,b.c:d;e"}));
1298 BOOST_TEST(
SplitString(
"aaa",
"bcdefg") == V({
"aaa"}));
1299 BOOST_TEST(
SplitString(
"x\0a,b"s,
"\0"s) == V({
"x",
"a,b"}));
1300 BOOST_TEST(
SplitString(
"x\0a,b"s,
'\0') == V({
"x",
"a,b"}));
1301 BOOST_TEST(
SplitString(
"x\0a,b"s,
"\0,"s) == V({
"x",
"a",
"b"}));
1302 BOOST_TEST(
SplitString(
"abcdefg",
"bcd") == V({
"a",
"",
"",
"efg"}));
1315 const std::string NUL(
"O\x00O", 3);
1324 const Tracker* origin;
1328 Tracker() noexcept : origin(this) {}
1329 Tracker(
const Tracker&
t) noexcept : origin(
t.origin), copies(
t.copies + 1) {}
1330 Tracker(Tracker&&
t) noexcept : origin(
t.origin), copies(
t.copies) {}
1331 Tracker& operator=(
const Tracker&
t)
noexcept
1335 copies =
t.copies + 1;
1358 auto v2 =
Vector(std::move(t2));
1363 auto v3 =
Vector(t1, std::move(t2));
1370 auto v4 =
Vector(std::move(v3[0]), v3[1], std::move(t3));
1379 auto v5 =
Cat(v1, v4);
1390 auto v6 =
Cat(std::move(v1), v3);
1399 auto v7 =
Cat(v2, std::move(v4));
1410 auto v8 =
Cat(std::move(v2), std::move(v3));
1422 const std::array<unsigned char, 32> privkey_bytes = {
1425 0xD9, 0x7F, 0x51, 0x08, 0xF1, 0x1C, 0xDA, 0x6E,
1426 0xEE, 0xBA, 0xAA, 0x42, 0x0F, 0xEF, 0x07, 0x26,
1427 0xB1, 0xF8, 0x98, 0x06, 0x0B, 0x98, 0x48, 0x9F,
1428 0xA3, 0x09, 0x84, 0x63, 0xC0, 0x03, 0x28, 0x66
1431 const std::string message =
"Trust no one";
1433 const std::string expected_signature =
1434 "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=";
1437 std::string generated_signature;
1439 BOOST_REQUIRE_MESSAGE(!privkey.
IsValid(),
1440 "Confirm the private key is invalid");
1442 BOOST_CHECK_MESSAGE(!
MessageSign(privkey, message, generated_signature),
1443 "Sign with an invalid private key");
1445 privkey.
Set(privkey_bytes.begin(), privkey_bytes.end(),
true);
1447 BOOST_REQUIRE_MESSAGE(privkey.
IsValid(),
1448 "Confirm the private key is valid");
1450 BOOST_CHECK_MESSAGE(
MessageSign(privkey, message, generated_signature),
1451 "Sign with a valid private key");
1461 "signature should be irrelevant",
1467 "3B5fQsEXEaV8v6U3ejYc8XaKXAkyQj2MjV",
1468 "signature should be irrelevant",
1474 "1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",
1475 "invalid signature, not in base64 encoding",
1476 "message should be irrelevant"),
1481 "1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",
1482 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
1483 "message should be irrelevant"),
1488 "15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",
1489 "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",
1490 "I never signed this"),
1495 "15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",
1496 "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",
1502 "11canuhp9X2NocwCq7xNrQYTmUgZAnLK3",
1503 "IIcaIENoYW5jZWxsb3Igb24gYnJpbmsgb2Ygc2Vjb25kIGJhaWxvdXQgZm9yIGJhbmtzIAaHRtbCeDZINyavx14=",
1510 const std::string unsigned_tx =
"...";
1511 const std::string prefixed_message =
1514 std::string(1, (
char)unsigned_tx.length()) +
1518 const uint256 message_hash1 =
Hash(prefixed_message);
1522 BOOST_CHECK_NE(message_hash1, signature_hash);
1588 fs::path tmpfolder = m_args.GetDataDirBase();
1589 fs::path tmpfile = tmpfolder /
"read_binary.dat";
1590 std::string expected_text;
1591 for (
int i = 0; i < 30; i++) {
1592 expected_text +=
"0123456789";
1595 std::ofstream file{tmpfile};
1596 file << expected_text;
1606 auto [valid, text] =
ReadBinaryFile(tmpfile, expected_text.size() / 2);
1612 fs::path invalid_file = tmpfolder /
"invalid_binary.dat";
1621 fs::path tmpfolder = m_args.GetDataDirBase();
1622 fs::path tmpfile = tmpfolder /
"write_binary.dat";
1623 std::string expected_text =
"bitcoin";
1625 std::string actual_text;
1626 std::ifstream file{tmpfile};
1627 file >> actual_text;
1635 std::vector<uint8_t> v = {1, 2, 3};
1642 std::vector<bool> v = {
false,
true,
false,
false,
true,
true};
1649 std::deque<int> v = {1, 3, 3, 7};
1656template <
typename T>
1659 constexpr auto MAX{std::numeric_limits<T>::max()};
1669 BOOST_CHECK_EQUAL(CheckedLeftShift<T>(1, std::numeric_limits<T>::digits - 1), MAX / 2 + 1);
1672 BOOST_CHECK(!CheckedLeftShift<T>((MAX >> 1) + 1, 1));
1674 BOOST_CHECK(!CheckedLeftShift<T>(1, std::numeric_limits<T>::digits));
1675 BOOST_CHECK(!CheckedLeftShift<T>(1, std::numeric_limits<T>::digits + 1));
1677 if constexpr (std::is_signed_v<T>) {
1678 constexpr auto MIN{std::numeric_limits<T>::min()};
1685 BOOST_CHECK(!CheckedLeftShift<T>((MIN >> 1) - 1, 1));
1691template <
typename T>
1694 constexpr auto MAX{std::numeric_limits<T>::max()};
1704 BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(1, std::numeric_limits<T>::digits - 1), MAX / 2 + 1);
1709 BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(1, std::numeric_limits<T>::digits), MAX);
1710 BOOST_CHECK_EQUAL(SaturatingLeftShift<T>(1, std::numeric_limits<T>::digits + 1), MAX);
1712 if constexpr (std::is_signed_v<T>) {
1713 constexpr auto MIN{std::numeric_limits<T>::min()};
1728 TestCheckedLeftShift<uint8_t>();
1729 TestCheckedLeftShift<int8_t>();
1730 TestCheckedLeftShift<size_t>();
1731 TestCheckedLeftShift<uint64_t>();
1732 TestCheckedLeftShift<int64_t>();
1737 TestSaturatingLeftShift<uint8_t>();
1738 TestSaturatingLeftShift<int8_t>();
1739 TestSaturatingLeftShift<size_t>();
1740 TestSaturatingLeftShift<uint64_t>();
1741 TestSaturatingLeftShift<int64_t>();
1748 const auto max_mib{std::numeric_limits<size_t>::max() >> 20};
1749 BOOST_CHECK_EXCEPTION(
operator""_MiB(
static_cast<unsigned long long>(max_mib) + 1), std::overflow_error,
HasReason(
"MiB value too large for size_t byte conversion"));
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
#define Assert(val)
Identity function.
#define Assume(val)
Assume is the identity function.
An encapsulated private key.
bool IsValid() const
Check whether this private key is valid.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip...
uint256 MessageHash(const std::string &message)
Hashes a message for signing and verification in a manner that prevents inadvertently signing a trans...
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
const std::string MESSAGE_MAGIC
Text used to signify that a signed message follows and to prevent inadvertently signing a transaction...
MessageVerificationResult MessageVerify(const std::string &address, const std::string &signature, const std::string &message)
Verify a signed message.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
void ReleaseDirectoryLocks()
Release all directory locks.
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
#define T(expected, seed, data)
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
std::string LogEscapeMessage(std::string_view str)
Belts and suspenders: make sure outgoing log messages don't contain potentially suspicious characters...
std::span< const char > Expr(std::span< const char > &sp)
Extract the expression that sp begins with.
bool Const(const std::string &str, std::span< const char > &sp)
Parse a constant.
bool Func(const std::string &str, std::span< const char > &sp)
Parse a function call.
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
std::vector< std::string > SplitString(std::string_view str, char sep)
consteval uint8_t ConstevalHexDigit(const char c)
consteval version of HexDigit() without the lookup table.
std::string_view TrimStringView(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
std::vector< T > Split(const std::span< const char > &sp, std::string_view separators)
Split a string on any char found in separators, returning a vector.
std::string_view RemovePrefixView(std::string_view str, std::string_view prefix)
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
std::string RemovePrefix(std::string_view str, std::string_view prefix)
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
void ReplaceAll(std::string &in_out, const std::string &search, const std::string &substitute)
LockResult LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
std::optional< T > CheckedAdd(const T i, const T j) noexcept
T SaturatingAdd(const T i, const T j) noexcept
bool WriteBinaryFile(const fs::path &filename, const std::string &data)
Write contents of std::string to a file.
std::pair< bool, std::string > ReadBinaryFile(const fs::path &filename, size_t maxsize)
Read full contents of a file and return them in a std::string.
@ ERR_MALFORMED_SIGNATURE
The provided signature couldn't be parsed (maybe invalid base64).
@ ERR_INVALID_ADDRESS
The provided address is invalid.
@ ERR_ADDRESS_NO_KEY
The provided address is valid but does not refer to a public key.
@ ERR_NOT_SIGNED
The message was not signed with the private key of the provided address.
@ OK
The message verification was successful.
@ ERR_PUBKEY_NOT_RECOVERED
A public key could not be recovered from the provided signature and message.
auto MakeByteSpan(const V &v) noexcept
constexpr auto MakeUCharSpan(const V &v) -> decltype(UCharSpanCast(std::span{v}))
Like the std::span constructor, but for (const) unsigned char member types only.
auto MakeWritableByteSpan(V &&v) noexcept
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
@ SAFE_CHARS_UA_COMMENT
BIP-0014 subset.
static time_point now() noexcept
Return current system time or mocked time, if set.
#define TRY_LOCK(cs, name)
@ ZEROS
Seed with a compile time constant of zeros.
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
bool IsHex(std::string_view str)
std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
std::optional< std::vector< Byte > > TryParseHex(std::string_view str)
Parse the hex string into bytes (uint8_t or std::byte).
std::optional< uint64_t > ParseByteUnits(std::string_view str, ByteUnit default_multiplier)
Parse a string with suffix unit [k|K|m|M|g|G|t|T].
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
void UninterruptibleSleep(const std::chrono::microseconds &n)
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
std::string FormatISO8601Date(int64_t nTime)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::optional< int64_t > ParseISO8601DateTime(std::string_view str)
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
int64_t atoi64_legacy(const std::string &str)
constexpr uint8_t HEX_PARSE_OUTPUT[]
constexpr char HEX_PARSE_INPUT[]
static void TestOtherProcess(fs::path dirname, fs::path lockname, int fd)
static constexpr char ExitCommand
static constexpr char UnlockCommand
static std::string SpanToStr(const std::span< const char > &span)
static void TestAddMatrixOverflow()
static void TestAddMatrix()
BOOST_AUTO_TEST_CASE(util_check)
static void RunToIntegralTests()
static const std::string STRING_WITH_EMBEDDED_NULL_CHAR
static constexpr char LockCommand
void TestCheckedLeftShift()
void TestSaturatingLeftShift()
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.
std::vector< std::common_type_t< Args... > > Vector(Args &&... args)
Construct a vector with the specified elements.
void ClearShrink(V &v) noexcept
Clear a vector (or std::deque) and release its allocated memory.