MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / DoCheck

Function DoCheck

src/test/descriptor_tests.cpp:171–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int flags,
172 const std::vector<std::vector<std::string>>& scripts, const std::optional<OutputType>& type, std::optional<uint256> op_desc_id = std::nullopt,
173 const std::set<std::vector<uint32_t>>& paths = ONLY_EMPTY, bool replace_apostrophe_with_h_in_prv=false,
174 bool replace_apostrophe_with_h_in_pub=false, uint32_t spender_nlocktime=0, uint32_t spender_nsequence=CTxIn::SEQUENCE_FINAL,
175 std::map<std::vector<uint8_t>, std::vector<uint8_t>> preimages={},
176 std::optional<std::string> expected_prv = std::nullopt, std::optional<std::string> expected_pub = std::nullopt, int desc_index = 0)
177{
178 FlatSigningProvider keys_priv, keys_pub;
179 std::set<std::vector<uint32_t>> left_paths = paths;
180 std::string error;
181
182 std::vector<std::unique_ptr<Descriptor>> parse_privs;
183 std::vector<std::unique_ptr<Descriptor>> parse_pubs;
184 // Check that parsing succeeds.
185 if (replace_apostrophe_with_h_in_prv) {
186 prv = UseHInsteadOfApostrophe(prv);
187 }
188 parse_privs = Parse(prv, keys_priv, error);
189 BOOST_CHECK_MESSAGE(!parse_privs.empty(), error);
190 if (replace_apostrophe_with_h_in_pub) {
191 pub = UseHInsteadOfApostrophe(pub);
192 }
193 parse_pubs = Parse(pub, keys_pub, error);
194 BOOST_CHECK_MESSAGE(!parse_pubs.empty(), error);
195
196 auto& parse_priv = parse_privs.at(desc_index);
197 auto& parse_pub = parse_pubs.at(desc_index);
198
199 // We must be able to estimate the max satisfaction size for any solvable descriptor top descriptor (but combo).
200 const bool is_nontop_or_nonsolvable{!parse_priv->IsSolvable() || !parse_priv->GetOutputType()};
201 const auto max_sat_maxsig{parse_priv->MaxSatisfactionWeight(true)};
202 const auto max_sat_nonmaxsig{parse_priv->MaxSatisfactionWeight(false)};
203 BOOST_CHECK(max_sat_nonmaxsig <= max_sat_maxsig);
204 const auto max_elems{parse_priv->MaxSatisfactionElems()};
205 const bool is_input_size_info_set{max_sat_maxsig && max_sat_nonmaxsig && max_elems};
206 BOOST_CHECK_MESSAGE(is_input_size_info_set || is_nontop_or_nonsolvable, prv);
207
208 // The ScriptSize() must match the size of the Script string. (ScriptSize() is set for all descs but 'combo()'.)
209 const bool is_combo{!parse_priv->IsSingleType()};
210 BOOST_CHECK_MESSAGE(is_combo || parse_priv->ScriptSize() == scripts[0][0].size() / 2, "Invalid ScriptSize() for " + prv);
211
212 // Check that the correct OutputType is inferred
213 BOOST_CHECK(parse_priv->GetOutputType() == type);
214 BOOST_CHECK(parse_pub->GetOutputType() == type);
215
216 // Check private keys are extracted from the private version but not the public one.
217 BOOST_CHECK(keys_priv.keys.size());
218 BOOST_CHECK(!keys_pub.keys.size());
219
220 // If expected_pub is provided, check that the serialize matches that.
221 // Otherwise check that they serialize back to the public version.
222 std::string pub1 = parse_priv->ToString();
223 std::string pub2 = parse_pub->ToString();
224 if (expected_pub) {
225 BOOST_CHECK_MESSAGE(EqualDescriptor(*expected_pub, pub1), "Private ser: " + pub1 + " Public desc: " + *expected_pub);
226 BOOST_CHECK_MESSAGE(EqualDescriptor(*expected_pub, pub2), "Public ser: " + pub2 + " Public desc: " + *expected_pub);
227 } else {
228 BOOST_CHECK_MESSAGE(EqualDescriptor(pub, pub1), "Private ser: " + pub1 + " Public desc: " + pub);

Callers 1

CheckFunction · 0.85

Calls 15

UseHInsteadOfApostropheFunction · 0.85
EqualDescriptorFunction · 0.85
DescriptorIDFunction · 0.85
EqualSigningProvidersFunction · 0.85
GetKeyDataFunction · 0.85
GetKeyOriginDataFunction · 0.85
CountXpubsFunction · 0.85
CountUniqueXpubsFunction · 0.85
ProduceSignatureFunction · 0.85
InferDescriptorFunction · 0.85

Tested by

no test coverage detected