Skip to content

Commit

Permalink
Merge bitcoin#20686: fuzz, refactor: replace CNode code with fuzz/uti…
Browse files Browse the repository at this point in the history
…l.h::ConsumeNode()

23d8f34 fuzz: replace CNode code with fuzz/util.h::ConsumeNode() (Jon Atack)

Pull request description:

  Noticed this while updating the CNode fuzzing in bitcoin#20210.

  - cc26fab created `test/fuzz/net.cpp` in May 2020

  - 79ef832 created a CNode factory utility `test/fuzz/util.h::ConsumeNode()` in October 2020

  This PR updates `fuzz/net.cpp` from the first commit to use `ConsumeNode()` from the second commit.

ACKs for top commit:
  MarcoFalke:
    ACK 23d8f34

Tree-SHA512: 26f7685395b3d48fcf40dde0d479d5c2fb4e953ec9371940b19eee16bb30aee4840b081e1a918b924a9704c1bef484302ea3e8fe63819a3bba73e7eb805164f1
  • Loading branch information
MarcoFalke committed Dec 17, 2020
2 parents 190d3d8 + 23d8f34 commit b7136c1
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions src/test/fuzz/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,7 @@ FUZZ_TARGET_INIT(net, initialize_net)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
SetMockTime(ConsumeTime(fuzzed_data_provider));
const std::optional<CAddress> address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
if (!address) {
return;
}
const std::optional<CAddress> address_bind = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
if (!address_bind) {
return;
}

CNode node{fuzzed_data_provider.ConsumeIntegral<NodeId>(),
static_cast<ServiceFlags>(fuzzed_data_provider.ConsumeIntegral<uint64_t>()),
fuzzed_data_provider.ConsumeIntegral<int>(),
INVALID_SOCKET,
*address,
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
*address_bind,
fuzzed_data_provider.ConsumeRandomLengthString(32),
fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND_FULL_RELAY, ConnectionType::MANUAL, ConnectionType::FEELER, ConnectionType::BLOCK_RELAY, ConnectionType::ADDR_FETCH}),
fuzzed_data_provider.ConsumeBool()};
CNode node{ConsumeNode(fuzzed_data_provider)};
node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>());
while (fuzzed_data_provider.ConsumeBool()) {
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 10)) {
Expand Down

0 comments on commit b7136c1

Please sign in to comment.