Skip to content

Commit 6da98e7

Browse files
committed
test: add change of networks
This commit add tests on `Customize` menu button and change `Networks` from `Mainnet` to `Testnet/Signet/Regtest`.
1 parent 40181c6 commit 6da98e7

5 files changed

Lines changed: 210 additions & 41 deletions

File tree

tests/pages/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
def create_ctx(mocker, btn_seq, wallet=None, printer=None, touch_seq=None):
55
"""Helper to create mocked context obj"""
66
from krux.krux_settings import Settings, THERMAL_ADAFRUIT_TXT
7-
from krux.context import Context
87

98
HASHED_IMAGE_BYTES = b"3\x0fr\x7fKY\x15\t\x83\xaab\x92\x0f&\x820\xb4\x14\x87\x19\xee\x95F\x9c\x8f\x0c\xbdo\xbc\x1d\xcbT"
109

11-
ctx: Context = mock_context(mocker)
10+
ctx = mock_context(mocker)
1211
ctx.power_manager.battery_charge_remaining.return_value = 1
1312
ctx.input.wait_for_button = mocker.MagicMock(side_effect=btn_seq)
1413
ctx.input.wait_for_fastnav_button = ctx.input.wait_for_button

tests/pages/home_pages/test_home.py

Lines changed: 162 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -414,49 +414,183 @@ def test_change_passphrase_menu(mocker, amigo, tdata):
414414
def test_cancel_customize_wallet_menu(mocker, amigo, tdata):
415415
from krux.pages.home_pages.home import Home
416416
from krux.wallet import Wallet
417-
from krux.input import BUTTON_ENTER, BUTTON_PAGE_PREV
417+
from krux.input import BUTTON_ENTER, BUTTON_PAGE_PREV, BUTTON_PAGE
418418

419-
BTN_SEQUENCE = [
420-
BUTTON_PAGE_PREV, # Move to No
421-
BUTTON_ENTER, # Press No
419+
cases = [
420+
# Case 0: Start with a mainnet wallet and cancel customization
421+
(
422+
[
423+
BUTTON_PAGE_PREV, # Move to No
424+
BUTTON_ENTER, # Press No
425+
],
426+
"Mainnet",
427+
"Mainnet",
428+
),
429+
# Case 1: Start with a mainnet wallet, start the customization and cancel it
430+
(
431+
[
432+
BUTTON_ENTER, # Choose Yes
433+
BUTTON_PAGE_PREV, # Move to Back
434+
BUTTON_ENTER, # Press Back
435+
],
436+
"Mainnet",
437+
"Mainnet",
438+
),
439+
# Case 2: Start with a mainnet wallet, start the customization and cancel it
440+
(
441+
[
442+
BUTTON_ENTER, # Choose Yes
443+
BUTTON_ENTER, # Choose network
444+
BUTTON_PAGE_PREV, # Move to Back
445+
BUTTON_ENTER, # Press Back
446+
BUTTON_PAGE_PREV, # Move to Back
447+
BUTTON_ENTER, # Press Back
448+
],
449+
"Mainnet",
450+
"Mainnet",
451+
),
452+
# Case 3: Start with a mainnet wallet, start the customization and select mainnet
453+
(
454+
[
455+
BUTTON_ENTER, # Choose Yes
456+
BUTTON_ENTER, # Choose network
457+
BUTTON_ENTER, # Press Mainnet
458+
BUTTON_PAGE_PREV, # Move to Back
459+
BUTTON_ENTER, # Press Back
460+
],
461+
"Mainnet",
462+
"Mainnet",
463+
),
464+
# Case 4: Start with a mainnet wallet, start the customization and select testnet
465+
(
466+
[
467+
BUTTON_ENTER, # Choose Yes
468+
BUTTON_ENTER, # Choose network
469+
BUTTON_PAGE, # Move to Testnet
470+
BUTTON_ENTER, # Press Testnet
471+
BUTTON_PAGE_PREV, # Move to Back
472+
BUTTON_ENTER, # Press Back
473+
],
474+
"Mainnet",
475+
"Testnet",
476+
),
477+
# Case 5: Start with a mainnet wallet, start the customization and select signet
478+
(
479+
[
480+
BUTTON_ENTER, # Choose Yes
481+
BUTTON_ENTER, # Choose network
482+
BUTTON_PAGE, # Move to Testnet
483+
BUTTON_PAGE, # Move to Signet
484+
BUTTON_ENTER, # Press Signet
485+
BUTTON_PAGE_PREV, # Move to Back
486+
BUTTON_ENTER, # Press Back
487+
],
488+
"Mainnet",
489+
"Signet",
490+
),
491+
# Case 6: Start with a mainnet wallet, start the customization and select regtest
492+
(
493+
[
494+
BUTTON_ENTER, # Choose Yes
495+
BUTTON_ENTER, # Choose network
496+
BUTTON_PAGE, # Move to Testnet
497+
BUTTON_PAGE, # Move to Signet
498+
BUTTON_PAGE, # Move to Regtest
499+
BUTTON_ENTER, # Press Regtest
500+
BUTTON_PAGE_PREV, # Move to Back
501+
BUTTON_ENTER, # Press Back
502+
],
503+
"Mainnet",
504+
"Regtest",
505+
),
422506
]
423507

424-
# Wallet before customization
425-
wallet = Wallet(tdata.SINGLESIG_SIGNING_KEY)
426-
assert wallet.key.network["name"] == "Mainnet"
508+
for n, case in enumerate(cases):
509+
print(f"Case {n}: {case}")
427510

428-
ctx = create_ctx(mocker, BTN_SEQUENCE, wallet=wallet)
429-
home = Home(ctx)
430-
home.customize()
511+
# Wallet before customization
512+
wallet = Wallet(tdata.SINGLESIG_SIGNING_KEY)
513+
assert wallet.key.network["name"] == case[1]
431514

432-
# Wallet after cancel customization
433-
# should remain the same as before
434-
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
435-
assert ctx.wallet.key.network["name"] == "Mainnet"
515+
ctx = create_ctx(mocker, case[0], wallet=wallet)
516+
home = Home(ctx)
517+
home.customize()
518+
519+
# Wallet after customization
520+
assert ctx.input.wait_for_button.call_count == len(case[0])
521+
assert ctx.wallet.key.network["name"] == case[2]
436522

437523

438524
def test_customize_wallet_menu(mocker, amigo, tdata):
439525
from krux.pages.home_pages.home import Home
440526
from krux.wallet import Wallet
441527
from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV
442528

443-
BTN_SEQUENCE = [
444-
BUTTON_ENTER, # Agree to customize
445-
BUTTON_ENTER, # Enter "Network"
446-
BUTTON_PAGE, # Change to "Testnet"
447-
BUTTON_ENTER, # Confirm "Testnet"
448-
BUTTON_PAGE_PREV, # Go to Back
449-
BUTTON_ENTER, # Exit
529+
cases = [
530+
# Mainet -> Mainnet
531+
(
532+
[
533+
BUTTON_ENTER, # Agree to customize
534+
BUTTON_ENTER, # Enter "Network"
535+
BUTTON_ENTER, # Confirm "Mainnet"
536+
BUTTON_PAGE_PREV, # Go to Back
537+
BUTTON_ENTER, # Exit
538+
],
539+
"Mainnet",
540+
"Mainnet",
541+
),
542+
# Mainet -> Testnet
543+
(
544+
[
545+
BUTTON_ENTER, # Agree to customize
546+
BUTTON_ENTER, # Enter "Network"
547+
BUTTON_PAGE, # Change to "Testnet"
548+
BUTTON_ENTER, # Confirm "Testnet"
549+
BUTTON_PAGE_PREV, # Go to Back
550+
BUTTON_ENTER, # Exit
551+
],
552+
"Mainnet",
553+
"Testnet",
554+
),
555+
# Mainet -> Signet
556+
(
557+
[
558+
BUTTON_ENTER, # Agree to customize
559+
BUTTON_ENTER, # Enter "Network"
560+
*([BUTTON_PAGE] * 2), # Change to "Signet"
561+
BUTTON_ENTER, # Confirm "Signet"
562+
BUTTON_PAGE_PREV, # Go to Back
563+
BUTTON_ENTER, # Exit
564+
],
565+
"Mainnet",
566+
"Signet",
567+
),
568+
# Mainet -> Regtest
569+
(
570+
[
571+
BUTTON_ENTER, # Agree to customize
572+
BUTTON_ENTER, # Enter "Network"
573+
*([BUTTON_PAGE] * 3), # Change to "Regtest"
574+
BUTTON_ENTER, # Confirm "Regtest"
575+
BUTTON_PAGE_PREV, # Go to Back
576+
BUTTON_ENTER, # Exit
577+
],
578+
"Mainnet",
579+
"Regtest",
580+
),
450581
]
451582

452-
wallet = Wallet(tdata.SINGLESIG_SIGNING_KEY)
453-
ctx = create_ctx(mocker, BTN_SEQUENCE, wallet=wallet)
454-
assert ctx.wallet.key.network["name"] == "Mainnet"
455-
home = Home(ctx)
456-
home.customize()
583+
for n, case in enumerate(cases):
584+
print(f"Case {n}: {case}")
585+
wallet = Wallet(tdata.SINGLESIG_12_WORD_KEY)
586+
ctx = create_ctx(mocker, case[0], wallet=wallet)
587+
assert ctx.wallet.key.network["name"] == case[1]
588+
home = Home(ctx)
589+
home.customize()
457590

458-
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
459-
assert ctx.wallet.key.network["name"] == "Testnet"
591+
assert ctx.wallet.key.network["name"] == case[2]
592+
assert ctx.input.wait_for_button.call_count == len(case[0])
593+
n += 1
460594

461595

462596
def test_cancel_load_bip85_menu(mocker, amigo, tdata):

tests/pages/test_login.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ def mock_retro_compatibility(mocker, amigo):
1313

1414
class MockDefaultWallet:
1515
namespace = "settings.wallet"
16-
network = CategorySetting("network", "main", ["main", "test"])
16+
network = CategorySetting(
17+
"network", "main", ["main", "test", "signet", "regtest"]
18+
)
1719
script_type = CategorySetting("script_type", "test", ["test"])
1820
multisig = CategorySetting("multisig", True, [True, False])
1921

tests/shared_mocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def board_embed_fire():
775775
)
776776

777777

778-
def mock_context(mocker):
778+
def mock_context(mocker: MagicMock):
779779
import board
780780

781781
if board.config["type"] == "m5stickv":

0 commit comments

Comments
 (0)