From 89bdf2d4993f335ba445cd3ac542a10c2e50ab57 Mon Sep 17 00:00:00 2001 From: scgbckbone Date: Fri, 10 Oct 2025 16:18:34 +0200 Subject: [PATCH] miniscript rename test --- releases/EdgeChangeLog.md | 4 ++- shared/ux_mk4.py | 2 +- shared/wallet.py | 8 +++--- testing/test_miniscript.py | 57 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/releases/EdgeChangeLog.md b/releases/EdgeChangeLog.md index bef9bf28..b46f5916 100644 --- a/releases/EdgeChangeLog.md +++ b/releases/EdgeChangeLog.md @@ -15,13 +15,15 @@ This lists the changes in the most recent EDGE firmware, for each hardware platf - New Feature: Key Teleport - New Feature: Spending Policy for Miniscript Wallets -- New Feature: Internal descriptor cache speeding up sequential operation with miniscript wallets. +- New Feature: Internal descriptor cache speeding up sequential operation with miniscript wallets. To take full advantage of the feature work with miniscript wallets sequentially. First, do all operations needed with `wallet1` before changing to `wallet2`. - New Feature: Add ability to import/export [BIP-388](https://github.com/bitcoin/bips/blob/master/bip-0388.mediawiki) Wallet Policies. BIP-388 policies are now also used as our wallets serialization format, which optimized our setting storage. - New Feature: Sign with specific miniscript wallet. `Settings -> Miniscript -> -> Sign PSBT` - New Feature: Miniscript wallet name can be specified for `sign` USB command +- New Feature: Rename Miniscript wallet via UX. `Settings -> Miniscript -> -> Rename`. + Old functionality - renaming by reimporting descriptor with different name was removed. - Change: Everything is miniscript now. To import multisig wallets go to `Settings -> Miniscript` - Enhancement: Slightly faster HW accelerated tagged hash - Enhancement: PSBT class optimizations. Ability to sign bigger txn. diff --git a/shared/ux_mk4.py b/shared/ux_mk4.py index 29a5d9cf..feb37ad2 100644 --- a/shared/ux_mk4.py +++ b/shared/ux_mk4.py @@ -283,7 +283,7 @@ async def ux_input_text(pw, confirm_exit=True, hex_only=False, max_len=100, min_ ch = await press.wait() if ch == 'y': if len(pw) < min_len: - ch = await ux_show_story('Need %d characters at least. Press OK ' + ch = await ux_show_story('Need %d character(s) at least. Press OK ' 'to continue X to exit.' % min_len, escape="xy", strict_escape=True) if ch == "x": return diff --git a/shared/wallet.py b/shared/wallet.py index 43bd753e..057da990 100644 --- a/shared/wallet.py +++ b/shared/wallet.py @@ -24,7 +24,7 @@ TRUST_OFFER = const(1) TRUST_PSBT = const(2) MAX_BIP32_IDX = (2 ** 31) - 1 - +MAX_NAME_LEN = 20 class WalletOutOfSpace(RuntimeError): pass @@ -159,7 +159,7 @@ class MiniScriptWallet(WalletABC): def __init__(self, name, desc_tmplt, keys_info, af, ik_u=None, desc=None, m_n=None, bip67=None, chain_type=None): - assert 1 <= len(name) <= 20, "name len" + assert 1 <= len(name) <= MAX_NAME_LEN, "name len" self.storage_idx = -1 self.name = name @@ -915,7 +915,7 @@ async def miniscript_wallet_rename(menu, label, item): idx, msc = item.arg new_name = await ux_input_text(msc.name, confirm_exit=False, - min_len=1, max_len=20) # TODO should be a constant + min_len=1, max_len=MAX_NAME_LEN) if not new_name: return @@ -1410,7 +1410,7 @@ async def multisig_640_migration(multisig_wallets): if name in taken_names: # name collision with miniscript name = name + "1" - if len(name) > 20: + if len(name) > MAX_NAME_LEN: # issue name = name[:15] + "mig1" diff --git a/testing/test_miniscript.py b/testing/test_miniscript.py index 48775c09..cc795f4b 100644 --- a/testing/test_miniscript.py +++ b/testing/test_miniscript.py @@ -6,7 +6,7 @@ import pytest, json, time, itertools, struct, random, os, base64 from ckcc.protocol import CCProtocolPacker from constants import AF_P2TR from psbt import BasicPSBT -from charcodes import KEY_QR, KEY_RIGHT, KEY_CANCEL +from charcodes import KEY_QR, KEY_RIGHT, KEY_CANCEL, KEY_DELETE from bbqr import split_qrs from bip32 import BIP32Node @@ -3289,7 +3289,58 @@ def test_bip388_policies(desc, way, offer_minsc_import, press_select, pick_menu_ assert usb_miniscript_get(new_name)["desc"].split("#")[0] == desc.split("#")[0].replace("'", 'h') -def test_miniscript_rename(): - pass +def test_miniscript_rename(offer_minsc_import, clear_miniscript, press_select, goto_home, + pick_menu_item, enter_complex, cap_menu, cap_screen, is_q1, + need_keypress, press_cancel): + clear_miniscript() + name = "old_name" + title, story = offer_minsc_import(json.dumps(dict(name=name, desc=CHANGE_BASED_DESCS[0]))) + assert "old_name" in story + assert "Create new miniscript wallet?" in story + press_select() + + goto_home() + pick_menu_item("Settings") + pick_menu_item("Miniscript") + pick_menu_item(name) + pick_menu_item("Rename") + if is_q1: + # old name is filled in input field + # same for Mk4, just not possible with cap_screen, or cap_story + time.sleep(.1) + scr = cap_screen() + assert name in scr + + new_name = 25 * "0" + # first delete old one + for _ in range(len(name) - (0 if is_q1 else 1)): + need_keypress(KEY_DELETE if is_q1 else "x") + + if is_q1: + # attempt to use empty string as a name + # on Mk4 it is not possible to not have at least one char + press_select() + time.sleep(.1) + scr = cap_screen() + assert "Need 1" in scr + + # it is not possible to input more than 20 characters + enter_complex(new_name, apply=False, b39pass=False) + + real_name = new_name[:20] + + # specific wallet menu has changed + time.sleep(.1) + m = cap_menu() + assert name not in m + assert real_name == m[0] + + # miniscript wallets menu has changed + press_cancel() # one back + + time.sleep(.1) + m = cap_menu() + assert name not in m + assert real_name == m[0] # EOF \ No newline at end of file