Skip to content

Commit 9b2a25b

Browse files
committed
Add tests for InferDescriptor and Descriptor::IsSolvable
1 parent 225bf3e commit 9b2a25b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/script/sign.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ struct KeyOriginInfo
2424
{
2525
unsigned char fingerprint[4];
2626
std::vector<uint32_t> path;
27+
28+
friend bool operator==(const KeyOriginInfo& a, const KeyOriginInfo& b)
29+
{
30+
return std::equal(std::begin(a.fingerprint), std::end(a.fingerprint), std::begin(b.fingerprint)) && a.path == b.path;
31+
}
2732
};
2833

2934
/** An interface to be implemented by keystores that support signing. */

src/test/descriptor_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,19 @@ void Check(const std::string& prv, const std::string& pub, int flags, const std:
102102
spend.vout.resize(1);
103103
BOOST_CHECK_MESSAGE(SignSignature(Merge(keys_priv, script_provider), spks[n], spend, 0, 1, SIGHASH_ALL), prv);
104104
}
105+
106+
/* Infer a descriptor from the generated script, and verify its solvability and that it roundtrips. */
107+
auto inferred = InferDescriptor(spks[n], script_provider);
108+
BOOST_CHECK_EQUAL(inferred->IsSolvable(), !(flags & UNSOLVABLE));
109+
std::vector<CScript> spks_inferred;
110+
FlatSigningProvider provider_inferred;
111+
BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred));
112+
BOOST_CHECK_EQUAL(spks_inferred.size(), 1);
113+
BOOST_CHECK(spks_inferred[0] == spks[n]);
114+
BOOST_CHECK_EQUAL(IsSolvable(provider_inferred, spks_inferred[0]), !(flags & UNSOLVABLE));
115+
BOOST_CHECK(provider_inferred.origins == script_provider.origins);
105116
}
117+
106118
// Test whether the observed key path is present in the 'paths' variable (which contains expected, unobserved paths),
107119
// and then remove it from that set.
108120
for (const auto& origin : script_provider.origins) {

0 commit comments

Comments
 (0)