diff options
author | Antoine Poinsot <darosior@protonmail.com> | 2023-07-21 19:14:36 +0200 |
---|---|---|
committer | Antoine Poinsot <darosior@protonmail.com> | 2023-07-21 19:14:36 +0200 |
commit | 131314b62e899f95d1863083d303b489b3212b16 (patch) | |
tree | 981129f25a6445882560882dc2a3da2b5583b82e /src/test/fuzz | |
parent | 90a24741e79cbf20d4456050f0fe39c3f88f5246 (diff) |
fuzz: increase coverage of the descriptor targets
Once a descriptor is successfully parsed, execute more of its methods.
There is probably still room for improvements by checking for some
invariants, but this is a low hanging fruit that significantly increases
the code coverage of these targets.
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/descriptor_parse.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/test/fuzz/descriptor_parse.cpp b/src/test/fuzz/descriptor_parse.cpp index 0d3e422ff7..b879b0d141 100644 --- a/src/test/fuzz/descriptor_parse.cpp +++ b/src/test/fuzz/descriptor_parse.cpp @@ -108,11 +108,30 @@ public: MockedDescriptorConverter MOCKED_DESC_CONVERTER; /** Test a successfully parsed descriptor. */ -static void TestDescriptor(const Descriptor& desc) +static void TestDescriptor(const Descriptor& desc, FlatSigningProvider& sig_provider, std::string& dummy) { - (void)desc.ToString(); + // Trivial helpers. (void)desc.IsRange(); (void)desc.IsSolvable(); + (void)desc.IsSingleType(); + (void)desc.GetOutputType(); + + // Serialization to string representation. + (void)desc.ToString(); + (void)desc.ToPrivateString(sig_provider, dummy); + (void)desc.ToNormalizedString(sig_provider, dummy); + + // Serialization to Script. + DescriptorCache cache; + std::vector<CScript> out_scripts; + (void)desc.Expand(0, sig_provider, out_scripts, sig_provider, &cache); + (void)desc.ExpandPrivate(0, sig_provider, sig_provider); + (void)desc.ExpandFromCache(0, cache, out_scripts, sig_provider); + + // If we could serialize to script we must be able to infer using the same provider. + if (!out_scripts.empty()) { + assert(InferDescriptor(out_scripts.back(), sig_provider)); + } } void initialize_descriptor_parse() @@ -134,7 +153,7 @@ FUZZ_TARGET(mocked_descriptor_parse, .init = initialize_mocked_descriptor_parse) FlatSigningProvider signing_provider; std::string error; const auto desc = Parse(*descriptor, signing_provider, error); - if (desc) TestDescriptor(*desc); + if (desc) TestDescriptor(*desc, signing_provider, error); } } @@ -145,6 +164,6 @@ FUZZ_TARGET(descriptor_parse, .init = initialize_descriptor_parse) std::string error; for (const bool require_checksum : {true, false}) { const auto desc = Parse(descriptor, signing_provider, error, require_checksum); - if (desc) TestDescriptor(*desc); + if (desc) TestDescriptor(*desc, signing_provider, error); } } |