Test a successfully parsed descriptor. */
| 16 | |
| 17 | /** Test a successfully parsed descriptor. */ |
| 18 | static void TestDescriptor(const Descriptor& desc, FlatSigningProvider& sig_provider, std::string& dummy, std::optional<bool>& is_ranged, std::optional<bool>& is_solvable) |
| 19 | { |
| 20 | // Trivial helpers. |
| 21 | (void)desc.IsRange(); |
| 22 | (void)desc.IsSingleType(); |
| 23 | (void)desc.GetOutputType(); |
| 24 | |
| 25 | if (is_ranged.has_value()) { |
| 26 | assert(desc.IsRange() == *is_ranged); |
| 27 | } else { |
| 28 | is_ranged = desc.IsRange(); |
| 29 | } |
| 30 | if (is_solvable.has_value()) { |
| 31 | assert(desc.IsSolvable() == *is_solvable); |
| 32 | } else { |
| 33 | is_solvable = desc.IsSolvable(); |
| 34 | } |
| 35 | |
| 36 | // Serialization to string representation. |
| 37 | (void)desc.ToString(); |
| 38 | (void)desc.ToPrivateString(sig_provider, dummy); |
| 39 | (void)desc.ToNormalizedString(sig_provider, dummy); |
| 40 | |
| 41 | // Serialization to Script. |
| 42 | DescriptorCache cache; |
| 43 | std::vector<CScript> out_scripts; |
| 44 | (void)desc.Expand(0, sig_provider, out_scripts, sig_provider, &cache); |
| 45 | (void)desc.ExpandPrivate(0, sig_provider, sig_provider); |
| 46 | (void)desc.ExpandFromCache(0, cache, out_scripts, sig_provider); |
| 47 | |
| 48 | // If we could serialize to script we must be able to infer using the same provider. |
| 49 | if (!out_scripts.empty()) { |
| 50 | assert(InferDescriptor(out_scripts.back(), sig_provider)); |
| 51 | |
| 52 | // The ScriptSize() must match the size of the serialized Script. (ScriptSize() is set for all descs but 'combo()'.) |
| 53 | const bool is_combo{!desc.IsSingleType()}; |
| 54 | assert(is_combo || desc.ScriptSize() == out_scripts.back().size()); |
| 55 | } |
| 56 | |
| 57 | const auto max_sat_maxsig{desc.MaxSatisfactionWeight(true)}; |
| 58 | const auto max_sat_nonmaxsig{desc.MaxSatisfactionWeight(false)}; |
| 59 | // Whether an estimate is available must not depend on the signature-size |
| 60 | // assumption, and assuming non-max-size signatures must never increase it. |
| 61 | assert(max_sat_maxsig.has_value() == max_sat_nonmaxsig.has_value()); |
| 62 | assert(max_sat_nonmaxsig <= max_sat_maxsig); |
| 63 | const auto max_elems{desc.MaxSatisfactionElems()}; |
| 64 | // We must be able to estimate the max satisfaction size for any solvable descriptor (but combo). |
| 65 | const bool is_nontop_or_nonsolvable{!*is_solvable || !desc.GetOutputType()}; |
| 66 | const bool is_input_size_info_set{max_sat_maxsig && max_sat_nonmaxsig && max_elems}; |
| 67 | assert(is_input_size_info_set || is_nontop_or_nonsolvable); |
| 68 | |
| 69 | auto max_key_expr = desc.GetMaxKeyExpr(); |
| 70 | auto key_count = desc.GetKeyCount(); |
| 71 | assert((max_key_expr == 0 && key_count == 0) || max_key_expr + 1 == key_count); |
| 72 | } |
| 73 | |
| 74 | void initialize_descriptor_parse() |
| 75 | { |
no test coverage detected