| 547 | } |
| 548 | |
| 549 | void CheckInferDescriptor(const std::string& script_hex, const std::string& expected_desc, const std::vector<std::string>& hex_scripts, const std::vector<std::pair<std::string, std::string>>& origin_pubkeys) |
| 550 | { |
| 551 | std::vector<unsigned char> script_bytes{ParseHex(script_hex)}; |
| 552 | const CScript& script{script_bytes.begin(), script_bytes.end()}; |
| 553 | |
| 554 | FlatSigningProvider provider; |
| 555 | for (const std::string& prov_script_hex : hex_scripts) { |
| 556 | std::vector<unsigned char> prov_script_bytes{ParseHex(prov_script_hex)}; |
| 557 | const CScript& prov_script{prov_script_bytes.begin(), prov_script_bytes.end()}; |
| 558 | provider.scripts.emplace(CScriptID(prov_script), prov_script); |
| 559 | } |
| 560 | for (const auto& [pubkey_hex, origin_str] : origin_pubkeys) { |
| 561 | CPubKey origin_pubkey{ParseHex(pubkey_hex)}; |
| 562 | provider.pubkeys.emplace(origin_pubkey.GetID(), origin_pubkey); |
| 563 | |
| 564 | if (!origin_str.empty()) { |
| 565 | KeyOriginInfo info; |
| 566 | std::span<const char> origin_sp{origin_str}; |
| 567 | std::vector<std::span<const char>> origin_split = Split(origin_sp, "/"); |
| 568 | std::string fpr_str(origin_split[0].begin(), origin_split[0].end()); |
| 569 | auto fpr_bytes = ParseHex(fpr_str); |
| 570 | std::copy(fpr_bytes.begin(), fpr_bytes.end(), info.fingerprint); |
| 571 | for (size_t i = 1; i < origin_split.size(); ++i) { |
| 572 | std::span<const char> elem = origin_split[i]; |
| 573 | bool hardened = false; |
| 574 | if (elem.size() > 0) { |
| 575 | const char last = elem[elem.size() - 1]; |
| 576 | if (last == '\'' || last == 'h') { |
| 577 | elem = elem.first(elem.size() - 1); |
| 578 | hardened = true; |
| 579 | } |
| 580 | } |
| 581 | const uint32_t p{*Assert(ToIntegral<uint32_t>(std::string_view{elem.begin(), elem.end()}))}; |
| 582 | info.path.push_back(p | (((uint32_t)hardened) << 31)); |
| 583 | } |
| 584 | |
| 585 | provider.origins.emplace(origin_pubkey.GetID(), std::make_pair(origin_pubkey, info)); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | std::string checksum{GetDescriptorChecksum(expected_desc)}; |
| 590 | |
| 591 | std::unique_ptr<Descriptor> desc = InferDescriptor(script, provider); |
| 592 | BOOST_CHECK_EQUAL(desc->ToString(), expected_desc + "#" + checksum); |
| 593 | } |
| 594 | |
| 595 | } |
| 596 |
no test coverage detected