Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
752BOOST_CHECK(!ToIntegral<int16_t>("-32769"));753BOOST_CHECK_EQUAL(ToIntegral<int16_t>("-32768").value(), -32'768);754BOOST_CHECK_EQUAL(ToIntegral<int16_t>("32767").value(), 32'767);755BOOST_CHECK(!ToIntegral<int16_t>("32768"));757BOOST_CHECK(!ToIntegral<uint16_t>("-1"));758BOOST_CHECK_EQUAL(ToIntegral<uint16_t>("0").value(), 0U);759BOOST_CHECK_EQUAL(ToIntegral<uint16_t>("65535").value(), 65'535U);760BOOST_CHECK(!ToIntegral<uint16_t>("65536"));762BOOST_CHECK(!ToIntegral<int8_t>("-129"));763BOOST_CHECK_EQUAL(ToIntegral<int8_t>("-128").value(), -128);764BOOST_CHECK_EQUAL(ToIntegral<int8_t>("127").value(), 127);765BOOST_CHECK(!ToIntegral<int8_t>("128"));767BOOST_CHECK(!ToIntegral<uint8_t>("-1"));768BOOST_CHECK_EQUAL(ToIntegral<uint8_t>("0").value(), 0U);769BOOST_CHECK_EQUAL(ToIntegral<uint8_t>("255").value(), 255U);770BOOST_CHECK(!ToIntegral<uint8_t>("256"));771}773int64_t atoi64_legacy(const std::string& str)774{775return strtoll(str.c_str(), nullptr, 10);776}778BOOST_AUTO_TEST_CASE(test_LocaleIndependentAtoi)779{780BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1234"), 1'234);781BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("0"), 0);782BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("01234"), 1'234);783BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1234"), -1'234);784BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" 1"), 1);785BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1 "), 1);786BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1a"), 1);787BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1.1"), 1);788BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("1.9"), 1);789BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+01.9"), 1);790BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1"), -1);791BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" -1"), -1);792BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-1 "), -1);793BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" -1 "), -1);794BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+1"), 1);795BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" +1"), 1);796BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(" +1 "), 1);798BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("+-1"), 0);799BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-+1"), 0);800BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("++1"), 0);801BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("--1"), 0);802BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>(""), 0);803BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("aap"), 0);804BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("0x1"), 0);805BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-32482348723847471234"), -2'147'483'647 - 1);806BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("32482348723847471234"), 2'147'483'647);808BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("-9223372036854775809"), -9'223'372'036'854'775'807LL - 1LL);809BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("-9223372036854775808"), -9'223'372'036'854'775'807LL - 1LL);810BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("9223372036854775807"), 9'223'372'036'854'775'807);811BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>("9223372036854775808"), 9'223'372'036'854'775'807);813std::map<std::string, int64_t> atoi64_test_pairs = {814{"-9223372036854775809", std::numeric_limits<int64_t>::min()},815{"-9223372036854775808", -9'223'372'036'854'775'807LL - 1LL},816{"9223372036854775807", 9'223'372'036'854'775'807},817{"9223372036854775808", std::numeric_limits<int64_t>::max()},818{"+-", 0},819{"0x1", 0},820{"ox1", 0},821{"", 0},822};824for (const auto& pair : atoi64_test_pairs) {825BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(pair.first), pair.second);826}828// Ensure legacy compatibility with previous versions of Bitcoin Core's atoi64829for (const auto& pair : atoi64_test_pairs) {830BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int64_t>(pair.first), atoi64_legacy(pair.first));831}833BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("-1"), 0U);834BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("0"), 0U);835BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("18446744073709551615"), 18'446'744'073'709'551'615ULL);836BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint64_t>("18446744073709551616"), 18'446'744'073'709'551'615ULL);838BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-2147483649"), -2'147'483'648LL);839BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("-2147483648"), -2'147'483'648LL);840BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("2147483647"), 2'147'483'647);841BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int32_t>("2147483648"), 2'147'483'647);843BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("-1"), 0U);844BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("0"), 0U);845BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("4294967295"), 4'294'967'295U);846BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint32_t>("4294967296"), 4'294'967'295U);848BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("-32769"), -32'768);849BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("-32768"), -32'768);850BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("32767"), 32'767);851BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int16_t>("32768"), 32'767);853BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("-1"), 0U);854BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("0"), 0U);855BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("65535"), 65'535U);856BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint16_t>("65536"), 65'535U);858BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("-129"), -128);859BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("-128"), -128);860BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("127"), 127);861BOOST_CHECK_EQUAL(LocaleIndependentAtoi<int8_t>("128"), 127);863BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("-1"), 0U);864BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("0"), 0U);865BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("255"), 255U);866BOOST_CHECK_EQUAL(LocaleIndependentAtoi<uint8_t>("256"), 255U);867}869BOOST_AUTO_TEST_CASE(test_ToIntegralHex)870{871std::optional<uint64_t> n;872// Valid values873n = ToIntegral<uint64_t>("1234", 16);874BOOST_CHECK_EQUAL(*n, 0x1234);875n = ToIntegral<uint64_t>("a", 16);876BOOST_CHECK_EQUAL(*n, 0xA);877n = ToIntegral<uint64_t>("0000000a", 16);878BOOST_CHECK_EQUAL(*n, 0xA);879n = ToIntegral<uint64_t>("100", 16);880BOOST_CHECK_EQUAL(*n, 0x100);881n = ToIntegral<uint64_t>("DEADbeef", 16);882BOOST_CHECK_EQUAL(*n, 0xDEADbeef);883n = ToIntegral<uint64_t>("FfFfFfFf", 16);884BOOST_CHECK_EQUAL(*n, 0xFfFfFfFf);885n = ToIntegral<uint64_t>("123456789", 16);886BOOST_CHECK_EQUAL(*n, 0x123456789ULL);887n = ToIntegral<uint64_t>("0", 16);888BOOST_CHECK_EQUAL(*n, 0);889n = ToIntegral<uint64_t>("FfFfFfFfFfFfFfFf", 16);890BOOST_CHECK_EQUAL(*n, 0xFfFfFfFfFfFfFfFfULL);891BOOST_CHECK_EQUAL(*ToIntegral<int64_t>("-1", 16), -1);892// Invalid values893BOOST_CHECK(!ToIntegral<uint64_t>("", 16));894BOOST_CHECK(!ToIntegral<uint64_t>("-1", 16));895BOOST_CHECK(!ToIntegral<uint64_t>("10 00", 16));896BOOST_CHECK(!ToIntegral<uint64_t>("1 ", 16));897BOOST_CHECK(!ToIntegral<uint64_t>("0xAB", 16));898BOOST_CHECK(!ToIntegral<uint64_t>("FfFfFfFfFfFfFfFf0", 16));899}901BOOST_AUTO_TEST_CASE(test_FormatParagraph)902{903BOOST_CHECK_EQUAL(FormatParagraph("", 79, 0), "");904BOOST_CHECK_EQUAL(FormatParagraph("test", 79, 0), "test");905BOOST_CHECK_EQUAL(FormatParagraph(" test", 79, 0), " test");906BOOST_CHECK_EQUAL(FormatParagraph("test test", 79, 0), "test test");907BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 0), "test\ntest");908BOOST_CHECK_EQUAL(FormatParagraph("testerde test", 4, 0), "testerde\ntest");909BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 4), "test\n test");911// Make sure we don't indent a fully-new line following a too-long line ending912BOOST_CHECK_EQUAL(FormatParagraph("test test\nabc", 4, 4), "test\n test\nabc");914BOOST_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");916// Test wrap length is exact917BOOST_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");918BOOST_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");919// Indent should be included in length of lines920BOOST_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");922BOOST_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.");923BOOST_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.");924BOOST_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.");925BOOST_CHECK_EQUAL(FormatParagraph("Testing that normal newlines do not get indented.\nLike here.", 79), "Testing that normal newlines do not get indented.\nLike here.");926}928BOOST_AUTO_TEST_CASE(test_FormatSubVersion)929{930std::vector<std::string> comments;931comments.emplace_back("comment1");932std::vector<std::string> comments2;933comments2.emplace_back("comment1");934comments2.push_back(SanitizeString(std::string("Comment2; .,_?@-; !\"#$%&'()*+/<=>[]\\^`{|}~"), SAFE_CHARS_UA_COMMENT)); // Semicolon is discouraged but not forbidden by BIP-0014935BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, std::vector<std::string>()),std::string("/Test:9.99.0/"));936BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, comments),std::string("/Test:9.99.0(comment1)/"));937BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, comments2),std::string("/Test:9.99.0(comment1; Comment2; .,_?@-; )/"));938}940BOOST_AUTO_TEST_CASE(test_ParseFixedPoint)941{942int64_t amount = 0;943BOOST_CHECK(ParseFixedPoint("0", 8, &amount));944BOOST_CHECK_EQUAL(amount, 0LL);945BOOST_CHECK(ParseFixedPoint("1", 8, &amount));946BOOST_CHECK_EQUAL(amount, 100000000LL);947BOOST_CHECK(ParseFixedPoint("0.0", 8, &amount));948BOOST_CHECK_EQUAL(amount, 0LL);949BOOST_CHECK(ParseFixedPoint("-0.1", 8, &amount));950BOOST_CHECK_EQUAL(amount, -10000000LL);951BOOST_CHECK(ParseFixedPoint("1.1", 8, &amount));952BOOST_CHECK_EQUAL(amount, 110000000LL);953BOOST_CHECK(ParseFixedPoint("1.10000000000000000", 8, &amount));954BOOST_CHECK_EQUAL(amount, 110000000LL);955BOOST_CHECK(ParseFixedPoint("1.1e1", 8, &amount));956BOOST_CHECK_EQUAL(amount, 1100000000LL);957BOOST_CHECK(ParseFixedPoint("1.1e-1", 8, &amount));958BOOST_CHECK_EQUAL(amount, 11000000LL);959BOOST_CHECK(ParseFixedPoint("1000", 8, &amount));960BOOST_CHECK_EQUAL(amount, 100000000000LL);961BOOST_CHECK(ParseFixedPoint("-1000", 8, &amount));962BOOST_CHECK_EQUAL(amount, -100000000000LL);963BOOST_CHECK(ParseFixedPoint("0.00000001", 8, &amount));964BOOST_CHECK_EQUAL(amount, 1LL);965BOOST_CHECK(ParseFixedPoint("0.0000000100000000", 8, &amount));966BOOST_CHECK_EQUAL(amount, 1LL);967BOOST_CHECK(ParseFixedPoint("-0.00000001", 8, &amount));968BOOST_CHECK_EQUAL(amount, -1LL);969BOOST_CHECK(ParseFixedPoint("1000000000.00000001", 8, &amount));970BOOST_CHECK_EQUAL(amount, 100000000000000001LL);971BOOST_CHECK(ParseFixedPoint("9999999999.99999999", 8, &amount));972BOOST_CHECK_EQUAL(amount, 999999999999999999LL);973BOOST_CHECK(ParseFixedPoint("-9999999999.99999999", 8, &amount));974BOOST_CHECK_EQUAL(amount, -999999999999999999LL);976BOOST_CHECK(!ParseFixedPoint("", 8, &amount));977BOOST_CHECK(!ParseFixedPoint("-", 8, &amount));978BOOST_CHECK(!ParseFixedPoint("a-1000", 8, &amount));979BOOST_CHECK(!ParseFixedPoint("-a1000", 8, &amount));980BOOST_CHECK(!ParseFixedPoint("-1000a", 8, &amount));981BOOST_CHECK(!ParseFixedPoint("-01000", 8, &amount));982BOOST_CHECK(!ParseFixedPoint("00.1", 8, &amount));983BOOST_CHECK(!ParseFixedPoint(".1", 8, &amount));984BOOST_CHECK(!ParseFixedPoint("--0.1", 8, &amount));985BOOST_CHECK(!ParseFixedPoint("0.000000001", 8, &amount));986BOOST_CHECK(!ParseFixedPoint("-0.000000001", 8, &amount));987BOOST_CHECK(!ParseFixedPoint("0.00000001000000001", 8, &amount));988BOOST_CHECK(!ParseFixedPoint("-10000000000.00000000", 8, &amount));989BOOST_CHECK(!ParseFixedPoint("10000000000.00000000", 8, &amount));990BOOST_CHECK(!ParseFixedPoint("-10000000000.00000001", 8, &amount));991BOOST_CHECK(!ParseFixedPoint("10000000000.00000001", 8, &amount));992BOOST_CHECK(!ParseFixedPoint("-10000000000.00000009", 8, &amount));993BOOST_CHECK(!ParseFixedPoint("10000000000.00000009", 8, &amount));994BOOST_CHECK(!ParseFixedPoint("-99999999999.99999999", 8, &amount));995BOOST_CHECK(!ParseFixedPoint("99999909999.09999999", 8, &amount));996BOOST_CHECK(!ParseFixedPoint("92233720368.54775807", 8, &amount));997BOOST_CHECK(!ParseFixedPoint("92233720368.54775808", 8, &amount));998BOOST_CHECK(!ParseFixedPoint("-92233720368.54775808", 8, &amount));999BOOST_CHECK(!ParseFixedPoint("-92233720368.54775809", 8, &amount));1000BOOST_CHECK(!ParseFixedPoint("1.1e", 8, &amount));
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.