Skip to content

Commit 4c50c21

Browse files
committed
tests: Check ExpandPrivate matches for both parsed descriptors
1 parent 092569e commit 4c50c21

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/script/signingprovider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class TaprootBuilder
136136
std::vector<std::tuple<uint8_t, uint8_t, std::vector<unsigned char>>> GetTreeTuples() const;
137137
/** Returns true if there are any tapscripts */
138138
bool HasScripts() const { return !m_branch.empty(); }
139+
140+
bool operator==(const TaprootBuilder& other) const { return GetTreeTuples() == other.GetTreeTuples(); }
139141
};
140142

141143
/** Given a TaprootSpendData and the output key, reconstruct its script tree.

src/test/descriptor_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ bool EqualDescriptor(std::string a, std::string b)
6262
return a == b;
6363
}
6464

65+
bool EqualSigningProviders(const FlatSigningProvider& a, const FlatSigningProvider& b)
66+
{
67+
return a.scripts == b.scripts
68+
&& a.pubkeys == b.pubkeys
69+
&& a.origins == b.origins
70+
&& a.keys == b.keys
71+
&& a.tr_trees == b.tr_trees;
72+
}
73+
6574
std::string UseHInsteadOfApostrophe(const std::string& desc)
6675
{
6776
std::string ret = desc;
@@ -214,6 +223,15 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
214223
BOOST_CHECK_MESSAGE(EqualDescriptor(prv, prv1), "Private ser: " + prv1 + " Private desc: " + prv);
215224
}
216225
BOOST_CHECK(!parse_pub->ToPrivateString(keys_pub, prv1));
226+
227+
// Check that both can ExpandPrivate and get the same SigningProviders
228+
FlatSigningProvider priv_prov;
229+
parse_priv->ExpandPrivate(0, keys_priv, priv_prov);
230+
231+
FlatSigningProvider pub_prov;
232+
parse_pub->ExpandPrivate(0, keys_priv, pub_prov);
233+
234+
BOOST_CHECK_MESSAGE(EqualSigningProviders(priv_prov, pub_prov), "Private desc: " + prv + " Pub desc: " + pub);
217235
}
218236

219237
// Check that private can produce the normalized descriptors

0 commit comments

Comments
 (0)