MCPcopy Create free account
hub / github.com/ElementsProject/elements / FUZZ_TARGET

Function FUZZ_TARGET

src/test/fuzz/node_eviction.cpp:17–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include <vector>
16
17FUZZ_TARGET(node_eviction)
18{
19 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
20 std::vector<NodeEvictionCandidate> eviction_candidates;
21 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
22 eviction_candidates.push_back({
23 /*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(),
24 /*m_connected=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
25 /*m_min_ping_time=*/std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
26 /*m_last_block_time=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
27 /*m_last_tx_time=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
28 /*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(),
29 /*fRelayTxes=*/fuzzed_data_provider.ConsumeBool(),
30 /*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(),
31 /*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
32 /*prefer_evict=*/fuzzed_data_provider.ConsumeBool(),
33 /*m_is_local=*/fuzzed_data_provider.ConsumeBool(),
34 /*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS),
35 });
36 }
37 // Make a copy since eviction_candidates may be in some valid but otherwise
38 // indeterminate state after the SelectNodeToEvict(&&) call.
39 const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;
40 const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates));
41 if (node_to_evict) {
42 assert(std::any_of(eviction_candidates_copy.begin(), eviction_candidates_copy.end(), [&node_to_evict](const NodeEvictionCandidate& eviction_candidate) { return *node_to_evict == eviction_candidate.id; }));
43 }
44}

Callers

nothing calls this directly

Calls 8

SelectNodeToEvictFunction · 0.85
ConsumeBoolMethod · 0.80
PickValueInArrayMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected