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.
1501auto v8 = Cat(std::move(v2), std::move(v3));1502BOOST_CHECK_EQUAL(v8.size(), 3U);1503BOOST_CHECK(v8[0].origin == &t2);1504BOOST_CHECK(v8[1].origin == &t1);1505BOOST_CHECK(v8[2].origin == &t2);1506BOOST_CHECK_EQUAL(v8[0].copies, 0);1507BOOST_CHECK_EQUAL(v8[1].copies, 1);1508BOOST_CHECK_EQUAL(v8[2].copies, 0);1509}1511BOOST_AUTO_TEST_CASE(message_sign)1512{1513const std::array<unsigned char, 32> privkey_bytes = {1514// just some random data1515// derived address from this private key: 15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs15160xD9, 0x7F, 0x51, 0x08, 0xF1, 0x1C, 0xDA, 0x6E,15170xEE, 0xBA, 0xAA, 0x42, 0x0F, 0xEF, 0x07, 0x26,15180xB1, 0xF8, 0x98, 0x06, 0x0B, 0x98, 0x48, 0x9F,15190xA3, 0x09, 0x84, 0x63, 0xC0, 0x03, 0x28, 0x661520};1522const std::string message = "Trust no one";1524const std::string expected_signature =1525"IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=";1527CKey privkey;1528std::string generated_signature;1530BOOST_REQUIRE_MESSAGE(!privkey.IsValid(),1531"Confirm the private key is invalid");1533BOOST_CHECK_MESSAGE(!MessageSign(privkey, message, generated_signature),1534"Sign with an invalid private key");1536privkey.Set(privkey_bytes.begin(), privkey_bytes.end(), true);1538BOOST_REQUIRE_MESSAGE(privkey.IsValid(),1539"Confirm the private key is valid");1541BOOST_CHECK_MESSAGE(MessageSign(privkey, message, generated_signature),1542"Sign with a valid private key");1544BOOST_CHECK_EQUAL(expected_signature, generated_signature);1545}1547BOOST_AUTO_TEST_CASE(message_verify)1548{1549BOOST_CHECK_EQUAL(1550MessageVerify(1551"invalid address",1552"signature should be irrelevant",1553"message too"),1554MessageVerificationResult::ERR_INVALID_ADDRESS);1556BOOST_CHECK_EQUAL(1557MessageVerify(1558"3B5fQsEXEaV8v6U3ejYc8XaKXAkyQj2MjV",1559"signature should be irrelevant",1560"message too"),1561MessageVerificationResult::ERR_ADDRESS_NO_KEY);1563BOOST_CHECK_EQUAL(1564MessageVerify(1565"1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",1566"invalid signature, not in base64 encoding",1567"message should be irrelevant"),1568MessageVerificationResult::ERR_MALFORMED_SIGNATURE);1570BOOST_CHECK_EQUAL(1571MessageVerify(1572"1KqbBpLy5FARmTPD4VZnDDpYjkUvkr82Pm",1573"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",1574"message should be irrelevant"),1575MessageVerificationResult::ERR_PUBKEY_NOT_RECOVERED);1577BOOST_CHECK_EQUAL(1578MessageVerify(1579"15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",1580"IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",1581"I never signed this"),1582MessageVerificationResult::ERR_NOT_SIGNED);1584BOOST_CHECK_EQUAL(1585MessageVerify(1586"15CRxFdyRpGZLW9w8HnHvVduizdL5jKNbs",1587"IPojfrX2dfPnH26UegfbGQQLrdK844DlHq5157/P6h57WyuS/Qsl+h/WSVGDF4MUi4rWSswW38oimDYfNNUBUOk=",1588"Trust no one"),1589MessageVerificationResult::OK);1591BOOST_CHECK_EQUAL(1592MessageVerify(1593"11canuhp9X2NocwCq7xNrQYTmUgZAnLK3",1594"IIcaIENoYW5jZWxsb3Igb24gYnJpbmsgb2Ygc2Vjb25kIGJhaWxvdXQgZm9yIGJhbmtzIAaHRtbCeDZINyavx14=",1595"Trust me"),1596MessageVerificationResult::OK);1597}1599BOOST_AUTO_TEST_CASE(message_hash)1600{1601const std::string unsigned_tx = "...";1602const std::string prefixed_message =1603std::string(1, (char)MESSAGE_MAGIC.length()) +1604MESSAGE_MAGIC +1605std::string(1, (char)unsigned_tx.length()) +1606unsigned_tx;1608const uint256 signature_hash = Hash(unsigned_tx);1609const uint256 message_hash1 = Hash(prefixed_message);1610const uint256 message_hash2 = MessageHash(unsigned_tx);1612BOOST_CHECK_EQUAL(message_hash1, message_hash2);1613BOOST_CHECK_NE(message_hash1, signature_hash);1614}1616BOOST_AUTO_TEST_CASE(remove_prefix)1617{1618BOOST_CHECK_EQUAL(RemovePrefix("./common/system.h", "./"), "common/system.h");1619BOOST_CHECK_EQUAL(RemovePrefixView("foo", "foo"), "");1620BOOST_CHECK_EQUAL(RemovePrefix("foo", "fo"), "o");1621BOOST_CHECK_EQUAL(RemovePrefixView("foo", "f"), "oo");1622BOOST_CHECK_EQUAL(RemovePrefix("foo", ""), "foo");1623BOOST_CHECK_EQUAL(RemovePrefixView("fo", "foo"), "fo");1624BOOST_CHECK_EQUAL(RemovePrefix("f", "foo"), "f");1625BOOST_CHECK_EQUAL(RemovePrefixView("", "foo"), "");1626BOOST_CHECK_EQUAL(RemovePrefix("", ""), "");1627}1629BOOST_AUTO_TEST_CASE(util_ParseByteUnits)1630{1631auto noop = ByteUnit::NOOP;1633// no multiplier1634BOOST_CHECK_EQUAL(ParseByteUnits("1", noop).value(), 1);1635BOOST_CHECK_EQUAL(ParseByteUnits("0", noop).value(), 0);1637BOOST_CHECK_EQUAL(ParseByteUnits("1k", noop).value(), 1000ULL);1638BOOST_CHECK_EQUAL(ParseByteUnits("1K", noop).value(), 1ULL << 10);1640BOOST_CHECK_EQUAL(ParseByteUnits("2m", noop).value(), 2'000'000ULL);1641BOOST_CHECK_EQUAL(ParseByteUnits("2M", noop).value(), 2_MiB);1643BOOST_CHECK_EQUAL(ParseByteUnits("3g", noop).value(), 3'000'000'000ULL);1644BOOST_CHECK_EQUAL(ParseByteUnits("3G", noop).value(), 3_GiB);1646BOOST_CHECK_EQUAL(ParseByteUnits("4t", noop).value(), 4'000'000'000'000ULL);1647BOOST_CHECK_EQUAL(ParseByteUnits("4T", noop).value(), 4ULL << 40);1649// check default multiplier1650BOOST_CHECK_EQUAL(ParseByteUnits("5", ByteUnit::K).value(), 5ULL << 10);1652// NaN1653BOOST_CHECK(!ParseByteUnits("", noop));1654BOOST_CHECK(!ParseByteUnits("foo", noop));1656// whitespace1657BOOST_CHECK(!ParseByteUnits("123m ", noop));1658BOOST_CHECK(!ParseByteUnits(" 123m", noop));1660// no +-1661BOOST_CHECK(!ParseByteUnits("-123m", noop));1662BOOST_CHECK(!ParseByteUnits("+123m", noop));1664// zero padding1665BOOST_CHECK_EQUAL(ParseByteUnits("020M", noop).value(), 20_MiB);1667// fractions not allowed1668BOOST_CHECK(!ParseByteUnits("0.5T", noop));1670// overflow1671BOOST_CHECK(!ParseByteUnits("18446744073709551615g", noop));1673// invalid unit1674BOOST_CHECK(!ParseByteUnits("1x", noop));1675}1677BOOST_AUTO_TEST_CASE(util_ReadBinaryFile)1678{1679fs::path tmpfolder = m_args.GetDataDirBase();1680fs::path tmpfile = tmpfolder / "read_binary.dat";1681std::string expected_text;1682for (int i = 0; i < 30; i++) {1683expected_text += "0123456789";1684}1685{1686std::ofstream file{tmpfile.std_path()};1687file << expected_text;1688}1689{1690// read all contents in file1691auto [valid, text] = ReadBinaryFile(tmpfile);1692BOOST_CHECK(valid);1693BOOST_CHECK_EQUAL(text, expected_text);1694}1695{1696// read half contents in file1697auto [valid, text] = ReadBinaryFile(tmpfile, expected_text.size() / 2);1698BOOST_CHECK(valid);1699BOOST_CHECK_EQUAL(text, expected_text.substr(0, expected_text.size() / 2));1700}1701{1702// read from non-existent file1703fs::path invalid_file = tmpfolder / "invalid_binary.dat";1704auto [valid, text] = ReadBinaryFile(invalid_file);1705BOOST_CHECK(!valid);1706BOOST_CHECK(text.empty());1707}1708}1710BOOST_AUTO_TEST_CASE(util_WriteBinaryFile)1711{1712fs::path tmpfolder = m_args.GetDataDirBase();1713fs::path tmpfile = tmpfolder / "write_binary.dat";1714std::string expected_text = "bitcoin";1715auto valid = WriteBinaryFile(tmpfile, expected_text);1716std::string actual_text;1717std::ifstream file{tmpfile.std_path()};1718file >> actual_text;1719BOOST_CHECK(valid);1720BOOST_CHECK_EQUAL(actual_text, expected_text);1721}1723BOOST_AUTO_TEST_CASE(clearshrink_test)1724{1725{1726std::vector<uint8_t> v = {1, 2, 3};1727ClearShrink(v);1728BOOST_CHECK_EQUAL(v.size(), 0);1729BOOST_CHECK_EQUAL(v.capacity(), 0);1730}1732{1733std::vector<bool> v = {false, true, false, false, true, true};1734ClearShrink(v);1735BOOST_CHECK_EQUAL(v.size(), 0);1736BOOST_CHECK_EQUAL(v.capacity(), 0);1737}1739{1740std::deque<int> v = {1, 3, 3, 7};1741ClearShrink(v);1742BOOST_CHECK_EQUAL(v.size(), 0);1743// std::deque has no capacity() we can observe.1744}1745}1747template <typename T>1748void TestCheckedLeftShift()1749{1750constexpr auto MAX{std::numeric_limits<T>::max()};
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.