mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
descriptors: Change Parse to return vector of descriptors
When given a descriptor which contins a multipath derivation specifier, a vector of descriptors will be returned.
This commit is contained in:
parent
0d640c6f02
commit
1bbf46e2da
22 changed files with 178 additions and 111 deletions
|
|
@ -15,14 +15,24 @@
|
|||
MockedDescriptorConverter MOCKED_DESC_CONVERTER;
|
||||
|
||||
/** Test a successfully parsed descriptor. */
|
||||
static void TestDescriptor(const Descriptor& desc, FlatSigningProvider& sig_provider, std::string& dummy)
|
||||
static void TestDescriptor(const Descriptor& desc, FlatSigningProvider& sig_provider, std::string& dummy, std::optional<bool>& is_ranged, std::optional<bool>& is_solvable)
|
||||
{
|
||||
// Trivial helpers.
|
||||
(void)desc.IsRange();
|
||||
const bool is_solvable{desc.IsSolvable()};
|
||||
(void)desc.IsSingleType();
|
||||
(void)desc.GetOutputType();
|
||||
|
||||
if (is_ranged.has_value()) {
|
||||
assert(desc.IsRange() == *is_ranged);
|
||||
} else {
|
||||
is_ranged = desc.IsRange();
|
||||
}
|
||||
if (is_solvable.has_value()) {
|
||||
assert(desc.IsSolvable() == *is_solvable);
|
||||
} else {
|
||||
is_solvable = desc.IsSolvable();
|
||||
}
|
||||
|
||||
// Serialization to string representation.
|
||||
(void)desc.ToString();
|
||||
(void)desc.ToPrivateString(sig_provider, dummy);
|
||||
|
|
@ -48,7 +58,7 @@ static void TestDescriptor(const Descriptor& desc, FlatSigningProvider& sig_prov
|
|||
const auto max_sat_nonmaxsig{desc.MaxSatisfactionWeight(true)};
|
||||
const auto max_elems{desc.MaxSatisfactionElems()};
|
||||
// We must be able to estimate the max satisfaction size for any solvable descriptor (but combo).
|
||||
const bool is_nontop_or_nonsolvable{!is_solvable || !desc.GetOutputType()};
|
||||
const bool is_nontop_or_nonsolvable{!*is_solvable || !desc.GetOutputType()};
|
||||
const bool is_input_size_info_set{max_sat_maxsig && max_sat_nonmaxsig && max_elems};
|
||||
assert(is_input_size_info_set || is_nontop_or_nonsolvable);
|
||||
}
|
||||
|
|
@ -77,7 +87,12 @@ 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, signing_provider, error);
|
||||
std::optional<bool> is_ranged;
|
||||
std::optional<bool> is_solvable;
|
||||
for (const auto& d : desc) {
|
||||
assert(d);
|
||||
TestDescriptor(*d, signing_provider, error, is_ranged, is_solvable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +106,11 @@ 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, signing_provider, error);
|
||||
std::optional<bool> is_ranged;
|
||||
std::optional<bool> is_solvable;
|
||||
for (const auto& d : desc) {
|
||||
assert(d);
|
||||
TestDescriptor(*d, signing_provider, error, is_ranged, is_solvable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue