39 #include <sys/types.h> 46 #include <boost/test/unit_test.hpp> 63 explicit NoCopyOrMove(
int i) : i{i} { }
65 NoCopyOrMove() =
delete;
66 NoCopyOrMove(
const NoCopyOrMove&) =
delete;
67 NoCopyOrMove(NoCopyOrMove&&) =
delete;
68 NoCopyOrMove& operator=(
const NoCopyOrMove&) =
delete;
69 NoCopyOrMove& operator=(NoCopyOrMove&&) =
delete;
71 operator bool()
const {
return i != 0; }
73 int get_ip1() {
return i + 1; }
77 [&]() {
Assume(get_ip1()); }();
78 return Assume(get_ip1() != 5);
86 const std::unique_ptr<int> p_two =
Assert(std::make_unique<int>(2));
88 const int two = *
Assert(p_two);
92 const bool result{
Assume(two == 2)};
105 const int nine{*
Assert(std::optional<int>{9})};
117 BOOST_ERROR(
"break was swallowed!");
127 BOOST_ERROR(
"break was swallowed!");
132 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7,
133 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde,
134 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12,
135 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d,
140 std::vector<unsigned char> result;
143 result =
ParseHex(
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
144 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
145 result = TryParseHex<uint8_t>(
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f").value();
146 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
150 BOOST_CHECK(result.size() == 4 && result[0] == 0x12 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78);
151 result = TryParseHex<uint8_t>(
"12 34 56 78").value();
152 BOOST_CHECK(result.size() == 4 && result[0] == 0x12 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78);
156 BOOST_CHECK(result.size() == 4 && result[0] == 0x89 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78);
157 result = TryParseHex<uint8_t>(
" 89 34 56 78").value();
158 BOOST_CHECK(result.size() == 4 && result[0] == 0x89 && result[1] == 0x34 && result[2] == 0x56 && result[3] == 0x78);
162 BOOST_CHECK(result.size() == 2 && result[0] == 0xff && result[1] == 0xaa);
163 result = TryParseHex<uint8_t>(
" Ff aA ").value();
164 BOOST_CHECK(result.size() == 2 && result[0] == 0xff && result[1] == 0xaa);
169 result = TryParseHex<uint8_t>(
"").value();
177 const std::string with_embedded_null{
" 11 "s
197 "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
211 const std::string out_exp{
"04678afdb0"};
219 auto input = std::string();
220 for (
size_t i=0; i<256; ++i) {
221 input.push_back(static_cast<char>(i));
225 BOOST_TEST_REQUIRE(hex.size() == 512);
226 static constexpr
auto hexmap = std::string_view(
"0123456789abcdef");
227 for (
size_t i = 0; i < 256; ++i) {
228 auto upper = hexmap.find(hex[i * 2]);
229 auto lower = hexmap.find(hex[i * 2 + 1]);
230 BOOST_TEST_REQUIRE(upper != std::string_view::npos);
231 BOOST_TEST_REQUIRE(lower != std::string_view::npos);
232 BOOST_TEST_REQUIRE(i == upper*16 + lower);
239 std::array mut_arr{uint8_t{0xaa}, uint8_t{0xbb}};
241 mut_bytes[1] = std::byte{0x11};
254 const auto op_upper = [](
const std::string& s) {
return ToUpper(s); };
262 const std::string original(
"A test \"%s\" string '%s'.");
263 auto test_replaceall = [&original](
const std::string& search,
const std::string& substitute,
const std::string& expected) {
264 auto test = original;
269 test_replaceall(
"",
"foo", original);
270 test_replaceall(original,
"foo",
"foo");
271 test_replaceall(
"%s",
"foo",
"A test \"foo\" string 'foo'.");
272 test_replaceall(
"\"",
"foo",
"A test foo%sfoo string '%s'.");
273 test_replaceall(
"'",
"foo",
"A test \"%s\" string foo%sfoo.");
288 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));
345 BOOST_CHECK_EQUAL(ParseMoney("12345.").value(), COIN * 12345); 347 BOOST_CHECK_EQUAL(ParseMoney("12345.6789").value(), (COIN/10000)*123456789); 349 BOOST_CHECK_EQUAL(ParseMoney("10000000.00").value(), COIN*10000000); 350 BOOST_CHECK_EQUAL(ParseMoney("1000000.00").value(), COIN*1000000); 351 BOOST_CHECK_EQUAL(ParseMoney("100000.00").value(), COIN*100000); 352 BOOST_CHECK_EQUAL(ParseMoney("10000.00").value(), COIN*10000); 353 BOOST_CHECK_EQUAL(ParseMoney("1000.00").value(), COIN*1000); 354 BOOST_CHECK_EQUAL(ParseMoney("100.00").value(), COIN*100); 355 BOOST_CHECK_EQUAL(ParseMoney("10.00").value(), COIN*10); 356 BOOST_CHECK_EQUAL(ParseMoney("1.00").value(), COIN); 357 BOOST_CHECK_EQUAL(ParseMoney("1").value(), COIN); 358 BOOST_CHECK_EQUAL(ParseMoney(" 1").value(), COIN); 359 BOOST_CHECK_EQUAL(ParseMoney("1 ").value(), COIN); 360 BOOST_CHECK_EQUAL(ParseMoney(" 1 ").value(), COIN); 361 BOOST_CHECK_EQUAL(ParseMoney("0.1").value(), COIN/10); 362 BOOST_CHECK_EQUAL(ParseMoney("0.01").value(), COIN/100); 363 BOOST_CHECK_EQUAL(ParseMoney("0.001").value(), COIN/1000); 364 BOOST_CHECK_EQUAL(ParseMoney("0.0001").value(), COIN/10000); 365 BOOST_CHECK_EQUAL(ParseMoney("0.00001").value(), COIN/100000); 366 BOOST_CHECK_EQUAL(ParseMoney("0.000001").value(), COIN/1000000); 367 BOOST_CHECK_EQUAL(ParseMoney("0.0000001").value(), COIN/10000000); 368 BOOST_CHECK_EQUAL(ParseMoney("0.00000001").value(), COIN/100000000); 369 BOOST_CHECK_EQUAL(ParseMoney(" 0.00000001 ").value(), COIN/100000000); 370 BOOST_CHECK_EQUAL(ParseMoney("0.00000001 ").value(), COIN/100000000); 371 BOOST_CHECK_EQUAL(ParseMoney(" 0.00000001").value(), COIN/100000000); 373 // Parsing amount that cannot be represented should fail 374 BOOST_CHECK(!ParseMoney("100000000.00")); 375 BOOST_CHECK(!ParseMoney("0.000000001")); 377 // Parsing empty string should fail 378 BOOST_CHECK(!ParseMoney("")); 379 BOOST_CHECK(!ParseMoney(" ")); 380 BOOST_CHECK(!ParseMoney(" ")); 382 // Parsing two numbers should fail 383 BOOST_CHECK(!ParseMoney("..")); 384 BOOST_CHECK(!ParseMoney("0..0")); 385 BOOST_CHECK(!ParseMoney("1 2")); 386 BOOST_CHECK(!ParseMoney(" 1 2 ")); 387 BOOST_CHECK(!ParseMoney(" 1.2 3 ")); 388 BOOST_CHECK(!ParseMoney(" 1 2.3 ")); 390 // Embedded whitespace should fail 391 BOOST_CHECK(!ParseMoney(" -1 .2 ")); 392 BOOST_CHECK(!ParseMoney(" 1 .2 ")); 393 BOOST_CHECK(!ParseMoney(" +1 .2 ")); 395 // Attempted 63 bit overflow should fail 396 BOOST_CHECK(!ParseMoney("92233720368.54775808")); 398 // Parsing negative amounts must fail 399 BOOST_CHECK(!ParseMoney("-1")); 401 // Parsing strings with embedded NUL characters should fail 402 BOOST_CHECK(!ParseMoney("\0-1"s)); 403 BOOST_CHECK(!ParseMoney(STRING_WITH_EMBEDDED_NULL_CHAR)); 404 BOOST_CHECK(!ParseMoney("1\0"s)); 407 BOOST_AUTO_TEST_CASE(util_IsHex) 409 BOOST_CHECK(IsHex("00")); 410 BOOST_CHECK(IsHex("00112233445566778899aabbccddeeffAABBCCDDEEFF")); 411 BOOST_CHECK(IsHex("ff")); 412 BOOST_CHECK(IsHex("FF")); 414 BOOST_CHECK(!IsHex("")); 415 BOOST_CHECK(!IsHex("0")); 416 BOOST_CHECK(!IsHex("a")); 417 BOOST_CHECK(!IsHex("eleven")); 418 BOOST_CHECK(!IsHex("00xx00")); 419 BOOST_CHECK(!IsHex("0x0000")); 422 BOOST_AUTO_TEST_CASE(util_IsHexNumber) 424 BOOST_CHECK(IsHexNumber("0x0")); 425 BOOST_CHECK(IsHexNumber("0")); 426 BOOST_CHECK(IsHexNumber("0x10")); 427 BOOST_CHECK(IsHexNumber("10")); 428 BOOST_CHECK(IsHexNumber("0xff")); 429 BOOST_CHECK(IsHexNumber("ff")); 430 BOOST_CHECK(IsHexNumber("0xFfa")); 431 BOOST_CHECK(IsHexNumber("Ffa")); 432 BOOST_CHECK(IsHexNumber("0x00112233445566778899aabbccddeeffAABBCCDDEEFF")); 433 BOOST_CHECK(IsHexNumber("00112233445566778899aabbccddeeffAABBCCDDEEFF")); 435 BOOST_CHECK(!IsHexNumber("")); // empty string not allowed 436 BOOST_CHECK(!IsHexNumber("0x")); // empty string after prefix not allowed 437 BOOST_CHECK(!IsHexNumber("0x0 ")); // no spaces at end, 438 BOOST_CHECK(!IsHexNumber(" 0x0")); // or beginning, 439 BOOST_CHECK(!IsHexNumber("0x 0")); // or middle, 440 BOOST_CHECK(!IsHexNumber(" ")); // etc. 441 BOOST_CHECK(!IsHexNumber("0x0ga")); // invalid character 442 BOOST_CHECK(!IsHexNumber("x0")); // broken prefix 443 BOOST_CHECK(!IsHexNumber("0x0x00")); // two prefixes not allowed 447 BOOST_AUTO_TEST_CASE(util_seed_insecure_rand) 449 SeedInsecureRand(SeedRand::ZEROS); 450 for (int mod=2;mod<11;mod++) 453 // Really rough binomial confidence approximation. 454 int err = 30*10000./mod*sqrt((1./mod*(1-1./mod))/10000.); 455 //mask is 2^ceil(log2(mod))-1 456 while(mask<mod-1)mask=(mask<<1)+1; 459 //How often does it get a zero from the uniform range [0,mod)? 460 for (int i = 0; i < 10000; i++) { 463 rval=InsecureRand32()&mask; 464 }while(rval>=(uint32_t)mod); 467 BOOST_CHECK(count<=10000/mod+err); 468 BOOST_CHECK(count>=10000/mod-err); 472 BOOST_AUTO_TEST_CASE(util_TimingResistantEqual) 474 BOOST_CHECK(TimingResistantEqual(std::string(""), std::string(""))); 475 BOOST_CHECK(!TimingResistantEqual(std::string("abc"), std::string(""))); 476 BOOST_CHECK(!TimingResistantEqual(std::string(""), std::string("abc"))); 477 BOOST_CHECK(!TimingResistantEqual(std::string("a"), std::string("aa"))); 478 BOOST_CHECK(!TimingResistantEqual(std::string("aa"), std::string("a"))); 479 BOOST_CHECK(TimingResistantEqual(std::string("abc"), std::string("abc"))); 480 BOOST_CHECK(!TimingResistantEqual(std::string("abc"), std::string("aba"))); 483 /* Test strprintf formatting directives. 484 * Put a string before and after to ensure sanity of element sizes on stack. */ 485 #define B "check_prefix" 486 #define E "check_postfix" 487 BOOST_AUTO_TEST_CASE(strprintf_numbers) 489 int64_t s64t = -9223372036854775807LL; /* signed 64 bit test value */ 490 uint64_t u64t = 18446744073709551615ULL; /* unsigned 64 bit test value */ 491 BOOST_CHECK(strprintf("%s %d %s", B, s64t, E) == B" -9223372036854775807 " E); 492 BOOST_CHECK(strprintf("%s %u %s", B, u64t, E) == B" 18446744073709551615 " E); 493 BOOST_CHECK(strprintf("%s %x %s", B, u64t, E) == B" ffffffffffffffff " E); 495 size_t st = 12345678; /* unsigned size_t test value */ 496 ssize_t sst = -12345678; /* signed size_t test value */ 497 BOOST_CHECK(strprintf("%s %d %s", B, sst, E) == B" -12345678 " E); 498 BOOST_CHECK(strprintf("%s %u %s", B, st, E) == B" 12345678 " E); 499 BOOST_CHECK(strprintf("%s %x %s", B, st, E) == B" bc614e " E); 501 ptrdiff_t pt = 87654321; /* positive ptrdiff_t test value */ 502 ptrdiff_t spt = -87654321; /* negative ptrdiff_t test value */ 503 BOOST_CHECK(strprintf("%s %d %s", B, spt, E) == B" -87654321 " E); 504 BOOST_CHECK(strprintf("%s %u %s", B, pt, E) == B" 87654321 " E); 505 BOOST_CHECK(strprintf("%s %x %s", B, pt, E) == B" 5397fb1 " E); 510 /* Check for mingw/wine issue #3494 511 * Remove this test before time.ctime(0xffffffff) == 'Sun Feb 7 07:28:15 2106
' 513 BOOST_AUTO_TEST_CASE(gettime) 515 BOOST_CHECK((GetTime() & ~0xFFFFFFFFLL) == 0); 518 BOOST_AUTO_TEST_CASE(util_time_GetTime) 521 // Check that mock time does not change after a sleep 522 for (const auto& num_sleep : {0ms, 1ms}) { 523 UninterruptibleSleep(num_sleep); 524 BOOST_CHECK_EQUAL(111, GetTime()); // Deprecated time getter 525 BOOST_CHECK_EQUAL(111, Now<NodeSeconds>().time_since_epoch().count()); 526 BOOST_CHECK_EQUAL(111, TicksSinceEpoch<std::chrono::seconds>(NodeClock::now())); 527 BOOST_CHECK_EQUAL(111, TicksSinceEpoch<SecondsDouble>(Now<NodeSeconds>())); 528 BOOST_CHECK_EQUAL(111, GetTime<std::chrono::seconds>().count()); 529 BOOST_CHECK_EQUAL(111000, GetTime<std::chrono::milliseconds>().count()); 530 BOOST_CHECK_EQUAL(111000, TicksSinceEpoch<std::chrono::milliseconds>(NodeClock::now())); 531 BOOST_CHECK_EQUAL(111000000, GetTime<std::chrono::microseconds>().count()); 535 // Check that steady time and system time changes after a sleep 536 const auto steady_ms_0 = Now<SteadyMilliseconds>(); 537 const auto steady_0 = std::chrono::steady_clock::now(); 538 const auto ms_0 = GetTime<std::chrono::milliseconds>(); 539 const auto us_0 = GetTime<std::chrono::microseconds>(); 540 UninterruptibleSleep(1ms); 541 BOOST_CHECK(steady_ms_0 < Now<SteadyMilliseconds>()); 542 BOOST_CHECK(steady_0 + 1ms <= std::chrono::steady_clock::now()); 543 BOOST_CHECK(ms_0 < GetTime<std::chrono::milliseconds>()); 544 BOOST_CHECK(us_0 < GetTime<std::chrono::microseconds>()); 547 BOOST_AUTO_TEST_CASE(test_IsDigit) 549 BOOST_CHECK_EQUAL(IsDigit('0
'), true); 550 BOOST_CHECK_EQUAL(IsDigit('1
'), true); 551 BOOST_CHECK_EQUAL(IsDigit('8
'), true); 552 BOOST_CHECK_EQUAL(IsDigit('9
'), true); 554 BOOST_CHECK_EQUAL(IsDigit('0
' - 1), false); 555 BOOST_CHECK_EQUAL(IsDigit('9
' + 1), false); 556 BOOST_CHECK_EQUAL(IsDigit(0), false); 557 BOOST_CHECK_EQUAL(IsDigit(1), false); 558 BOOST_CHECK_EQUAL(IsDigit(8), false); 559 BOOST_CHECK_EQUAL(IsDigit(9), false); 562 /* Check for overflow */ 563 template <typename T> 564 static void TestAddMatrixOverflow() 566 constexpr T MAXI{std::numeric_limits<T>::max()}; 567 BOOST_CHECK(!CheckedAdd(T{1}, MAXI)); 568 BOOST_CHECK(!CheckedAdd(MAXI, MAXI)); 569 BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{1}, MAXI)); 570 BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(MAXI, MAXI)); 572 BOOST_CHECK_EQUAL(0, CheckedAdd(T{0}, T{0}).value()); 573 BOOST_CHECK_EQUAL(MAXI, CheckedAdd(T{0}, MAXI).value()); 574 BOOST_CHECK_EQUAL(MAXI, CheckedAdd(T{1}, MAXI - 1).value()); 575 BOOST_CHECK_EQUAL(MAXI - 1, CheckedAdd(T{1}, MAXI - 2).value()); 576 BOOST_CHECK_EQUAL(0, SaturatingAdd(T{0}, T{0})); 577 BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{0}, MAXI)); 578 BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{1}, MAXI - 1)); 579 BOOST_CHECK_EQUAL(MAXI - 1, SaturatingAdd(T{1}, MAXI - 2)); 582 /* Check for overflow or underflow */ 583 template <typename T> 584 static void TestAddMatrix() 586 TestAddMatrixOverflow<T>(); 587 constexpr T MINI{std::numeric_limits<T>::min()}; 588 constexpr T MAXI{std::numeric_limits<T>::max()}; 589 BOOST_CHECK(!CheckedAdd(T{-1}, MINI)); 590 BOOST_CHECK(!CheckedAdd(MINI, MINI)); 591 BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{-1}, MINI)); 592 BOOST_CHECK_EQUAL(MINI, SaturatingAdd(MINI, MINI)); 594 BOOST_CHECK_EQUAL(MINI, CheckedAdd(T{0}, MINI).value()); 595 BOOST_CHECK_EQUAL(MINI, CheckedAdd(T{-1}, MINI + 1).value()); 596 BOOST_CHECK_EQUAL(-1, CheckedAdd(MINI, MAXI).value()); 597 BOOST_CHECK_EQUAL(MINI + 1, CheckedAdd(T{-1}, MINI + 2).value()); 598 BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{0}, MINI)); 599 BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{-1}, MINI + 1)); 600 BOOST_CHECK_EQUAL(MINI + 1, SaturatingAdd(T{-1}, MINI + 2)); 601 BOOST_CHECK_EQUAL(-1, SaturatingAdd(MINI, MAXI)); 604 BOOST_AUTO_TEST_CASE(util_overflow) 606 TestAddMatrixOverflow<unsigned>(); 607 TestAddMatrix<signed>(); 610 BOOST_AUTO_TEST_CASE(test_ParseInt32) 614 BOOST_CHECK(ParseInt32("1234", nullptr)); 615 BOOST_CHECK(ParseInt32("0", &n) && n == 0); 616 BOOST_CHECK(ParseInt32("1234", &n) && n == 1234); 617 BOOST_CHECK(ParseInt32("01234", &n) && n == 1234); // no octal 618 BOOST_CHECK(ParseInt32("2147483647", &n) && n == 2147483647); 619 BOOST_CHECK(ParseInt32("-2147483648", &n) && n == (-2147483647 - 1)); // (-2147483647 - 1) equals INT_MIN 620 BOOST_CHECK(ParseInt32("-1234", &n) && n == -1234); 621 BOOST_CHECK(ParseInt32("00000000000000001234", &n) && n == 1234); 622 BOOST_CHECK(ParseInt32("-00000000000000001234", &n) && n == -1234); 623 BOOST_CHECK(ParseInt32("00000000000000000000", &n) && n == 0); 624 BOOST_CHECK(ParseInt32("-00000000000000000000", &n) && n == 0); 626 BOOST_CHECK(!ParseInt32("", &n)); 627 BOOST_CHECK(!ParseInt32(" 1", &n)); // no padding inside 628 BOOST_CHECK(!ParseInt32("1 ", &n)); 629 BOOST_CHECK(!ParseInt32("++1", &n)); 630 BOOST_CHECK(!ParseInt32("+-1", &n)); 631 BOOST_CHECK(!ParseInt32("-+1", &n)); 632 BOOST_CHECK(!ParseInt32("--1", &n)); 633 BOOST_CHECK(!ParseInt32("1a", &n)); 634 BOOST_CHECK(!ParseInt32("aap", &n)); 635 BOOST_CHECK(!ParseInt32("0x1", &n)); // no hex 636 BOOST_CHECK(!ParseInt32(STRING_WITH_EMBEDDED_NULL_CHAR, &n)); 637 // Overflow and underflow 638 BOOST_CHECK(!ParseInt32("-2147483649", nullptr)); 639 BOOST_CHECK(!ParseInt32("2147483648", nullptr)); 640 BOOST_CHECK(!ParseInt32("-32482348723847471234", nullptr)); 641 BOOST_CHECK(!ParseInt32("32482348723847471234", nullptr)); 644 template <typename T> 645 static void RunToIntegralTests() 647 BOOST_CHECK(!ToIntegral<T>(STRING_WITH_EMBEDDED_NULL_CHAR)); 648 BOOST_CHECK(!ToIntegral<T>(" 1")); 649 BOOST_CHECK(!ToIntegral<T>("1 ")); 650 BOOST_CHECK(!ToIntegral<T>("1a")); 651 BOOST_CHECK(!ToIntegral<T>("1.1")); 652 BOOST_CHECK(!ToIntegral<T>("1.9")); 653 BOOST_CHECK(!ToIntegral<T>("+01.9")); 654 BOOST_CHECK(!ToIntegral<T>("-")); 655 BOOST_CHECK(!ToIntegral<T>("+")); 656 BOOST_CHECK(!ToIntegral<T>(" -1")); 657 BOOST_CHECK(!ToIntegral<T>("-1 ")); 658 BOOST_CHECK(!ToIntegral<T>(" -1 ")); 659 BOOST_CHECK(!ToIntegral<T>("+1")); 660 BOOST_CHECK(!ToIntegral<T>(" +1")); 661 BOOST_CHECK(!ToIntegral<T>(" +1 ")); 662 BOOST_CHECK(!ToIntegral<T>("+-1")); 663 BOOST_CHECK(!ToIntegral<T>("-+1")); 664 BOOST_CHECK(!ToIntegral<T>("++1")); 665 BOOST_CHECK(!ToIntegral<T>("--1")); 666 BOOST_CHECK(!ToIntegral<T>("")); 667 BOOST_CHECK(!ToIntegral<T>("aap")); 668 BOOST_CHECK(!ToIntegral<T>("0x1")); 669 BOOST_CHECK(!ToIntegral<T>("-32482348723847471234")); 670 BOOST_CHECK(!ToIntegral<T>("32482348723847471234")); 673 BOOST_AUTO_TEST_CASE(test_ToIntegral) 675 BOOST_CHECK_EQUAL(ToIntegral<int32_t>("1234").value(), 1'234);
678 BOOST_CHECK_EQUAL(ToIntegral<int32_t>("00000000000000001234").value(), 1'234);
680 BOOST_CHECK_EQUAL(ToIntegral<int32_t>("00000000000000000000").value(), 0); 681 BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-00000000000000000000").value(), 0); 682 BOOST_CHECK_EQUAL(ToIntegral<int32_t>("-1234").value(), -1'234);
685 RunToIntegralTests<uint64_t>();
686 RunToIntegralTests<int64_t>();
687 RunToIntegralTests<uint32_t>();
688 RunToIntegralTests<int32_t>();
689 RunToIntegralTests<uint16_t>();
690 RunToIntegralTests<int16_t>();
691 RunToIntegralTests<uint8_t>();
692 RunToIntegralTests<int8_t>();
694 BOOST_CHECK(!ToIntegral<int64_t>(
"-9223372036854775809"));
695 BOOST_CHECK_EQUAL(ToIntegral<int64_t>(
"-9223372036854775808").value(), -9
'223'372
'036'854
'775'807LL - 1LL);
696 BOOST_CHECK_EQUAL(ToIntegral<int64_t>(
"9223372036854775807").value(), 9
'223'372
'036'854
'775'807);
697 BOOST_CHECK(!ToIntegral<int64_t>(
"9223372036854775808"));
701 BOOST_CHECK_EQUAL(ToIntegral<uint64_t>(
"18446744073709551615").value(), 18
'446'744
'073'709
'551'615ULL);
702 BOOST_CHECK(!ToIntegral<uint64_t>(
"18446744073709551616"));
706 BOOST_CHECK_EQUAL(ToIntegral<int32_t>("2147483647").value(), 2'147
'483'647);
712 BOOST_CHECK(!ToIntegral<uint32_t>("4294967296")); 714 BOOST_CHECK(!ToIntegral<int16_t>("-32769")); 715 BOOST_CHECK_EQUAL(ToIntegral<int16_t>("-32768").value(), -32'768);
717 BOOST_CHECK(!ToIntegral<int16_t>("32768")); 719 BOOST_CHECK(!ToIntegral<uint16_t>("-1")); 720 BOOST_CHECK_EQUAL(ToIntegral<uint16_t>("0").value(), 0U); 721 BOOST_CHECK_EQUAL(ToIntegral<uint16_t>("65535").value(), 65'535U);
737 return strtoll(str.c_str(),
nullptr, 10);
743 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("0"), 0); 744 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("01234"), 1'234);
746 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" 1"), 1); 747 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1 "), 1); 748 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1a"), 1); 749 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1.1"), 1); 750 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1.9"), 1); 751 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+01.9"), 1); 752 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1"), -1); 753 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" -1"), -1); 754 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1 "), -1); 755 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" -1 "), -1); 756 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+1"), 1); 757 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" +1"), 1); 758 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" +1 "), 1); 760 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+-1"), 0); 761 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-+1"), 0); 762 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("++1"), 0); 763 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("--1"), 0); 764 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(""), 0); 765 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("aap"), 0); 766 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("0x1"), 0); 767 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-32482348723847471234"), -2'147
'483'647 - 1);
768 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(
"32482348723847471234"), 2
'147'483
'647); 770 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("-9223372036854775809"), -9'223
'372'036
'854'775
'807LL - 1LL); 771 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("-9223372036854775808"), -9'223
'372'036
'854'775
'807LL - 1LL); 772 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("9223372036854775807"), 9'223
'372'036
'854'775
'807); 773 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("9223372036854775808"), 9'223
'372'036
'854'775
'807); 775 std::map<std::string, int64_t> atoi64_test_pairs = { 776 {"-9223372036854775809", std::numeric_limits<int64_t>::min()}, 777 {"-9223372036854775808", -9'223
'372'036
'854'775
'807LL - 1LL}, 778 {"9223372036854775807", 9'223
'372'036
'854'775
'807}, 779 {"9223372036854775808", std::numeric_limits<int64_t>::max()}, 786 for (const auto& pair : atoi64_test_pairs) { 787 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(pair.first), pair.second); 790 // Ensure legacy compatibility with previous versions of Bitcoin Core's atoi64
791 for (
const auto& pair : atoi64_test_pairs) {
797 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>(
"18446744073709551615"), 18
'446'744
'073'709
'551'615ULL);
798 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>(
"18446744073709551616"), 18
'446'744
'073'709
'551'615ULL);
800 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(
"-2147483649"), -2
'147'483
'648LL); 801 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-2147483648"), -2'147
'483'648LL);
803 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("2147483648"), 2'147
'483'647);
807 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>(
"4294967295"), 4
'294'967
'295U); 808 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("4294967296"), 4'294
'967'295U);
811 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("-32768"), -32'768);
813 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("32768"), 32'767);
818 BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("65536"), 65'535U);
1009 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");
1012 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");
1013 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");
1015 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");
1017 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.");
1018 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.");
1019 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.");
1020 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.");
1025 std::vector<std::string> comments;
1026 comments.emplace_back(
"comment1");
1027 std::vector<std::string> comments2;
1028 comments2.emplace_back(
"comment1");
1114 #ifndef WIN32 // Cannot do this test on WIN32 due to lack of fork() 1123 int rv = read(fd, &ch, 1);
1128 rv = write(fd, &ch, 1);
1134 rv = write(fd, &ch, 1);
1149 fs::path dirname = m_args.GetDataDirBase() /
"lock_dir";
1155 void (*old_handler)(int) = signal(SIGCHLD, SIG_DFL);
1227 signal(SIGCHLD, old_handler);
1232 fs::remove_all(dirname);
1238 fs::path tmpdirname = m_args.GetDataDirBase();
1245 fs::create_directory(tmpdirname);
1248 fs::remove(tmpdirname);
1288 return std::string(span.
begin(), span.
end());
1299 input =
"MilkToastHoney";
1301 success =
Const(
"", sp);
1305 success =
Const(
"Milk", sp);
1309 success =
Const(
"Bread", sp);
1312 success =
Const(
"Toast", sp);
1316 success =
Const(
"Honeybadger", sp);
1319 success =
Const(
"Honey", sp);
1324 input =
"Foo(Bar(xy,z()))";
1327 success =
Func(
"FooBar", sp);
1330 success =
Func(
"Foo(", sp);
1333 success =
Func(
"Foo", sp);
1337 success =
Func(
"Bar", sp);
1341 success =
Func(
"xy", sp);
1347 input =
"(n*(n-1))/2";
1359 input =
"(aaaaa,bbbbb()),c";
1371 input =
"((a),(b),(c)),xxx";
1378 std::vector<Span<const char>> results;
1381 results =
Split(input,
'x');
1388 input =
"one#two#three";
1389 results =
Split(input,
'-');
1393 input =
"one#two#three";
1394 results =
Split(input,
'#');
1400 input =
"*foo*bar*";
1401 results =
Split(input,
'*');
1413 std::vector<std::string> result =
SplitString(
"",
'-');
1420 std::vector<std::string> result =
SplitString(
"-",
'-');
1428 std::vector<std::string> result =
SplitString(
"--",
'-');
1437 std::vector<std::string> result =
SplitString(
"abc",
'-');
1444 std::vector<std::string> result =
SplitString(
"a-b",
'-');
1452 std::vector<std::string> result =
SplitString(
"AAA",
'a');
1459 using V = std::vector<std::string>;
1460 BOOST_TEST(
SplitString(
"a,b.c:d;e",
",;") == V({
"a",
"b.c:d",
"e"}));
1461 BOOST_TEST(
SplitString(
"a,b.c:d;e",
",;:.") == V({
"a",
"b",
"c",
"d",
"e"}));
1462 BOOST_TEST(
SplitString(
"a,b.c:d;e",
"") == V({
"a,b.c:d;e"}));
1463 BOOST_TEST(
SplitString(
"aaa",
"bcdefg") == V({
"aaa"}));
1464 BOOST_TEST(
SplitString(
"x\0a,b"s,
"\0"s) == V({
"x",
"a,b"}));
1465 BOOST_TEST(
SplitString(
"x\0a,b"s,
'\0') == V({
"x",
"a,b"}));
1466 BOOST_TEST(
SplitString(
"x\0a,b"s,
"\0,"s) == V({
"x",
"a",
"b"}));
1467 BOOST_TEST(
SplitString(
"abcdefg",
"bcd") == V({
"a",
"",
"",
"efg"}));
1480 const std::string NUL(
"O\x00O", 3);
1489 const Tracker* origin;
1493 Tracker() noexcept : origin(this) {}
1494 Tracker(
const Tracker& t) noexcept : origin(
t.origin), copies(
t.copies + 1) {}
1495 Tracker(Tracker&& t) noexcept : origin(
t.origin), copies(
t.copies) {}
1496 Tracker& operator=(
const Tracker& t) noexcept
1499 copies =
t.copies + 1;
1521 auto v2 =
Vector(std::move(t2));
1526 auto v3 =
Vector(t1, std::move(t2));
1533 auto v4 =
Vector(std::move(v3[0]), v3[1], std::move(t3));
1542 auto v5 =
Cat(v1, v4);
1553 auto v6 =
Cat(std::move(v1), v3);
1562 auto v7 =
Cat(v2, std::move(v4));
1573 auto v8 =
Cat(std::move(v2), std::move(v3));
1585 const std::array<unsigned char, 32> privkey_bytes = {
1588 0xD9, 0x7F, 0x51, 0x08, 0xF1, 0x1C, 0xDA, 0x6E,
1589 0xEE, 0xBA, 0xAA, 0x42, 0x0F, 0xEF, 0x07, 0x26,
1590 0xB1, 0xF8, 0x98, 0x06, 0x0B, 0x98, 0x48, 0x9F,
1591 0xA3, 0x09, 0x84, 0x63, 0xC0, 0x03, 0x28, 0x66
1594 const std::string message =
"Trust no one";
1596 const std::string expected_signature =
1597 "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=";
1600 std::string generated_signature;
1602 BOOST_REQUIRE_MESSAGE(!privkey.
IsValid(),
1603 "Confirm the private key is invalid");
1605 BOOST_CHECK_MESSAGE(!
MessageSign(privkey, message, generated_signature),
1606 "Sign with an invalid private key");
1608 privkey.
Set(privkey_bytes.begin(), privkey_bytes.end(),
true);
1610 BOOST_REQUIRE_MESSAGE(privkey.
IsValid(),
1611 "Confirm the private key is valid");
1613 BOOST_CHECK_MESSAGE(
MessageSign(privkey, message, generated_signature),
1614 "Sign with a valid private key");
1624 "signature should be irrelevant",
1630 "3B5fQsEXEaV8v6U3ejYc8XaKXAkyQj2MjV",
1631 "signature should be irrelevant",
1637 "1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",
1638 "invalid signature, not in base64 encoding",
1639 "message should be irrelevant"),
1644 "1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",
1645 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
1646 "message should be irrelevant"),
1651 "15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",
1652 "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",
1653 "I never signed this"),
1658 "15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",
1659 "IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",
1665 "11canuhp9X2NocwCq7xNrQYTmUgZAnLK3",
1666 "IIcaIENoYW5jZWxsb3Igb24gYnJpbmsgb2Ygc2Vjb25kIGJhaWxvdXQgZm9yIGJhbmtzIAaHRtbCeDZINyavx14=",
1673 const std::string unsigned_tx =
"...";
1674 const std::string prefixed_message =
1677 std::string(1, (
char)unsigned_tx.length()) +
1681 const uint256 message_hash1 =
Hash(prefixed_message);
1685 BOOST_CHECK_NE(message_hash1, signature_hash);
1716 BOOST_CHECK_EQUAL(ParseByteUnits("3G", noop).value(), 3ULL << 30); 1718 BOOST_CHECK_EQUAL(ParseByteUnits("4t", noop).value(), 4'000
'000'000
'000ULL); 1719 BOOST_CHECK_EQUAL(ParseByteUnits("4T", noop).value(), 4ULL << 40); 1721 // check default multiplier 1722 BOOST_CHECK_EQUAL(ParseByteUnits("5", ByteUnit::K).value(), 5ULL << 10); 1725 BOOST_CHECK(!ParseByteUnits("", noop)); 1726 BOOST_CHECK(!ParseByteUnits("foo", noop)); 1729 BOOST_CHECK(!ParseByteUnits("123m ", noop)); 1730 BOOST_CHECK(!ParseByteUnits(" 123m", noop)); 1733 BOOST_CHECK(!ParseByteUnits("-123m", noop)); 1734 BOOST_CHECK(!ParseByteUnits("+123m", noop)); 1737 BOOST_CHECK_EQUAL(ParseByteUnits("020M", noop).value(), 20ULL << 20); 1739 // fractions not allowed 1740 BOOST_CHECK(!ParseByteUnits("0.5T", noop)); 1743 BOOST_CHECK(!ParseByteUnits("18446744073709551615g", noop)); 1746 BOOST_CHECK(!ParseByteUnits("1x", noop)); 1749 BOOST_AUTO_TEST_CASE(util_ReadBinaryFile) 1751 fs::path tmpfolder = m_args.GetDataDirBase(); 1752 fs::path tmpfile = tmpfolder / "read_binary.dat"; 1753 std::string expected_text; 1754 for (int i = 0; i < 30; i++) { 1755 expected_text += "0123456789"; 1758 std::ofstream file{tmpfile}; 1759 file << expected_text; 1762 // read all contents in file 1763 auto [valid, text] = ReadBinaryFile(tmpfile); 1765 BOOST_CHECK_EQUAL(text, expected_text); 1768 // read half contents in file 1769 auto [valid, text] = ReadBinaryFile(tmpfile, expected_text.size() / 2); 1771 BOOST_CHECK_EQUAL(text, expected_text.substr(0, expected_text.size() / 2)); 1774 // read from non-existent file 1775 fs::path invalid_file = tmpfolder / "invalid_binary.dat"; 1776 auto [valid, text] = ReadBinaryFile(invalid_file); 1777 BOOST_CHECK(!valid); 1778 BOOST_CHECK(text.empty()); 1782 BOOST_AUTO_TEST_CASE(util_WriteBinaryFile) 1784 fs::path tmpfolder = m_args.GetDataDirBase(); 1785 fs::path tmpfile = tmpfolder / "write_binary.dat"; 1786 std::string expected_text = "bitcoin"; 1787 auto valid = WriteBinaryFile(tmpfile, expected_text); 1788 std::string actual_text; 1789 std::ifstream file{tmpfile}; 1790 file >> actual_text; 1792 BOOST_CHECK_EQUAL(actual_text, expected_text); 1795 BOOST_AUTO_TEST_CASE(clearshrink_test) 1798 std::vector<uint8_t> v = {1, 2, 3}; 1800 BOOST_CHECK_EQUAL(v.size(), 0); 1801 BOOST_CHECK_EQUAL(v.capacity(), 0); 1805 std::vector<bool> v = {false, true, false, false, true, true}; 1807 BOOST_CHECK_EQUAL(v.size(), 0); 1808 BOOST_CHECK_EQUAL(v.capacity(), 0); 1812 std::deque<int> v = {1, 3, 3, 7}; 1814 BOOST_CHECK_EQUAL(v.size(), 0); 1815 // std::deque has no capacity() we can observe. 1819 BOOST_AUTO_TEST_SUITE_END()
static void TestOtherThread(fs::path dirname, fs::path lockname, bool *result)
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
std::vector< T > Split(const Span< const char > &sp, std::string_view separators)
Split a string on any char found in separators, returning a vector.
bool Func(const std::string &str, Span< const char > &sp)
Parse a function call.
std::string FormatISO8601Date(int64_t nTime)
#define TRY_LOCK(cs, name)
constexpr C * end() const noexcept
The provided signature couldn't be parsed (maybe invalid base64).
MessageVerificationResult MessageVerify(const std::string &address, const std::string &signature, const std::string &message)
Verify a signed message.
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
bool Const(const std::string &str, Span< const char > &sp)
Parse a constant.
std::string_view TrimStringView(std::string_view str, std::string_view pattern=" \\\)
bool ParseUInt64(std::string_view str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
fs::path GetUniquePath(const fs::path &base)
Helper function for getting a unique path.
The message verification was successful.
std::vector< std::string > SplitString(std::string_view str, char sep)
bool DirIsWritable(const fs::path &directory)
static const unsigned char ParseHex_expected[65]
int64_t atoi64_legacy(const std::string &str)
Span< const char > Expr(Span< const char > &sp)
Extract the expression that sp begins with.
std::vector< typename std::common_type< Args... >::type > Vector(Args &&... args)
Construct a vector with the specified elements.
BOOST_AUTO_TEST_CASE(util_check)
int64_t CAmount
Amount in satoshis (Can be negative)
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
bool ParseUInt32(std::string_view str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
static constexpr char ExitCommand
std::string_view RemovePrefixView(std::string_view str, std::string_view prefix)
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
static const std::string STRING_WITH_EMBEDDED_NULL_CHAR
bool ParseUInt16(std::string_view str, uint16_t *out)
Convert decimal string to unsigned 16-bit integer with strict parse error feedback.
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::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
bool ParseUInt8(std::string_view str, uint8_t *out)
Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
uint256 MessageHash(const std::string &message)
Hashes a message for signing and verification in a manner that prevents inadvertently signing a trans...
void ReplaceAll(std::string &in_out, const std::string &search, const std::string &substitute)
void ReleaseDirectoryLocks()
Release all directory locks.
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...
static constexpr char LockCommand
bool LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
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 Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
#define Assume(val)
Assume is the identity function.
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
The message was not signed with the private key of the provided address.
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
constexpr C * begin() const noexcept
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
bool ParseInt64(std::string_view str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
#define BOOST_CHECK_EQUAL(v1, v2)
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
The provided address is invalid.
Span< const std::byte > MakeByteSpan(V &&v) noexcept
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...
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span
Like the Span constructor, but for (const) unsigned char member types only.
std::string RemovePrefix(std::string_view str, std::string_view prefix)
static void TestOtherProcess(fs::path dirname, fs::path lockname, int fd)
std::optional< std::vector< Byte > > TryParseHex(std::string_view str)
Parse the hex string into bytes (uint8_t or std::byte).
const std::string MESSAGE_MAGIC
Text used to signify that a signed message follows and to prevent inadvertently signing a transaction...
An encapsulated private key.
A Span is an object that can refer to a contiguous sequence of objects.
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
std::string LogEscapeMessage(const std::string &str)
Belts and suspenders: make sure outgoing log messages don't contain potentially suspicious characters...
A public key could not be recovered from the provided signature and message.
std::string TrimString(std::string_view str, std::string_view pattern=" \\\)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static std::string SpanToStr(const Span< const char > &span)
static constexpr char UnlockCommand
The provided address is valid but does not refer to a public key.
#define Assert(val)
Identity function.
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
bool IsValid() const
Check whether this private key is valid.
#define BOOST_CHECK(expr)
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.
static constexpr CAmount COIN
The amount of satoshis in one BTC.
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.