Skip to content

Commit

Permalink
Fix generated Script for miniscript a: wrapper; added test
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Apr 7, 2023
1 parent 250b327 commit f9673ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/handler/lib/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ static const generic_processor_command_t commands_or_i[] = {{CMD_CODE_OP, OP_IF}

static const generic_processor_command_t commands_a[] = {{CMD_CODE_OP, OP_TOALTSTACK},
{CMD_CODE_PROCESS_CHILD, 0},
{CMD_CODE_OP, OP_FROMALTSTACK},
{CMD_CODE_END, 0}};

static const generic_processor_command_t commands_s[] = {{CMD_CODE_OP, OP_SWAP},
Expand Down
23 changes: 14 additions & 9 deletions tests/test_e2e_miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,32 @@ def test_e2e_miniscript_me_and_bob_or_me_and_carl_1(rpc, rpc_test_wallet, client
run_test_e2e(wallet_policy, [core_wallet_name1], rpc, rpc_test_wallet, client, speculos_globals, comm)


def test_e2e_miniscript_me_and_bob_or_me_and_carl_2(rpc, rpc_test_wallet, client: Client, speculos_globals: SpeculosGlobals, comm: Union[TransportClient, SpeculosClient]):
# same as the previous example, but uses the same xpubs with two different paths for the internal keys,
# by using the /<M,N>/* notation instead of different internal xpubs
def test_e2e_miniscript_policy_with_a(rpc, rpc_test_wallet, client: Client, speculos_globals: SpeculosGlobals, comm: Union[TransportClient, SpeculosClient]):
# versions 2.1.0 and 2.1.1 of the app incorrectly compiled the 'a:' wrapper, producing incorrect addresses

core_wallet_name1, core_xpub_orig1 = create_new_wallet()
_, core_xpub_orig1 = create_new_wallet()
_, core_xpub_orig2 = create_new_wallet()
core_wallet_name3, core_xpub_orig3 = create_new_wallet()
_, core_xpub_orig4 = create_new_wallet()
_, core_xpub_orig5 = create_new_wallet()

path = "44'/1'/0'"
path = "48'/1'/0'/2'"
internal_xpub = get_internal_xpub(speculos_globals.seed, path)
internal_xpub_orig = f"[{speculos_globals.master_key_fingerprint.hex()}/{path}]{internal_xpub}"

wallet_policy = WalletPolicy(
name="Me and Bob or me and Carl",
descriptor_template="wsh(c:andor(pk(@0/<0;1>/*),pk_k(@1/**),and_v(v:pk(@0/<2;3>/*),pk_k(@2/**))))",
name="Policy with a:",
descriptor_template="wsh(or_i(and_v(v:pkh(@0/**),older(65535)),or_d(multi(2,@1/**,@3/**),and_v(v:thresh(1,pkh(@4/**),a:pkh(@5/**)),older(64231)))))",
keys_info=[
internal_xpub_orig,
f"{core_xpub_orig1}",
internal_xpub_orig,
f"{core_xpub_orig2}",
f"{core_xpub_orig3}",
f"{core_xpub_orig4}",
f"{core_xpub_orig5}",
])

run_test_e2e(wallet_policy, [core_wallet_name1], rpc, rpc_test_wallet, client, speculos_globals, comm)
run_test_e2e(wallet_policy, [core_wallet_name3], rpc, rpc_test_wallet, client, speculos_globals, comm)


def test_invalid_miniscript(rpc, client: Client, speculos_globals: SpeculosGlobals):
Expand Down

0 comments on commit f9673ef

Please sign in to comment.