Skip to content

Commit 1e3eac7

Browse files
committed
descriptor-policy: pass correctly sized key information map for tests
1 parent ef7220b commit 1e3eac7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/ctest/test_descriptor.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ static struct wally_map_item g_policy_map_items[] = {
5656
{ B("@1"), B("xpub6AHA9hZDN11k2ijHMeS5QqHx2KP9aMBRhTDqANMnwVtdyw2TDYRmF8PjpvwUFcL1Et8Hj59S3gTSMcUQ5gAqTz3Wd8EsMTmF3DChhqPQBnU") }
5757
};
5858

59-
static const struct wally_map g_policy_map = {
60-
g_policy_map_items,
61-
NUM_ELEMS(g_policy_map_items),
62-
NUM_ELEMS(g_policy_map_items),
63-
NULL
59+
/* 1 and 2 element key variable maps for policy testing.
60+
* The bip refers to these as "key information vectors".
61+
*/
62+
static const struct wally_map g_policy_maps[2] = {
63+
{ g_policy_map_items, 1, 1, NULL },
64+
{ g_policy_map_items, NUM_ELEMS(g_policy_map_items), NUM_ELEMS(g_policy_map_items), NULL }
6465
};
6566

6667
static const uint32_t g_miniscript_index_0 = 0;
@@ -1925,9 +1926,14 @@ static bool check_descriptor_to_script(const struct descriptor_test* test)
19251926
uint32_t multi_index = 0;
19261927
uint32_t child_num = test->child_num ? *test->child_num : 0, features;
19271928
const bool is_policy = test->flags & WALLY_MINISCRIPT_POLICY_TEMPLATE;
1928-
const struct wally_map *keys = is_policy ? &g_policy_map : &g_key_map;
1929+
const struct wally_map *keys = is_policy ? &g_policy_maps[0] : &g_key_map;
19291930

19301931
expected_ret = test->script ? WALLY_OK : WALLY_EINVAL;
1932+
if (is_policy && expected_ret == WALLY_OK) {
1933+
const char *p = strchr(test->descriptor, '@');
1934+
if (p && strchr(p + 1, '@'))
1935+
keys = &g_policy_maps[1]; /* 2-Element policy key map */
1936+
}
19311937

19321938
ret = wally_descriptor_parse(test->descriptor, keys, test->network,
19331939
test->flags, &descriptor);

0 commit comments

Comments
 (0)