Skip to content

Commit 729003e

Browse files
committed
wizard: move hw_unlock to base cls, and add test_wizard unlock_hw test
1 parent b0464cc commit 729003e

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

electrum/gui/qt/wizard/wallet.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from electrum.plugin import run_hook, HardwarePluginLibraryUnavailable
1818
from electrum.storage import StorageReadWriteError
1919
from electrum.util import WalletFileException, get_new_wallet_name, UserFacingException, InvalidPassword
20-
from electrum.util import is_subpath, ChoiceItem, multisig_type
20+
from electrum.util import is_subpath, ChoiceItem, multisig_type, UserCancelled
2121
from electrum.wallet import wallet_types
2222
from .wizard import QEAbstractWizard, WizardComponent
2323
from electrum.logging import get_logger, Logger
@@ -91,6 +91,7 @@ def __init__(self, config: 'SimpleConfig', app: 'QElectrumApplication', plugins:
9191
# attach gui classes to views
9292
self.navmap_merge({
9393
'wallet_name': {'gui': WCWalletName},
94+
'hw_unlock': {'gui': WCChooseHWDevice},
9495
'wallet_type': {'gui': WCWalletType},
9596
'keystore_type': {'gui': WCKeystoreType},
9697
'create_seed': {'gui': WCCreateSeed},
@@ -114,16 +115,12 @@ def __init__(self, config: 'SimpleConfig', app: 'QElectrumApplication', plugins:
114115
'wallet_password_hardware': {'gui': WCWalletPasswordHardware}
115116
})
116117

117-
# add open existing wallet from wizard, incl hw unlock
118+
# add open existing wallet from wizard
118119
self.navmap_merge({
119120
'wallet_name': {
120121
'next': lambda d: 'hw_unlock' if d['wallet_needs_hw_unlock'] else 'wallet_type',
121122
'last': lambda d: d['wallet_exists'] and not d['wallet_needs_hw_unlock']
122123
},
123-
'hw_unlock': {
124-
'gui': WCChooseHWDevice,
125-
'next': lambda d: self.on_hardware_device(d, new_wallet=False)
126-
}
127124
})
128125

129126
run_hook('init_wallet_wizard', self)
@@ -1333,6 +1330,8 @@ def on_ready(self):
13331330
def unlock_task(client):
13341331
try:
13351332
self.password = client.get_password_for_storage_encryption()
1333+
except UserCancelled as e:
1334+
self.error = repr(e)
13361335
except Exception as e:
13371336
self.error = repr(e) # TODO: handle user interaction exceptions (e.g. invalid pin) more gracefully
13381337
self.logger.exception(repr(e))

electrum/wizard.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ def __init__(self, daemon: 'Daemon', plugins: 'Plugins'):
382382
KeystoreWizard.__init__(self, plugins)
383383
self.navmap = {
384384
'wallet_name': {
385-
'next': 'wallet_type'
385+
'next': lambda d: 'hw_unlock' if d.get('wallet_needs_hw_unlock') else 'wallet_type',
386+
},
387+
'hw_unlock': {
388+
'next': lambda d: self.on_hardware_device(d, new_wallet=False),
386389
},
387390
'wallet_type': {
388391
'next': self.on_wallet_type

tests/test_wizard.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ class WalletWizardTestCase(WizardTestCase):
126126

127127
# TODO imported addresses
128128
# TODO imported WIF keys
129-
# TODO hardware signer std wallet (e.g. Trezor)
130-
# TODO encrypt with hardware (xpub) password
131129
# TODO multisig
132130
# TODO slip39
133131

@@ -523,3 +521,28 @@ async def test_create_standard_wallet_trezor(self):
523521
self.assertEqual("bc1q7ltf4aq95rj695fu5aaa5mx5m9p55xyr2fy6y0", wallet.get_receiving_addresses()[0])
524522
self.assertTrue(wallet.has_password())
525523
self.assertTrue(wallet.has_storage_encryption())
524+
525+
async def test_unlock_hw_trezor(self):
526+
# bip39 seed for trezor: "history six okay anchor sheriff flock atom tomorrow foster aerobic eternal foam"
527+
w = NewWalletWizard(DaemonMock(self.config), self.plugins)
528+
v = w.start()
529+
self.assertEqual('wallet_name', v.view)
530+
d = {
531+
'wallet_name': 'mywallet',
532+
'wallet_exists': True, 'wallet_is_open': False, 'wallet_needs_hw_unlock': True,}
533+
self.assertFalse(w.is_last_view(v.view, d))
534+
v = w.resolve_next(v.view, d)
535+
self.assertEqual('hw_unlock', v.view)
536+
537+
d.update({
538+
'hardware_device': (
539+
'trezor',
540+
DeviceInfo(
541+
device=Device(path='webusb:002:1', interface_number=-1, id_='webusb:002:1', product_key='Trezor', usage_page=0, transport_ui_string='webusb:002:1'),
542+
label='trezor_unittests', initialized=True, exception=None, plugin_name='trezor', soft_device_id='088C3F260B66F60E15DE0FA5', model_name='Trezor T'))})
543+
v = w.resolve_next(v.view, d)
544+
self.assertEqual('trezor_unlock', v.view)
545+
546+
d.update({'password': '03a580deb85ef85654ed177fc049867ce915a8b392a34a524123870925e48a5b9e'})
547+
self.assertTrue(w.is_last_view(v.view, d))
548+
v = w.resolve_next(v.view, d)

0 commit comments

Comments
 (0)