diff --git a/src/krux/pages/home_pages/home.py b/src/krux/pages/home_pages/home.py index 627ab60e..5ee5dc14 100644 --- a/src/krux/pages/home_pages/home.py +++ b/src/krux/pages/home_pages/home.py @@ -323,7 +323,8 @@ def sign_psbt(self): if not self.prompt(t("Proceed?"), BOTTOM_PROMPT_LINE): return MENU_CONTINUE - # Show the policy for multisig and miniscript PSBTs in case the wallet descriptor is not loaded + # Show the policy for multisig and miniscript PSBTs + # in case the wallet descriptor is not loaded if ( not self.ctx.wallet.is_loaded() and not self.ctx.wallet.key.policy_type == TYPE_SINGLESIG diff --git a/src/krux/pages/home_pages/wallet_descriptor.py b/src/krux/pages/home_pages/wallet_descriptor.py index d6cbd600..fddcfdfb 100644 --- a/src/krux/pages/home_pages/wallet_descriptor.py +++ b/src/krux/pages/home_pages/wallet_descriptor.py @@ -31,7 +31,7 @@ from ...qr import FORMAT_NONE from ...sd_card import DESCRIPTOR_FILE_EXTENSION, JSON_FILE_EXTENSION from ...themes import theme -from ...key import FINGERPRINT_SYMBOL, TYPE_SINGLESIG +from ...key import FINGERPRINT_SYMBOL class WalletDescriptor(Page): diff --git a/tests/pages/home_pages/test_home.py b/tests/pages/home_pages/test_home.py index ebac36c4..dabe3fe8 100644 --- a/tests/pages/home_pages/test_home.py +++ b/tests/pages/home_pages/test_home.py @@ -6,7 +6,7 @@ @pytest.fixture def tdata(mocker): from collections import namedtuple - from krux.key import Key, P2PKH, P2SH_P2WPKH, P2TR + from krux.key import Key, P2PKH, P2SH_P2WPKH, P2TR, TYPE_SINGLESIG, TYPE_MULTISIG from embit.networks import NETWORKS TEST_12_WORD_MNEMONIC = ( @@ -16,32 +16,32 @@ def tdata(mocker): SIGNING_MNEMONIC = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" ACTION_MNEMONIC = "action action action action action action action action action action action action" - SINGLESIG_12_WORD_KEY = Key(TEST_12_WORD_MNEMONIC, False, NETWORKS["main"]) - SINGLESIG_24_WORD_KEY = Key(TEST_24_WORD_MNEMONIC, False, NETWORKS["main"]) - MULTISIG_12_WORD_KEY = Key(TEST_12_WORD_MNEMONIC, True, NETWORKS["main"]) - SINGLESIG_SIGNING_KEY = Key(SIGNING_MNEMONIC, False, NETWORKS["main"]) - MULTISIG_SIGNING_KEY = Key(SIGNING_MNEMONIC, True, NETWORKS["main"]) - SINGLESIG_ACTION_KEY = Key(ACTION_MNEMONIC, False, NETWORKS["main"]) + SINGLESIG_12_WORD_KEY = Key(TEST_12_WORD_MNEMONIC, TYPE_SINGLESIG, NETWORKS["main"]) + SINGLESIG_24_WORD_KEY = Key(TEST_24_WORD_MNEMONIC, TYPE_SINGLESIG, NETWORKS["main"]) + MULTISIG_12_WORD_KEY = Key(TEST_12_WORD_MNEMONIC, TYPE_MULTISIG, NETWORKS["main"]) + SINGLESIG_SIGNING_KEY = Key(SIGNING_MNEMONIC, TYPE_SINGLESIG, NETWORKS["main"]) + MULTISIG_SIGNING_KEY = Key(SIGNING_MNEMONIC, TYPE_MULTISIG, NETWORKS["main"]) + SINGLESIG_ACTION_KEY = Key(ACTION_MNEMONIC, TYPE_SINGLESIG, NETWORKS["main"]) SINGLESIG_ACTION_KEY_TEST = Key( - ACTION_MNEMONIC, False, NETWORKS["test"], script_type=P2TR + ACTION_MNEMONIC, TYPE_SINGLESIG, NETWORKS["test"], script_type=P2TR ) LEGACY1_KEY = Key( TEST_12_WORD_MNEMONIC, - False, + TYPE_SINGLESIG, NETWORKS["main"], account_index=1, script_type=P2PKH, ) NESTEDSW1_KEY = Key( TEST_12_WORD_MNEMONIC, - False, + TYPE_SINGLESIG, NETWORKS["main"], account_index=1, script_type=P2SH_P2WPKH, ) NATIVESW1_KEY = Key( TEST_12_WORD_MNEMONIC, - False, + TYPE_SINGLESIG, NETWORKS["main"], account_index=1, ) diff --git a/tests/pages/home_pages/test_pub_key_view.py b/tests/pages/home_pages/test_pub_key_view.py index 987174fd..675e08f7 100644 --- a/tests/pages/home_pages/test_pub_key_view.py +++ b/tests/pages/home_pages/test_pub_key_view.py @@ -7,6 +7,7 @@ def test_public_key(mocker, m5stickv, tdata): from krux.wallet import Wallet from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV from krux.qr import FORMAT_NONE + from krux.key import TYPE_MULTISIG cases = [ # Case parameters: [Wallet, Printer, Button Sequence, Show XPUB, Show ZPUB] @@ -77,7 +78,8 @@ def test_public_key(mocker, m5stickv, tdata): pub_key_viewer.public_key() - version = "Zpub" if ctx.wallet.key.multisig else "zpub" + version = "Zpub" if ctx.wallet.key.policy_type == TYPE_MULTISIG else "zpub" + print(ctx.key.policy_type, version) qr_view_calls = [] print_qr_calls = [] diff --git a/tests/pages/test_settings_page.py b/tests/pages/test_settings_page.py index 89034eb4..f18c58d8 100644 --- a/tests/pages/test_settings_page.py +++ b/tests/pages/test_settings_page.py @@ -28,14 +28,13 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): # Default Wallet BUTTON_ENTER, # Go to Network - BUTTON_PAGE, BUTTON_ENTER, # Change network *([BUTTON_PAGE] * 2), # Cycle through 2 options BUTTON_PAGE_PREV, # Go back to the second option - testnet BUTTON_ENTER, # Leave Default Wallet - *([BUTTON_PAGE] * 2), + *([BUTTON_PAGE] * 3), BUTTON_ENTER, # Leave Settings BUTTON_PAGE_PREV, @@ -150,7 +149,7 @@ def test_settings_m5stickv(m5stickv, mocker, mocker_printer): assert case[1]() -@pytest.fixture(params=["m5stickv", "cube"]) +@pytest.fixture(params=["m5stickv", "cube"]) # TODO:Add WonderMV to the list def bkl_control_devices(request): return request.getfixturevalue(request.param) @@ -221,7 +220,7 @@ def test_settings_on_amigo_tft(amigo, mocker, mocker_printer): # Enter Wallet 0, # Go to Network - 1, + 0, # Change network NEXT_INDEX, GO_INDEX, diff --git a/tests/pages/test_wallet_settings.py b/tests/pages/test_wallet_settings.py index e68eda40..52dce7de 100644 --- a/tests/pages/test_wallet_settings.py +++ b/tests/pages/test_wallet_settings.py @@ -110,13 +110,13 @@ def test_change_multisig_changes(m5stickv, mocker, tdata): ctx = create_ctx(mocker, BTN_SEQUENCE_1, Wallet(tdata.SINGLESIG_12_WORD_KEY)) mnemonic = ctx.wallet.key.mnemonic wallet_settings = WalletSettings(ctx) - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, @@ -138,13 +138,13 @@ def test_change_multisig_changes(m5stickv, mocker, tdata): ] ctx = create_ctx(mocker, BTN_SEQUENCE_2, ctx.wallet) wallet_settings = WalletSettings(ctx) - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, @@ -163,7 +163,7 @@ def test_change_script_type(m5stickv, mocker, tdata): BTN_SEQUENCE_1 = [ *([BUTTON_PAGE] * 2), # Go to "Script Type" BUTTON_ENTER, # Enter "Script Type" - BUTTON_PAGE_PREV, # Move to Taproot + *([BUTTON_PAGE] * 3), # Move to Taproot BUTTON_ENTER, # Confirm Taproot BUTTON_PAGE_PREV, # Go to Back BUTTON_ENTER, # Leave @@ -172,13 +172,13 @@ def test_change_script_type(m5stickv, mocker, tdata): ctx = create_ctx(mocker, BTN_SEQUENCE_1, Wallet(tdata.SINGLESIG_12_WORD_KEY)) mnemonic = ctx.wallet.key.mnemonic wallet_settings = WalletSettings(ctx) - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, @@ -198,13 +198,13 @@ def test_change_script_type(m5stickv, mocker, tdata): ] ctx = create_ctx(mocker, BTN_SEQUENCE_2, ctx.wallet) wallet_settings = WalletSettings(ctx) - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, @@ -234,13 +234,13 @@ def test_change_account(m5stickv, mocker, tdata): ctx = create_ctx(mocker, BTN_SEQUENCE_1, Wallet(tdata.SINGLESIG_12_WORD_KEY)) mnemonic = ctx.wallet.key.mnemonic wallet_settings = WalletSettings(ctx) - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, @@ -265,13 +265,13 @@ def test_change_account(m5stickv, mocker, tdata): ] ctx = create_ctx(mocker, BTN_SEQUENCE_2, ctx.wallet) wallet_settings = WalletSettings(ctx) - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, @@ -300,13 +300,13 @@ def test_change_account_esc(m5stickv, mocker, tdata): ctx = create_ctx(mocker, BTN_SEQUENCE_1, Wallet(tdata.SINGLESIG_12_WORD_KEY)) mnemonic = ctx.wallet.key.mnemonic wallet_settings = WalletSettings(ctx) - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, @@ -337,13 +337,13 @@ def test_account_out_of_range(m5stickv, mocker, tdata): mnemonic = ctx.wallet.key.mnemonic wallet_settings = WalletSettings(ctx) wallet_settings.flash_error = mocker.MagicMock() - network, multisig, script_type, account = wallet_settings.customize_wallet( + network, policy_type, script_type, account = wallet_settings.customize_wallet( ctx.wallet.key ) ctx.wallet = Wallet( Key( mnemonic, - multisig, + policy_type, network, "", # passphrase account, diff --git a/tests/test_context.py b/tests/test_context.py index 8278fa04..8d8649c1 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -42,6 +42,8 @@ def test_clear_clears_printer(mocker, m5stickv): def test_is_logged_in(mocker, m5stickv): + from krux.key import TYPE_SINGLESIG + mock_modules(mocker) from krux.context import Context from krux.wallet import Wallet @@ -52,5 +54,7 @@ def test_is_logged_in(mocker, m5stickv): c.wallet = Wallet(None) assert c.is_logged_in() == False - c.wallet = Wallet(Key(mnemonic="abandon " * 11 + "about", multisig=False)) + c.wallet = Wallet( + Key(mnemonic="abandon " * 11 + "about", policy_type=TYPE_SINGLESIG) + ) assert c.is_logged_in() == True diff --git a/tests/test_key.py b/tests/test_key.py index 9e70e94b..3a324972 100644 --- a/tests/test_key.py +++ b/tests/test_key.py @@ -88,14 +88,14 @@ def mock_modules(mocker): def test_init(mocker, m5stickv, tdata): mock_modules(mocker) from embit.networks import NETWORKS - from krux.key import Key + from krux.key import Key, TYPE_SINGLESIG, TYPE_MULTISIG cases = [ ( [tdata.TEST_12_WORD_MNEMONIC, False], { "mnemonic": tdata.TEST_12_WORD_MNEMONIC, - "multisig": False, + "policy_type": TYPE_SINGLESIG, "network": NETWORKS["test"], "root key": "tprv8ZgxMBicQKsPfJtsjGcMm6f7ibxmy2LbqbePeCJnhE3tFNKfuWmNHUyMnAfgwQXDSAhfTLGvN4f8zjEFochGbnHiZcrGXnyHDKQaTRK5trx", "derivation": "m/84h/1h/0h", @@ -106,7 +106,7 @@ def test_init(mocker, m5stickv, tdata): [tdata.TEST_12_WORD_MNEMONIC, True], { "mnemonic": tdata.TEST_12_WORD_MNEMONIC, - "multisig": True, + "policy_type": TYPE_MULTISIG, "network": NETWORKS["test"], "root key": "tprv8ZgxMBicQKsPfJtsjGcMm6f7ibxmy2LbqbePeCJnhE3tFNKfuWmNHUyMnAfgwQXDSAhfTLGvN4f8zjEFochGbnHiZcrGXnyHDKQaTRK5trx", "derivation": "m/48h/1h/0h/2h", @@ -117,7 +117,7 @@ def test_init(mocker, m5stickv, tdata): [tdata.TEST_12_WORD_MNEMONIC, False, NETWORKS["main"]], { "mnemonic": tdata.TEST_12_WORD_MNEMONIC, - "multisig": False, + "policy_type": TYPE_SINGLESIG, "network": NETWORKS["main"], "root key": "xprv9s21ZrQH143K4VfM4hkrbT38QUYZjWJbW3jGmmtLDFZQTmaav9RcmjburzW2w38u4jAtTEfACi5LXsgWgQMKnj282ydxsSFEJDfA1o1TySf", "derivation": "m/84h/0h/0h", @@ -128,7 +128,7 @@ def test_init(mocker, m5stickv, tdata): [tdata.TEST_12_WORD_MNEMONIC, True, NETWORKS["main"]], { "mnemonic": tdata.TEST_12_WORD_MNEMONIC, - "multisig": True, + "policy_type": TYPE_MULTISIG, "network": NETWORKS["main"], "root key": "xprv9s21ZrQH143K4VfM4hkrbT38QUYZjWJbW3jGmmtLDFZQTmaav9RcmjburzW2w38u4jAtTEfACi5LXsgWgQMKnj282ydxsSFEJDfA1o1TySf", "derivation": "m/48h/0h/0h/2h", @@ -139,7 +139,7 @@ def test_init(mocker, m5stickv, tdata): [tdata.TEST_24_WORD_MNEMONIC, False], { "mnemonic": tdata.TEST_24_WORD_MNEMONIC, - "multisig": False, + "policy_type": TYPE_SINGLESIG, "network": NETWORKS["test"], "root key": "tprv8ZgxMBicQKsPe5ghS4VTSeC3XwXJqVcJo4pzkFpuqZzFxhjuMsF13r8avzU8nwnwng6PCZ5EcJuPuqWwvJVCMRj3G9ZZyJ884RcrjAQ52BG", "derivation": "m/84h/1h/0h", @@ -150,7 +150,7 @@ def test_init(mocker, m5stickv, tdata): [tdata.TEST_24_WORD_MNEMONIC, True], { "mnemonic": tdata.TEST_24_WORD_MNEMONIC, - "multisig": True, + "policy_type": TYPE_MULTISIG, "network": NETWORKS["test"], "root key": "tprv8ZgxMBicQKsPe5ghS4VTSeC3XwXJqVcJo4pzkFpuqZzFxhjuMsF13r8avzU8nwnwng6PCZ5EcJuPuqWwvJVCMRj3G9ZZyJ884RcrjAQ52BG", "derivation": "m/48h/1h/0h/2h", @@ -161,7 +161,7 @@ def test_init(mocker, m5stickv, tdata): [tdata.TEST_24_WORD_MNEMONIC, False, NETWORKS["main"]], { "mnemonic": tdata.TEST_24_WORD_MNEMONIC, - "multisig": False, + "policy_type": TYPE_SINGLESIG, "network": NETWORKS["main"], "root key": "xprv9s21ZrQH143K3GTAmVdxGza4Dp76byaJTWussqQTMbVnB6zpNVuFY6m91pJUnaQdREZcCTTUSxKbSyyCo69FYNTSjWMGJwQ59KsSHUeNNQd", "derivation": "m/84h/0h/0h", @@ -172,7 +172,7 @@ def test_init(mocker, m5stickv, tdata): [tdata.TEST_24_WORD_MNEMONIC, True, NETWORKS["main"]], { "mnemonic": tdata.TEST_24_WORD_MNEMONIC, - "multisig": True, + "policy_type": TYPE_MULTISIG, "network": NETWORKS["main"], "root key": "xprv9s21ZrQH143K3GTAmVdxGza4Dp76byaJTWussqQTMbVnB6zpNVuFY6m91pJUnaQdREZcCTTUSxKbSyyCo69FYNTSjWMGJwQ59KsSHUeNNQd", "derivation": "m/48h/0h/0h/2h", @@ -186,7 +186,7 @@ def test_init(mocker, m5stickv, tdata): assert isinstance(key, Key) assert key.mnemonic == case[1]["mnemonic"] - assert key.multisig == case[1]["multisig"] + assert key.policy_type == case[1]["policy_type"] assert key.network == case[1]["network"] assert key.root.to_base58() == case[1]["root key"] assert key.derivation == case[1]["derivation"] diff --git a/tests/test_psbt.py b/tests/test_psbt.py index ecddde0a..cc8c664f 100644 --- a/tests/test_psbt.py +++ b/tests/test_psbt.py @@ -612,7 +612,7 @@ def test_outputs_multisig(mocker, m5stickv, tdata): [ "Inputs (2): ₿ 0.20 000 000\n\nSpend (1): ₿ 0.18 993 880\n\nSelf-transfer or Change (1): ₿ 0.01 000 000\n\nFee: ₿ 0.00 006 120 (0.1%) ~20.1 sat/vB", "1. Spend: \n\ntb1q35pg2rdt3p0v27dmdh9st43q8vzl29cps6kt3yradnqmg55eahfqfgn83n\n\n₿ 0.18 993 880", - "1. Self-transfer: \n\ntb1q4xgr8suxvgenukgf4c7r6qaawxxmy9zelh24q8hg5pfxzn2ekn3qfw808t\n\n₿ 0.01 000 000", + "1. Change: \n\ntb1q4xgr8suxvgenukgf4c7r6qaawxxmy9zelh24q8hg5pfxzn2ekn3qfw808t\n\n₿ 0.01 000 000", ], ), ( @@ -620,7 +620,7 @@ def test_outputs_multisig(mocker, m5stickv, tdata): [ "Inputs (1): ₿ 1.00 000 000\n\nSpend (1): ₿ 0.10 000 000\n\nSelf-transfer or Change (1): ₿ 0.89 995 740\n\nFee: ₿ 0.00 004 260 (0.1%) ~20.0 sat/vB", "1. Spend: \n\ntb1que40al7rsw88ru9z0vr78vqwme4w3ctqj694kx\n\n₿ 0.10 000 000", - "1. Self-transfer: \n\n2N3vYfcg14Axr4NN33ADUorE2kEGEchFJpC\n\n₿ 0.89 995 740", + "1. Change: \n\n2N3vYfcg14Axr4NN33ADUorE2kEGEchFJpC\n\n₿ 0.89 995 740", ], ), ] @@ -629,6 +629,7 @@ def test_outputs_multisig(mocker, m5stickv, tdata): signer = PSBTSigner(wallet, case[0], FORMAT_NONE) outputs, _ = signer.outputs() assert outputs == case[1] + # TODO: Re-create wallets and check if addresses are change indeed outside these tests def test_xpubs_fails_with_no_xpubs(mocker, m5stickv, tdata):