Skip to content

Commit

Permalink
tests: Check ExpandPrivate matches for both parsed descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Jan 6, 2025
1 parent 092569e commit 4c50c21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/script/signingprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class TaprootBuilder
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.
Expand Down
18 changes: 18 additions & 0 deletions src/test/descriptor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4c50c21

Please sign in to comment.