Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
#
# libwally-core documentation build configuration file
from os import getenv

SCANNING, DOCS, FUNC = 1, 2, 3

from os import getenv
# DUMP_FUNCS/DUMP_INTERNAL are used by tools/build_wrappers.py to auto-generate wrapper code
DUMP_FUNCS = getenv("WALLY_DOC_DUMP_FUNCS") is not None
DUMP_INTERNAL = DUMP_FUNCS and getenv("WALLY_DOC_DUMP_INTERNAL") is not None
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""setuptools config for wallycore """
from setuptools import setup, Extension
import copy, os, platform, shutil, subprocess, sys
import copy
import distutils.sysconfig
import os
import platform
import subprocess
import sys

def _msg(s):
print(s + '\n', file=sys.stderr)
Expand Down
170 changes: 161 additions & 9 deletions src/ctest/test_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ static struct wally_map_item g_key_map_items[] = {
{ B("mainnet_xpub"), B("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL") },
{ B("mainnet_xpriv"), B("xprvA2YKGLieCs6cWCiczALiH1jzk3VCCS5M1pGQfWPkamCdR9UpBgE2Gb8AKAyVjKHkz8v37avcfRjdcnP19dVAmZrvZQfvTcXXSAiFNQ6tTtU") },
{ B("uncompressed"), B("0414fc03b8df87cd7b872996810db8458d61da8448e531569c8517b469a119d267be5645686309c6e6736dbd93940707cc9143d3cf29f1b877ff340e2cb2d259cf") },
{ B("x_only"), B("b71aa79cab0ae2d83b82d44cbdc23f5dcca3797e8ba622c4e45a8f7dce28ba0e") },
{ B("non_x_only"), B("03b71aa79cab0ae2d83b82d44cbdc23f5dcca3797e8ba622c4e45a8f7dce28ba0e") }
};

static const struct wally_map g_key_map = {
Expand Down Expand Up @@ -369,6 +371,30 @@ static const struct descriptor_test {
WALLY_NETWORK_NONE, 0, 0, 0, NULL, 0,
"76a91477b6f27ac523d8b9aa8abcfc94fd536493202ae088ac",
"9gv5p2gj"
},{
"descriptor - rawtr - x-only",
"rawtr(x_only)",
WALLY_NETWORK_BITCOIN_REGTEST, 0, 0, 0, NULL, 0,
"5120b71aa79cab0ae2d83b82d44cbdc23f5dcca3797e8ba622c4e45a8f7dce28ba0e",
"nsnjmrf4"
},{
"descriptor - rawtr - non-x-only returns the same script as x-only",
"rawtr(non_x_only)",
WALLY_NETWORK_BITCOIN_REGTEST, 0, 0, 0, NULL, 0,
"5120b71aa79cab0ae2d83b82d44cbdc23f5dcca3797e8ba622c4e45a8f7dce28ba0e",
"ha989syu"
},{
"descriptor - tr - x-only",
"tr(x_only)",
WALLY_NETWORK_BITCOIN_REGTEST, 0, 0, 0, NULL, 0,
"51205fb8e39dbbdc7c831af59e44a9b2997f9daaf72c3e965b30982f3c731539e1db",
"axny68jy"
},{
"descriptor - tr - non-x-only returns the same script as x-only",
"tr(non_x_only)",
WALLY_NETWORK_BITCOIN_REGTEST, 0, 0, 0, NULL, 0,
"51205fb8e39dbbdc7c831af59e44a9b2997f9daaf72c3e965b30982f3c731539e1db",
"tp2ky708"
},{
"descriptor - A single key",
"wsh(c:pk_k(key_1))",
Expand Down Expand Up @@ -477,6 +503,12 @@ static const struct descriptor_test {
* Miniscript: Randomly generated test set that covers the majority of type and node type combinations
*/
{
"miniscript - A single key",
"pk_k(key_1)",
WALLY_NETWORK_NONE, 0, 0, 0, NULL, WALLY_MINISCRIPT_ONLY,
"21038bc7431d9285a064b0328b6333f3a20b86664437b6de8f4e26e6bbdee258f048",
"jyazm5lc"
},{
"miniscript - random 1",
"lltvln:after(1231488000)",
WALLY_NETWORK_NONE, 0, 0, 0, NULL, WALLY_MINISCRIPT_ONLY,
Expand Down Expand Up @@ -761,13 +793,13 @@ static const struct descriptor_test {
* Miniscript: BOLT examples
*/
{
"miniscript - A single key",
"miniscript - A single key + CHECKSIG",
"c:pk_k(key_1)",
WALLY_NETWORK_NONE, 0, 0, 0, NULL, WALLY_MINISCRIPT_ONLY,
"21038bc7431d9285a064b0328b6333f3a20b86664437b6de8f4e26e6bbdee258f048ac",
""
}, {
"miniscript - A single key (2)",
"miniscript - A single key + CHECKSIG (2)",
"pk(key_1)",
WALLY_NETWORK_NONE, 0, 0, 0, NULL, WALLY_MINISCRIPT_ONLY,
"21038bc7431d9285a064b0328b6333f3a20b86664437b6de8f4e26e6bbdee258f048ac",
Expand Down Expand Up @@ -897,7 +929,7 @@ static const struct descriptor_test {
"d959hk4q"
},
/*
* Taproot cases
* Miniscript taproot cases
*/
{
"miniscript - taproot raw pubkey",
Expand Down Expand Up @@ -1139,6 +1171,14 @@ static const struct descriptor_test {
"descriptor - pk - non-key child",
"pk(1)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - pk - invalid public key",
"pk(uncompresseduncompressed)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - pk - x-only child",
"pk(x_only)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - pk - multi-child",
"pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)",
Expand Down Expand Up @@ -1251,6 +1291,46 @@ static const struct descriptor_test {
"descriptor - raw - any parent",
"pk(raw(000102030405060708090a0b0c0d0e0f))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - empty rawtr",
"rawtr()",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - multi-child",
"rawtr(x_only,x_only)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - any parent",
"pk(rawtr(x_only))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - uncompressed key",
"rawtr(uncompressed)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - invalid public key",
"rawtr(uncompresseduncompressed)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - empty tr",
"tr()",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - multi-child",
"tr(x_only,x_only)", /* FIXME: delete this case when script path is supported */
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - any parent",
"pk(tr(x_only))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - uncompressed key",
"tr(uncompressed)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - invalid public key",
"tr(uncompresseduncompressed)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - after - non number child",
"wsh(after(key_1))",
Expand Down Expand Up @@ -1729,6 +1809,46 @@ static const struct address_test {
1, 0, 0,
ADDR("mn9rm3FtHUHANae2p5jURy9GXJGDM1ox43")
},
/*
* Taproot
*/
{
"address - rawtr (x-only)",
"rawtr(x_only)",
WALLY_NETWORK_BITCOIN_REGTEST,
0, 0, 0,
ADDR("bcrt1pkud2089tpt3dswuz63xtms3lthx2x7t73wnz938yt28hmn3ghg8qvxhwkz")
}, {
"address list - rawtr (0-4)",
"rawtr([59d1f3b0/86'/1'/0']tpubDC2Q4xK4XH72Gow34bNSZpx7uPcg1gfu6hPACSSieETYzpWgywMLmi2Yz9STA2Nrif3Yav7jvkzSj8q3nDKjjQrEfRYckUj5jsadYCdCw1C/0/*)#2k4we0vv",
WALLY_NETWORK_BITCOIN_REGTEST,
0, 0, 0, 5,
{
"bcrt1p7evqsttltmzxd4sjyzhdzs5nj8tmahu0qdpge8t7gp3dsr3hx3dq403ahy",
"bcrt1pa76letfw4eskpz9wap84ha0vcajul7xhhnhktmpp0mhgzlcdr6gswjcq3u",
"bcrt1phmq09p8y6efk06fp5hvf6dkvjsq2vfmph2uuy7y6ya6jvmrfxq3s44cksv",
"bcrt1p9s6clznyy4enaplm2ak9fa0t3d66s5q5m4khpg7w00w9wuerp93q88e9ql",
"bcrt1p220y7newnya8fk04079hcvd3cupx6t8ta659nayh8kaav39f3scsf63y8h",
}
}, {
"address - tr (x-only)",
"tr(x_only)",
WALLY_NETWORK_BITCOIN_REGTEST,
0, 0, 0,
ADDR("bcrt1pt7uw88dmm37gxxh4nez2nv5e07w64aev86t9kvyc9u78x9feu8dsp5hh3s")
}, {
"address list - tr (5-9)",
"tr([59d1f3b0/86'/1'/0']tpubDC2Q4xK4XH72Gow34bNSZpx7uPcg1gfu6hPACSSieETYzpWgywMLmi2Yz9STA2Nrif3Yav7jvkzSj8q3nDKjjQrEfRYckUj5jsadYCdCw1C/0/*)#9wpuzyss",
WALLY_NETWORK_BITCOIN_REGTEST,
0, 0, 5, 5,
{
"bcrt1p3hf8e9tczepujy3fe66wgq9ez5tllqkschupy08pfzukjtye5wksgtj5k2",
"bcrt1p9wut0rvmq347rldeyktdn9qmrj9qk9ynefykruxrp4yr9u27pzvqfd6ktq",
"bcrt1p3kjmw33umzaylvdmglk489vd4ph2te67ged3c4fmk20adn0pfknsm5jmvu",
"bcrt1pz6t2y0qg69594u60qmnlq23rezxseyf65qk0xl2kt7l02y8rcs8qndm2sm",
"bcrt1p2nunl5trs2hfrlu5fp6kg3hu3tffpzg0w5m56mpmx8m96pl0qxnszgdnaw",
}
},
/*
* Multi-path
*/
Expand Down Expand Up @@ -1948,9 +2068,8 @@ static const struct address_test {
static bool check_descriptor_to_script(const struct descriptor_test* test)
{
struct wally_descriptor *descriptor;
size_t written, max_written;
const size_t script_len = 520;
unsigned char *script = malloc(script_len);
size_t written, computed_written, max_written;
const size_t default_script_len = 520;
char *checksum, *canonical;
int expected_ret, ret, len_ret;
uint32_t multi_index = 0;
Expand Down Expand Up @@ -1980,25 +2099,53 @@ static bool check_descriptor_to_script(const struct descriptor_test* test)
if (!check_ret("descriptor_parse", ret, expected_ret))
return false;

if (expected_ret != WALLY_OK) {
free(script);
if (expected_ret != WALLY_OK)
return true;
}
}

computed_written = default_script_len;
if (expected_ret == WALLY_OK) {
/* Try the call with a too-short buffer.
* This returns a more exact required size for generation, although
* it may still overestimate by a few bytes for some descriptors.
*/
unsigned char *short_script = malloc(1);
ret = wally_descriptor_to_script(descriptor,
test->depth, test->index,
test->variant, multi_index,
child_num, 0,
short_script, 1, &computed_written);
free(short_script);
if (!check_ret("descriptor_to_script(short buffer)\n", ret, expected_ret))
return false;
}

const size_t script_len = computed_written ? computed_written : 1;
unsigned char *script = malloc(script_len);
ret = wally_descriptor_to_script(descriptor,
test->depth, test->index,
test->variant, multi_index,
child_num, 0,
script, script_len, &written);
if (ret == WALLY_OK && written > script_len) {
printf("descriptor_to_script: wrote more than computed length!\n");
return false;
}
if (!check_ret("descriptor_to_script", ret, expected_ret))
return false;

if (expected_ret != WALLY_OK) {
/* Failure case: stop testing here */
wally_descriptor_free(descriptor);
free(script);
return true;
}

if (computed_written < written) {
printf("descriptor_to_script: computed < written\n");
return false;
}

ret = wally_descriptor_get_features(descriptor, &features);
if (!check_ret("descriptor_get_features", ret, WALLY_OK))
return false;
Expand All @@ -2010,6 +2157,11 @@ static bool check_descriptor_to_script(const struct descriptor_test* test)
max_written < written)
return false;

if (computed_written > max_written) {
printf("descriptor_to_script: computed > max written\n");
return false;
}

ret = wally_descriptor_get_checksum(descriptor, 0, &checksum);
if (!check_ret("descriptor_get_checksum", ret, WALLY_OK))
return false;
Expand Down
Loading
Loading