Skip to content

Commit

Permalink
add poor unit test to catch bug
Browse files Browse the repository at this point in the history
  • Loading branch information
newtonick committed Jul 16, 2024
1 parent b207a49 commit 98f6aed
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_flows_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ class TestMessageSigningFlows(FlowTest):
TESTNET_DERIVATION_PATH = "m/84h/1h/0h/0/0"
CUSTOM_DERIVATION_PATH = "m/99h/0/0"
SHORT_MESSAGE = "I attest that I control this bitcoin address blah blah blah"
NO_WHITESPACE_MESSAGE = """{"height":841407,"lightning_bolt12":"lno1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}"""
MULTIPAGE_MESSAGE = """Chancellor on brink of second bailout for banks
Billions may be needed as lending squeeze tightens
Expand Down Expand Up @@ -443,6 +444,10 @@ def load_multipage_message_into_decoder(self, view: View):
self.load_signmessage_into_decoder(view, self.MAINNET_DERIVATION_PATH, self.MULTIPAGE_MESSAGE)


def load_no_whitespace_message_into_decoder(self, view: View):
self.load_signmessage_into_decoder(view, self.MAINNET_DERIVATION_PATH, self.NO_WHITESPACE_MESSAGE)


def load_custom_derivation_into_decoder(self, view: View):
self.load_signmessage_into_decoder(view, self.CUSTOM_DERIVATION_PATH, self.SHORT_MESSAGE)

Expand All @@ -454,6 +459,7 @@ def inject_mesage_as_paged_message(self, view: View):
text=self.controller.sign_message_data["message"],
width=240 - 2*GUIConstants.EDGE_PADDING,
height=240 - GUIConstants.TOP_NAV_HEIGHT - 3*GUIConstants.EDGE_PADDING - GUIConstants.BUTTON_HEIGHT,
allow_text_overflow=True,
)
self.controller.sign_message_data["paged_message"] = paged

Expand Down Expand Up @@ -529,6 +535,21 @@ def test_sign_message_flow(self):
FlowStep(MainMenuView),
])

# Scenario 4: Load a long message without whitespace
self.controller.discard_seed(0)
self.run_sequence([
FlowStep(MainMenuView, button_data_selection=MainMenuView.SCAN),
FlowStep(scan_views.ScanView, before_run=self.load_seed_into_decoder), # simulate read SeedQR; ret val is ignored
FlowStep(seed_views.SeedFinalizeView, button_data_selection=seed_views.SeedFinalizeView.FINALIZE),
FlowStep(seed_views.SeedOptionsView, button_data_selection=seed_views.SeedOptionsView.SIGN_MESSAGE),
FlowStep(scan_views.ScanView, before_run=self.load_no_whitespace_message_into_decoder), # simulate read message QR; ret val is ignored
FlowStep(seed_views.SeedSignMessageStartView, is_redirect=True),
FlowStep(seed_views.SeedSignMessageConfirmMessageView, before_run=self.inject_mesage_as_paged_message, screen_return_value=0),
FlowStep(seed_views.SeedSignMessageConfirmAddressView, screen_return_value=0),
FlowStep(seed_views.SeedSignMessageSignedMessageQRView, screen_return_value=0),
FlowStep(MainMenuView),
])


def test_sign_message_network_mismatch_flow(self):
"""
Expand Down

0 comments on commit 98f6aed

Please sign in to comment.