tests: Check ExpandPrivate matches for both parsed descriptors

This commit is contained in:
Ava Chow 2025-01-01 23:52:33 -05:00
parent 092569e858
commit 4c50c21f6b
2 changed files with 20 additions and 0 deletions

View file

@ -136,6 +136,8 @@ public:
std::vector<std::tuple<uint8_t, uint8_t, std::vector<unsigned char>>> GetTreeTuples() const;
/** Returns true if there are any tapscripts */
bool HasScripts() const { return !m_branch.empty(); }
bool operator==(const TaprootBuilder& other) const { return GetTreeTuples() == other.GetTreeTuples(); }
};
/** Given a TaprootSpendData and the output key, reconstruct its script tree.

View file

@ -62,6 +62,15 @@ bool EqualDescriptor(std::string a, std::string b)
return a == b;
}
bool EqualSigningProviders(const FlatSigningProvider& a, const FlatSigningProvider& b)
{
return a.scripts == b.scripts
&& a.pubkeys == b.pubkeys
&& a.origins == b.origins
&& a.keys == b.keys
&& a.tr_trees == b.tr_trees;
}
std::string UseHInsteadOfApostrophe(const std::string& desc)
{
std::string ret = desc;
@ -214,6 +223,15 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
BOOST_CHECK_MESSAGE(EqualDescriptor(prv, prv1), "Private ser: " + prv1 + " Private desc: " + prv);
}
BOOST_CHECK(!parse_pub->ToPrivateString(keys_pub, prv1));
// Check that both can ExpandPrivate and get the same SigningProviders
FlatSigningProvider priv_prov;
parse_priv->ExpandPrivate(0, keys_priv, priv_prov);
FlatSigningProvider pub_prov;
parse_pub->ExpandPrivate(0, keys_priv, pub_prov);
BOOST_CHECK_MESSAGE(EqualSigningProviders(priv_prov, pub_prov), "Private desc: " + prv + " Pub desc: " + pub);
}
// Check that private can produce the normalized descriptors