Merge bitcoin/bitcoin#30134: fuzz: add more coverage for ScriptPubKeyMan

e3249f2111 fuzz: add more coverage for `ScriptPubKeyMan` (brunoerg)

Pull request description:

  This PR adds more coverage for `ScriptPubKeyMan`:

  - Check `GetKey` and `HasPrivKey` after adding descriptor key.
  - Cover `GetEndRange` and `GetKeyPoolSize`.
  - Cover `MarkUnusedAddresses` with the scripts from ScriptPubKeys and `GetMetadata` with the destinations from them.

ACKs for top commit:
  marcofleon:
    Tested ACK e3249f2111. I ran the updated harness for ~9 hours on an empty corpus, generated a coverage report, and checked that the new functions mentioned were hit. Coverage of `scriptpubkeyman.cpp` increased.
  murchandamus:
    Tested ACK e3249f2111

Tree-SHA512: cfab91f6c8401174842e79209c0e9225c08f011fe9b41d0a58bcec716ae4545eaf803867f899ed7b5fbcefea45711f91894e36df082ba19732dd310cd9e61a79
This commit is contained in:
merge-script 2024-06-03 14:01:47 +01:00
commit c065ae8469
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -137,6 +137,15 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm)
PKHash{ConsumeUInt160(fuzzed_data_provider)}};
std::string str_sig;
(void)spk_manager->SignMessage(msg, pk_hash, str_sig);
(void)spk_manager->GetMetadata(dest);
}
}
},
[&] {
auto spks{spk_manager->GetScriptPubKeys()};
for (const CScript& spk : spks) {
if (fuzzed_data_provider.ConsumeBool()) {
spk_manager->MarkUnusedAddresses(spk);
}
}
},
@ -148,6 +157,10 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm)
}
spk_manager->AddDescriptorKey(key, key.GetPubKey());
spk_manager->TopUp();
LOCK(spk_manager->cs_desc_man);
auto particular_key{spk_manager->GetKey(key.GetPubKey().GetID())};
assert(*particular_key == key);
assert(spk_manager->HasPrivKey(key.GetPubKey().GetID()));
},
[&] {
std::string descriptor;
@ -194,6 +207,9 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm)
}
);
}
(void)spk_manager->GetEndRange();
(void)spk_manager->GetKeyPoolSize();
}
} // namespace