MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MakeCorruptPeersDat

Function MakeCorruptPeersDat

src/test/addrman_tests.cpp:1103–1127  ·  view source on GitHub ↗

Produce a corrupt peers.dat that claims 20 addrs when it only has one addr.

Source from the content-addressed store, hash-verified

1101
1102// Produce a corrupt peers.dat that claims 20 addrs when it only has one addr.
1103static auto MakeCorruptPeersDat()
1104{
1105 DataStream s{};
1106 s << ::Params().MessageStart();
1107
1108 unsigned char nVersion = 1;
1109 s << nVersion;
1110 s << ((unsigned char)32);
1111 s << uint256::ONE;
1112 s << 10; // nNew
1113 s << 10; // nTried
1114
1115 int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30);
1116 s << nUBuckets;
1117
1118 const std::optional<CService> serv{Lookup("252.1.1.1", 7777, false)};
1119 BOOST_REQUIRE(serv.has_value());
1120 CAddress addr = CAddress(serv.value(), NODE_NONE);
1121 std::optional<CNetAddr> resolved{LookupHost("252.2.2.2", false)};
1122 BOOST_REQUIRE(resolved.has_value());
1123 AddrInfo info = AddrInfo(addr, resolved.value());
1124 s << CAddress::V1_DISK(info);
1125
1126 return s;
1127}
1128
1129BOOST_AUTO_TEST_CASE(load_addrman_corrupted)
1130{

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 7

LookupFunction · 0.85
LookupHostFunction · 0.85
ParamsClass · 0.50
CAddressClass · 0.50
AddrInfoClass · 0.50
has_valueMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected