Repository: bitcoin/bitcoin
File: src/test/miniscript_tests.cpp (C++)

Code before:
        if (it == g_testdata->signatures.end()) return false;
        return sig == it->second;
    }

    bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion,
                               ScriptExecutionData&, ScriptError*) const override {
        XOnlyPubKey pk{pubkey};
        auto it = g_testdata->schnorr_signatures.find(pk);
        if (it == g_testdata->schnorr_signatures.end()) return false;
        return std::ranges::equal(sig, it->second);
    }

    bool CheckLockTime(const CScriptNum& locktime) const override {
        // Delegate to Satisfier.
        return ctx.CheckAfter(locktime.GetInt64());
    }

    bool CheckSequence(const CScriptNum& sequence) const override {
        // Delegate to Satisfier.
        return ctx.CheckOlder(sequence.GetInt64());
    }
};

using Fragment = miniscript::Fragment;
using NodeRef = miniscript::NodeRef<CPubKey>;
using miniscript::operator"" _mst;
using Node = miniscript::Node<CPubKey>;

/** Compute all challenges (pubkeys, hashes, timelocks) that occur in a given Miniscript. */
// NOLINTNEXTLINE(misc-no-recursion)
std::set<Challenge> FindChallenges(const NodeRef& ref) {
    std::set<Challenge> chal;
    for (const auto& key : ref->keys) {
        chal.emplace(ChallengeType::PK, ChallengeNumber(key));
    }
    if (ref->fragment == miniscript::Fragment::OLDER) {
        chal.emplace(ChallengeType::OLDER, ref->k);
    } else if (ref->fragment == miniscript::Fragment::AFTER) {
        chal.emplace(ChallengeType::AFTER, ref->k);
    } else if (ref->fragment == miniscript::Fragment::SHA256) {
        chal.emplace(ChallengeType::SHA256, ChallengeNumber(ref->data));
    } else if (ref->fragment == miniscript::Fragment::RIPEMD160) {
        chal.emplace(ChallengeType::RIPEMD160, ChallengeNumber(ref->data));
    } else if (ref->fragment == miniscript::Fragment::HASH256) {
        chal.emplace(ChallengeType::HASH256, ChallengeNumber(ref->data));
    } else if (ref->fragment == miniscript::Fragment::HASH160) {
        chal.emplace(ChallengeType::HASH160, ChallengeNumber(ref->data));
    }
    for (const auto& sub : ref->subs) {
        auto sub_chal = FindChallenges(sub);
        chal.insert(sub_chal.begin(), sub_chal.end());

Review comment (suggestion):
nit: given the focus on miniscript here, we might as well use the whole namespace like we do for e.g. `std::literals`:
```suggestion
using namespace miniscript;
```

Code after:
        if (it == g_testdata->signatures.end()) return false;
        return sig == it->second;
    }

    bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion,
                               ScriptExecutionData&, ScriptError*) const override {
        XOnlyPubKey pk{pubkey};
        auto it = g_testdata->schnorr_signatures.find(pk);
        if (it == g_testdata->schnorr_signatures.end()) return false;
        return std::ranges::equal(sig, it->second);
    }

    bool CheckLockTime(const CScriptNum& locktime) const override {
        // Delegate to Satisfier.
        return ctx.CheckAfter(locktime.GetInt64());
    }

    bool CheckSequence(const CScriptNum& sequence) const override {
        // Delegate to Satisfier.
        return ctx.CheckOlder(sequence.GetInt64());
    }
};

using Fragment = miniscript::Fragment;
using NodeRef = miniscript::NodeRef<CPubKey>;
using miniscript::operator""_mst;
using Node = miniscript::Node<CPubKey>;

/** Compute all challenges (pubkeys, hashes, timelocks) that occur in a given Miniscript. */
// NOLINTNEXTLINE(misc-no-recursion)
std::set<Challenge> FindChallenges(const NodeRef& ref) {
    std::set<Challenge> chal;
    for (const auto& key : ref->keys) {
        chal.emplace(ChallengeType::PK, ChallengeNumber(key));
    }
    if (ref->fragment == miniscript::Fragment::OLDER) {
        chal.emplace(ChallengeType::OLDER, ref->k);
    } else if (ref->fragment == miniscript::Fragment::AFTER) {
        chal.emplace(ChallengeType::AFTER, ref->k);
    } else if (ref->fragment == miniscript::Fragment::SHA256) {
        chal.emplace(ChallengeType::SHA256, ChallengeNumber(ref->data));
    } else if (ref->fragment == miniscript::Fragment::RIPEMD160) {
        chal.emplace(ChallengeType::RIPEMD160, ChallengeNumber(ref->data));
    } else if (ref->fragment == miniscript::Fragment::HASH256) {
        chal.emplace(ChallengeType::HASH256, ChallengeNumber(ref->data));
    } else if (ref->fragment == miniscript::Fragment::HASH160) {
        chal.emplace(ChallengeType::HASH160, ChallengeNumber(ref->data));
    }
    for (const auto& sub : ref->subs) {
        auto sub_chal = FindChallenges(sub);
        chal.insert(sub_chal.begin(), sub_chal.end());