@@ -79,28 +79,42 @@ void Check(const std::string& prv, const std::string& pub, int flags, const std:
79
79
BOOST_CHECK_EQUAL (parse_pub->IsRange (), (flags & RANGE) != 0 );
80
80
BOOST_CHECK_EQUAL (parse_priv->IsRange (), (flags & RANGE) != 0 );
81
81
82
-
83
- // Is not ranged descriptor, only a single result is expected.
82
+ // * For ranged descriptors, the `scripts` parameter is a list of expected result outputs, for subsequent
83
+ // positions to evaluate the descriptors on (so the first element of `scripts` is for evaluating the
84
+ // descriptor at 0; the second at 1; and so on). To verify this, we evaluate the descriptors once for
85
+ // each element in `scripts`.
86
+ // * For non-ranged descriptors, we evaluate the descriptors at positions 0, 1, and 2, but expect the
87
+ // same result in each case, namely the first element of `scripts`. Because of that, the size of
88
+ // `scripts` must be one in that case.
84
89
if (!(flags & RANGE)) assert (scripts.size () == 1 );
85
-
86
90
size_t max = (flags & RANGE) ? scripts.size () : 3 ;
91
+
92
+ // Iterate over the position we'll evaluate the descriptors in.
87
93
for (size_t i = 0 ; i < max; ++i) {
94
+ // Call the expected result scripts `ref`.
88
95
const auto & ref = scripts[(flags & RANGE) ? i : 0 ];
96
+ // When t=0, evaluate the `prv` descriptor; when t=1, evaluate the `pub` descriptor.
89
97
for (int t = 0 ; t < 2 ; ++t) {
98
+ // When the descriptor is hardened, evaluate with access to the private keys inside.
90
99
const FlatSigningProvider& key_provider = (flags & HARDENED) ? keys_priv : keys_pub;
100
+
101
+ // Evaluate the descriptor selected by `t` in poisition `i`.
91
102
FlatSigningProvider script_provider, script_provider_cached;
92
103
std::vector<CScript> spks, spks_cached;
93
104
std::vector<unsigned char > cache;
94
105
BOOST_CHECK ((t ? parse_priv : parse_pub)->Expand (i, key_provider, spks, script_provider, &cache));
95
106
107
+ // Compare the output with the expected result.
108
+ BOOST_CHECK_EQUAL (spks.size (), ref.size ());
109
+
96
110
// Try to expand again using cached data, and compare.
97
111
BOOST_CHECK (parse_pub->ExpandFromCache (i, cache, spks_cached, script_provider_cached));
98
112
BOOST_CHECK (spks == spks_cached);
99
113
BOOST_CHECK (script_provider.pubkeys == script_provider_cached.pubkeys );
100
114
BOOST_CHECK (script_provider.scripts == script_provider_cached.scripts );
101
115
BOOST_CHECK (script_provider.origins == script_provider_cached.origins );
102
116
103
- BOOST_CHECK_EQUAL (spks. size (), ref. size ());
117
+ // For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it.
104
118
for (size_t n = 0 ; n < spks.size (); ++n) {
105
119
BOOST_CHECK_EQUAL (ref[n], HexStr (spks[n].begin (), spks[n].end ()));
106
120
BOOST_CHECK_EQUAL (IsSolvable (Merge (key_provider, script_provider), spks[n]), (flags & UNSOLVABLE) == 0 );
@@ -132,6 +146,7 @@ void Check(const std::string& prv, const std::string& pub, int flags, const std:
132
146
}
133
147
}
134
148
}
149
+
135
150
// Verify no expected paths remain that were not observed.
136
151
BOOST_CHECK_MESSAGE (left_paths.empty (), " Not all expected key paths found: " + prv);
137
152
}
0 commit comments