Merge pull request #725 from Foundation-Devices/SFT-7375-paginate-transaction-details
What changed, and why it matters
This commit changes how the Passport hardware wallet displays transaction details during signing. Instead of one long scrolling screen, it now breaks the review into separate pages and requires the user to scroll to the bottom of each page before pressing forward. This is a user-interface hardening change meant to make sure people actually see all transaction details and warnings before approving. It is not a fix for a remote exploit or a cryptographic bug, but it does reduce the chance that a user accidentally approves a bad transaction because important information was hidden off-screen.
Treat as a security-hardening improvement rather than an emergency patch. Review the scroll-gate implementation for edge cases (very short pages, dynamic layout updates, and event-callback removal on detach) and ensure the pagination order cannot be skipped or reordered by a malicious PSBT. Continue running the new transaction_review.py unit tests in CI.
Security signals we found
UI anti-tampering: require_scroll_to_end prevents users from advancing until all page content has been viewed
Pagination splits transaction outputs, change, fees, and warnings into separate screens, reducing hidden-off-screen content
Adds unit and UI tests for review pagination and scroll-gate behavior
Removes old aggregate render_warnings() in favor of per-page rendering
Evidence from the diff
The patch refactors SignPsbtCommonFlow.show_transaction_details() to paginate transaction review and adds a require_scroll_to_end gate to LongTextPage. The flow now yields discrete review pages (outputs, change, fee, warnings) and only advances when the user reaches the bottom of each page. LongTextPage disables the right/forward micron until the scroll position reaches the bottom, then re-enables it. Tests are updated and expanded to cover pagination, forward/back navigation, and the scroll-gate behavior. The change removes the old separate show_change() and show_warnings() flow steps and folds them into the paginated review.
Changed components
ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.pyports/stm32/boards/Passport/modules/pages/long_text_page.pyports/stm32/boards/Passport/modules/tests/unit/transaction_review.pyports/stm32/boards/Passport/modules/tests/unit/one_of_n_warning.pyports/stm32/boards/Passport/modules/tests/unit/psbt_fee.pyports/stm32/boards/Passport/modules/tests/host/test_wallet_policy_flows.pyports/stm32/boards/Passport/modules/tests/test_unit.pyInspect captured patch +384 / −199
### ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.py
@@ -9,10 +9,8 @@
#
# sign_psbt_common_flow.py - Sign a PSBT from a microSD card
-import lvgl as lv
from flows import Flow
import microns
-from pages.chooser_page import ChooserPage
from styles.colors import HIGHLIGHT_TEXT_HEX, BLACK_HEX
from tasks import validate_psbt_task
import gc
@@ -27,6 +25,7 @@ def __init__(self, psbt_len):
self.psbt_len = psbt_len
self.chain = chains.current_chain()
self.header = 'Transaction Info'
+ self.review_page_index = 0
async def validate_psbt(self):
(self.psbt, error_msg, error) = await spinner_task('Validating transaction', validate_psbt_task,
@@ -62,7 +61,7 @@ async def check_multisig_import(self):
self.set_result(None)
return
- # Review hides change destinations, so prove ownership before showing it.
+ # Prove ownership before presenting an output as change.
if any(output.is_change for output in self.psbt.outputs):
gc.collect()
(error_msg, error) = await spinner_task('Verifying change',
@@ -76,104 +75,87 @@ async def check_multisig_import(self):
self.goto(self.show_transaction_details)
async def show_transaction_details(self):
- import uio
+ import common
+ from animations.constants import TRANSITION_DIR_POP, TRANSITION_DIR_PUSH
from pages import LongTextPage, ErrorPage
from public_constants import MARGIN_FOR_ADDRESSES
try:
- outputs = uio.StringIO()
-
- if self.psbt.self_send:
- outputs.write("\n{}\n".format(recolor(HIGHLIGHT_TEXT_HEX, 'Self-Send')))
-
- first = True
- for idx, tx_out in self.psbt.output_iter():
- gc.collect()
- outp = self.psbt.outputs[idx]
- # Show change outputs if this is a self-send
- if outp.is_change and not self.psbt.self_send:
- continue
-
- if first:
- first = False
+ while True:
+ for page_index, text in enumerate(self.review_pages()):
+ if page_index < self.review_page_index:
+ continue
+ gc.collect()
+ result = await LongTextPage(
+ text=text,
+ centered=True,
+ card_header={'title': self.header},
+ margins=MARGIN_FOR_ADDRESSES,
+ require_scroll_to_end=True,
+ ).show()
+ if result:
+ self.review_page_index += 1
+ common.page_transition_dir = TRANSITION_DIR_PUSH
+ elif result is False and self.review_page_index > 0:
+ self.review_page_index -= 1
+ common.page_transition_dir = TRANSITION_DIR_POP
+ break
+ else:
+ self.set_result(None)
+ return
else:
- outputs.write('\n')
-
- outputs.write(self.render_output(tx_out))
-
- gc.collect()
-
- # print('total_out={} total_in={}
- # change={}'.format=(self.psbt.total_value_out, self.psbt.total_value_in,
- # self.psbt.total_value_in - self.psbt.total_value_out))
-
- result = await LongTextPage(
- text=outputs.getvalue(),
- centered=True,
- card_header={'title': self.header},
- margins=MARGIN_FOR_ADDRESSES,
- ).show()
- if result:
- if self.psbt.self_send:
- self.goto(self.show_warnings)
- else:
- self.goto(self.show_change)
- else:
- self.set_result(None)
+ self.review_page_index = page_index
+ self.goto(self.show_policy_authorization)
+ return
except MemoryError:
await ErrorPage(text='Transaction is too complex.').show()
self.set_result(None)
- except BaseException as e:
- await ErrorPage(text=self.invalid_psbt_text(e)).show()
+ except Exception as error:
+ await ErrorPage(text=self.invalid_psbt_text(error)).show()
self.set_result(None)
- async def show_change(self):
- from pages import LongTextPage, ErrorPage
- from public_constants import MARGIN_FOR_ADDRESSES
-
- try:
- msg = self.render_change_text()
- result = await LongTextPage(
- text=msg,
- centered=True,
- card_header={'title': self.header},
- margins=MARGIN_FOR_ADDRESSES
- ).show()
- gc.collect()
- if not result:
- self.back()
- else:
- self.goto(self.show_warnings)
- except Exception as e:
- await ErrorPage(text=self.invalid_psbt_text(e)).show()
- self.set_result(None)
-
- async def show_warnings(self):
- from pages import LongTextPage
-
- warnings = self.render_warnings()
- gc.collect()
- # print('warnings = "{}"'.format(warnings))
-
- if warnings is not None:
- result = await LongTextPage(
- text=warnings,
- centered=True,
- card_header={'title': self.header}
- ).show()
- if not result:
- self.back()
- else:
- self.goto(self.show_policy_authorization)
+ def review_pages(self):
+ output_count = sum(not output.is_change or self.psbt.self_send for output in self.psbt.outputs)
+ output_number = 0
+ for index, output in self.psbt.output_iter():
+ if self.psbt.outputs[index].is_change and not self.psbt.self_send:
+ continue
+ output_number += 1
+ title = 'Self-Send' if self.psbt.self_send else 'Output'
+ title = recolor(HIGHLIGHT_TEXT_HEX, '{} {}/{}'.format(title, output_number, output_count))
+ yield '{}\n{}'.format(title, self.render_output(output))
+
+ if not self.psbt.self_send:
+ yield self.render_change_text()
+ change_count = sum(1 for output in self.psbt.outputs if output.is_change)
+ change_number = 0
+ for index, output in self.psbt.output_iter():
+ if not self.psbt.outputs[index].is_change:
+ continue
+ change_number += 1
+ title = recolor(HIGHLIGHT_TEXT_HEX, 'Change {}/{}'.format(change_number, change_count))
+ yield '{}\n{}'.format(title, self.render_output(output))
+
+ fee_labels = ('Big Fee', 'Huge Fee', 'Unverified Fee')
+ fee_text = self.render_fee()
+ fee_warnings = [warning for warning in self.psbt.warnings if warning[0] in fee_labels]
+ if fee_warnings:
+ for warning in fee_warnings:
+ yield '{}\n\n{}'.format(fee_text, self.render_warning(warning))
else:
- self.goto(self.show_policy_authorization)
+ yield fee_text
+
+ warnings = [warning for warning in self.psbt.warnings if warning[0] not in fee_labels]
+ for index, warning in enumerate(warnings):
+ title = recolor(HIGHLIGHT_TEXT_HEX, 'Warning {}/{}'.format(index + 1, len(warnings)))
+ yield '{}\n\n{}'.format(title, self.render_warning(warning))
async def show_policy_authorization(self):
policy = self.psbt.active_policy
if policy is None:
- self.goto(self.sign_transaction)
+ self.goto(self.sign_transaction, save_curr=False)
return
from policy_display import compatible_path_indexes
@@ -206,6 +188,7 @@ async def show_policy_authorization(self):
'card_header': {'title': 'Policy transaction'},
'text': text,
'centered': True,
+ 'require_scroll_to_end': True,
} for text in texts]
result = await SeriesOfPagesFlow(LongTextPage, page_args).run()
if result:
@@ -228,9 +211,6 @@ async def sign_transaction(self):
question = 'Sign transaction?'
result = await QuestionPage(text=question, right_micron=microns.Sign).show()
if not result:
- options = [{'label': 'Cancel', 'value': True},
- {'label': 'Review Details', 'value': False}]
-
should_cancel = await QuestionPage(text='Cancel this transaction?').show()
if should_cancel:
self.set_result(None)
@@ -274,40 +254,11 @@ def render_output(self, o):
dest)
def render_change_text(self):
- import uio
-
- # Produce text report of what the "change" outputs are (based on our opinion).
- # - we don't really expect all users to verify these outputs, but just in case.
- # - show the total amount, and list addresses
- with uio.StringIO() as msg:
- msg.write('\n{}'.format(recolor(HIGHLIGHT_TEXT_HEX, 'Change Amount')))
- total = 0
- addrs = []
- # print('len(outputs)={}'.format(len(self.psbt.outputs)))
- for idx, tx_out in self.psbt.output_iter():
- outp = self.psbt.outputs[idx]
- if not outp.is_change:
- continue
- # print('idx: {} output:{}'.format(idx, self.chain.render_address(tx_out.scriptPubKey)))
- total += tx_out.nValue
- addrs.append(stylize_address(self.chain.render_address(tx_out.scriptPubKey)))
-
- if len(addrs) == 0:
- msg.write('\nNo change')
- return msg.getvalue()
-
- total_val = ' '.join(self.chain.render_value(total))
-
- msg.write('\n%s\n' % total_val)
-
- if len(addrs) == 1:
- msg.write('\n{}\n{}\n'.format(recolor(HIGHLIGHT_TEXT_HEX, 'Change Address'), addrs[0]))
- else:
- msg.write('\n{}\n'.format(recolor(HIGHLIGHT_TEXT_HEX, 'Change Addresses')))
- for a in addrs:
- msg.write('%s\n\n' % a)
-
- return msg.getvalue()
+ if not any(output.is_change for output in self.psbt.outputs):
+ return 'No change'
+ total = sum(output.nValue for index, output in self.psbt.output_iter() if self.psbt.outputs[index].is_change)
+ amount = ' '.join(self.chain.render_value(total))
+ return '{}\n{}'.format(recolor(HIGHLIGHT_TEXT_HEX, 'Change Amount'), amount)
def invalid_psbt_text(self, exc):
# Labels render with LVGL recolor on, so a literal '#' in the text opens
@@ -316,34 +267,14 @@ def invalid_psbt_text(self, exc):
# the index is the most useful part of them, so escape before display.
return 'Invalid PSBT: {}'.format(escape_text('{}'.format(exc)))
- def render_warnings(self):
- import uio
-
- with uio.StringIO() as msg:
- # # mention warning at top
- # wl = len(self.psbt.warnings)
- # if wl == 1:
- # msg.write('(1 warning below)\n\n')
- # elif wl >= 2:
- # msg.write('(%d warnings below)\n\n' % wl)
-
- # gc.collect()
-
- fee = self.psbt.calculate_fee()
- if not self.psbt.fee_is_verified:
- msg.write('\n{}\nUnverified '.format(recolor(HIGHLIGHT_TEXT_HEX, 'Network Fee')))
- elif fee is not None:
- amount, units = self.chain.render_value(fee)
- msg.write('\n{}\n{} {} '.format(recolor(HIGHLIGHT_TEXT_HEX, 'Network Fee'), amount, units))
-
- # # NEW: show where all the change outputs are going
- # self.render_change_text(msg)
- # gc.collect()
-
- if self.psbt.warnings and len(self.psbt.warnings) > 0:
- msg.write('\n\n{}'.format(recolor(HIGHLIGHT_TEXT_HEX, 'Warnings')))
- for label, m in self.psbt.warnings:
- msg.write('\n{}\n{}\n'.format(recolor(BLACK_HEX, escape_text(label)), escape_text(m)))
- gc.collect()
+ def render_fee(self):
+ fee = self.psbt.calculate_fee()
+ if not self.psbt.fee_is_verified or fee is None:
+ amount = 'Unverified'
+ else:
+ amount = ' '.join(self.chain.render_value(fee))
+ return '{}\n{}'.format(recolor(HIGHLIGHT_TEXT_HEX, 'Network Fee'), amount)
- return msg.getvalue()
+ def render_warning(self, warning):
+ label, message = warning
+ return '{}\n{}'.format(recolor(BLACK_HEX, escape_text(label)), escape_text(message))
### ports/stm32/boards/Passport/modules/pages/long_text_page.py
@@ -23,7 +23,8 @@ def __init__(self,
left_micron=microns.Back,
right_micron=microns.Forward,
margins=None,
- top_margin=None):
+ top_margin=None,
+ require_scroll_to_end=False):
super().__init__(
card_header=card_header,
statusbar=statusbar,
@@ -36,6 +37,11 @@ def __init__(self,
self.centered = centered
self.side_margins = (margins if margins is not None else 12)
self.top_margin = (top_margin if top_margin is not None else 16)
+ self.require_scroll_to_end = require_scroll_to_end
+ self.reviewed = not require_scroll_to_end
+ self.forward_micron = right_micron
+ if require_scroll_to_end:
+ self.right_micron = None
# Set non-style props
self.set_width(lv.pct(100))
@@ -85,6 +91,28 @@ def attach(self, group):
lv.gridnav_add(self.lvgl_root, lv.GRIDNAV_CTRL.NONE)
group.add_obj(self.lvgl_root) # IMPORTANT: Add this to the group AFTER setting up gridnav
+ if self.require_scroll_to_end:
+ self.container.lvgl_root.add_event_cb(self.update_review_status, lv.EVENT.SCROLL, None)
+ self.update_review_status()
+
+ def update_review_status(self, event=None):
+ import common
+
+ if self.reviewed:
+ return
+ self.container.lvgl_root.update_layout()
+ if self.container.lvgl_root.get_scroll_bottom() <= 0:
+ self.reviewed = True
+ self.right_micron = self.forward_micron
+ common.ui.set_right_micron(self.right_micron)
+
+ def right_action(self, is_pressed):
+ if self.require_scroll_to_end:
+ self.update_review_status()
+ super().right_action(is_pressed)
+
def detach(self):
+ if self.require_scroll_to_end:
+ self.container.lvgl_root.remove_event_cb(self.update_review_status)
lv.group_remove_obj(self.lvgl_root)
super().detach()
### ports/stm32/boards/Passport/modules/tests/host/test_wallet_policy_flows.py
@@ -52,6 +52,7 @@ def test_authorization_preserves_path_results(monkeypatch, compatible_sets, expe
class Series:
def __init__(self, page_type, args):
+ assert all(arg['require_scroll_to_end'] for arg in args)
pages.extend(arg['text'] for arg in args)
async def run(self):
### ports/stm32/boards/Passport/modules/tests/test_unit.py
@@ -96,6 +96,10 @@ def test_sign_psbt(test):
assert test('sign_psbt.py') == b'OK'
+def test_transaction_review(test):
+ assert test('transaction_review.py') == b'OK'
+
+
def test_op_return_rendering(test):
assert test('op_return_rendering.py') == b'OK'
### ports/stm32/boards/Passport/modules/tests/unit/one_of_n_warning.py
@@ -3,8 +3,6 @@
#
# Exercise imported PSBT review methods in the standard simulator harness.
-import pages
-import uasyncio as asyncio
from psbt import psbtObject
from serializations import CTxOut
from flows.sign_psbt_common_flow import SignPsbtCommonFlow
@@ -56,22 +54,14 @@ class MockChain:
def render_value(self, value):
return str(value), 'sats'
+ def render_address(self, script):
+ return 'bc1qtest'
-class MockFlow:
- chain = MockChain()
- header = 'Transaction Info'
- show_policy_authorization = 'authorize'
- render_warnings = SignPsbtCommonFlow.render_warnings
+class MockFlow(SignPsbtCommonFlow):
def __init__(self, psbt):
self.psbt = psbt
- self.events = []
-
- def back(self):
- self.events.append('back')
-
- def goto(self, state):
- self.events.append(state)
+ self.chain = MockChain()
# None means there is no change output at all; zero retains a zero-value one.
@@ -91,41 +81,14 @@ def goto(self, state):
expected = policy is not None and policy[0] == 1 and policy[1] > 1
assert len(psbt.warnings) == int(expected)
if expected:
- text = MockFlow(psbt).render_warnings()
+ review = list(MockFlow(psbt).review_pages())
+ text = review[-1]
+ assert 'Network Fee' not in text
+ assert sum('Any other cosigner' in page for page in review) == 1
assert '1-of-{} Multisig'.format(policy[1]) in text
assert 'Any other cosigner can spend' in text
assert 'including change' in text
assert 'without approval from this wallet' in text
-class MockPage:
- approve = False
- flow = None
-
- def __init__(self, text, **kwargs):
- assert text == self.flow.render_warnings()
- assert '1-of-2 Multisig' in text
-
- async def show(self):
- self.flow.events.append('review')
- return self.approve
-
-
-async def run_tests():
- original_page = pages.LongTextPage
- try:
- pages.LongTextPage = MockPage
- for approve in (False, True):
- psbt = MockPSBT((1, 2), None)
- psbtObject.consider_outputs(psbt)
- flow = MockFlow(psbt)
- MockPage.flow = flow
- MockPage.approve = approve
- await SignPsbtCommonFlow.show_warnings(flow)
- assert flow.events == ['review', 'authorize' if approve else 'back']
- finally:
- pages.LongTextPage = original_page
-
-
-asyncio.run(run_tests())
return_value.write(b'OK')
### ports/stm32/boards/Passport/modules/tests/unit/psbt_fee.py
@@ -234,11 +234,11 @@ def __init__(self, psbt):
self.psbt = psbt
-review = SignPsbtCommonFlow.render_warnings(MockFlow(unverified_fee_psbt))
+review = SignPsbtCommonFlow.render_fee(MockFlow(unverified_fee_psbt))
assert 'Unverified' in review
assert '4000 sats' not in review
-review = SignPsbtCommonFlow.render_warnings(MockFlow(verified_fee_psbt))
+review = SignPsbtCommonFlow.render_fee(MockFlow(verified_fee_psbt))
assert '4000 sats' in review
return_value.write(b'OK')
### ports/stm32/boards/Passport/modules/tests/unit/transaction_review.py
@@ -0,0 +1,258 @@
+# SPDX-FileCopyrightText: 2026 Foundation Devices, Inc. <hello@foundation.xyz>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+import common
+import lvgl as lv
+import microns
+import pages
+import uasyncio as asyncio
+from display import Display
+from flows.sign_psbt_common_flow import SignPsbtCommonFlow
+from pages.long_text_page import LongTextPage
+from psbt import psbtOutputProxy
+from serializations import CTxOut
+from styles.colors import HIGHLIGHT_TEXT_HEX
+from uio import BytesIO
+from utils import escape_text, recolor, stylize_address
+
+
+class Transaction:
+ active_policy = None
+ fee_is_verified = True
+
+ def __init__(self, changes=(None, True, None, True), self_send=False, warnings=()):
+ self.outputs = []
+ for index, change in enumerate(changes):
+ output = psbtOutputProxy(BytesIO(b'\x00'), index)
+ if change is not None:
+ output.is_change = change
+ self.outputs.append(output)
+ self.self_send = self_send
+ self.warnings = warnings
+
+ def output_iter(self):
+ output = CTxOut()
+ for index in range(len(self.outputs)):
+ output.nValue = index + 1
+ output.scriptPubKey = 'destination-{}'.format(index)
+ yield index, output
+
+ def calculate_fee(self):
+ return 42
+
+
+class Chain:
+ def render_value(self, value):
+ return str(value), 'sats'
+
+ def render_address(self, script):
+ return script
+
+
+class ReviewFlow(SignPsbtCommonFlow):
+ def __init__(self, transaction):
+ original_settings = common.settings
+ common.settings = {}
+ try:
+ super().__init__(0)
+ finally:
+ common.settings = original_settings
+ self.psbt = transaction
+ self.chain = Chain()
+ self.state = self.show_transaction_details
+ self.signed = False
+
+ async def sign_transaction(self):
+ self.signed = True
+ self.set_result('signed')
+
+
+class ReviewPage:
+ texts = []
+ responses = []
+
+ def __init__(self, text, **kwargs):
+ assert kwargs['require_scroll_to_end']
+ self.texts.append(text)
+
+ async def show(self):
+ assert self.responses, 'Unexpected review page'
+ return self.responses.pop(0)
+
+
+class ErrorPage:
+ errors = []
+
+ def __init__(self, text):
+ self.errors.append(text)
+
+ async def show(self):
+ return True
+
+
+class QuestionPage:
+ questions = []
+
+ def __init__(self, text, **kwargs):
+ self.questions.append(text)
+
+ async def show(self):
+ return False
+
+
+def render(transaction):
+ return list(ReviewFlow(transaction).review_pages())
+
+
+warnings = [('Big Fee', 'Large fee'), ('Suspicious Change Outputs', 'Output #1: unusual path'),
+ ('1-of-2 Multisig', 'Any other cosigner can spend'), ('Other #warning', '#ff0000 message#')]
+transaction = Transaction(warnings=warnings)
+texts = render(transaction)
+destinations = [stylize_address('destination-{}'.format(index)) for index in range(4)]
+assert len(texts) == 9
+assert texts[0].startswith(recolor(HIGHLIGHT_TEXT_HEX, 'Output 1/2')) and destinations[0] in texts[0]
+assert texts[1].startswith(recolor(HIGHLIGHT_TEXT_HEX, 'Output 2/2')) and destinations[2] in texts[1]
+assert 'Change Amount' in texts[2] and '6 sats' in texts[2]
+assert texts[3].startswith(recolor(HIGHLIGHT_TEXT_HEX, 'Change 1/2')) and destinations[1] in texts[3]
+assert texts[4].startswith(recolor(HIGHLIGHT_TEXT_HEX, 'Change 2/2')) and destinations[3] in texts[4]
+assert 'Network Fee' in texts[5] and '42 sats' in texts[5] and 'Big Fee' in texts[5]
+assert 'Suspicious Change Outputs' in texts[6] and 'Output ##1' in texts[6]
+assert '1-of-2 Multisig' in texts[7]
+assert escape_text('Other #warning') in texts[8] and escape_text('#ff0000 message#') in texts[8]
+for index in range(3):
+ assert texts[6 + index].startswith(recolor(HIGHLIGHT_TEXT_HEX, 'Warning {}/3'.format(index + 1)))
+assert all(sum(destination in text for destination in destinations) <= 1 for text in texts)
+for label in ('Big Fee', 'Huge Fee', 'Unverified Fee'):
+ fee_transaction = Transaction(changes=(False,), warnings=[(label, 'Fee warning')])
+ fee_transaction.fee_is_verified = label != 'Unverified Fee'
+ fee_page = render(fee_transaction)[-1]
+ assert 'Network Fee' in fee_page and label in fee_page
+ assert ('42 sats' in fee_page) == fee_transaction.fee_is_verified
+ assert ('Unverified' in fee_page) != fee_transaction.fee_is_verified
+
+self_send = render(Transaction(changes=(True, True), self_send=True))
+assert len(self_send) == 3
+assert self_send[0].startswith(recolor(HIGHLIGHT_TEXT_HEX, 'Self-Send 1/2'))
+assert self_send[1].startswith(recolor(HIGHLIGHT_TEXT_HEX, 'Self-Send 2/2'))
+assert destinations[0] in self_send[0] and destinations[1] in self_send[1]
+assert len(render(Transaction(changes=(False,)))) == 3
+assert render(Transaction(changes=(False,)))[1] == 'No change'
+
+
+async def run_flow_tests():
+ original_page, original_error = pages.LongTextPage, pages.ErrorPage
+ original_question = pages.QuestionPage
+ pages.LongTextPage, pages.ErrorPage = ReviewPage, ErrorPage
+ pages.QuestionPage = QuestionPage
+ try:
+ for stop in range(len(texts)):
+ flow = ReviewFlow(transaction)
+ ReviewPage.texts, ReviewPage.responses = [], [True] * stop + [None]
+ assert await flow.run() is None
+ assert not flow.signed
+ assert ReviewPage.texts == texts[:stop + 1]
+
+ for stop in range(len(texts)):
+ flow = ReviewFlow(transaction)
+ ReviewPage.texts = []
+ ReviewPage.responses = [True] * stop + [False] * (stop + 1)
+ assert await flow.run() is None
+ assert not flow.signed
+ assert ReviewPage.texts == texts[:stop + 1] + list(reversed(texts[:stop]))
+
+ flow = ReviewFlow(transaction)
+ ReviewPage.texts = []
+ ReviewPage.responses = [True, True, False] + [True] * (len(texts) - 1)
+ assert await flow.run() == 'signed'
+ assert flow.signed
+ assert ReviewPage.texts == texts[:3] + texts[1:]
+ assert not ReviewPage.responses
+
+ # Declining cancellation must return to review without requesting a signature.
+ flow.done = False
+ flow.signed = False
+ await SignPsbtCommonFlow.sign_transaction(flow)
+ assert QuestionPage.questions == ['Sign transaction?', 'Cancel this transaction?']
+ ReviewPage.texts, ReviewPage.responses = [], [False, None]
+ assert await flow.run() is None
+ assert ReviewPage.texts == texts[-1:] + texts[-2:-1]
+ assert not flow.signed
+
+ for case in (Transaction(changes=(True, True), self_send=True),
+ Transaction(changes=(False,)),
+ Transaction(changes=(None,)),
+ Transaction(changes=(None, False, True), warnings=warnings),
+ Transaction(changes=(None,) * 100, warnings=warnings)):
+ expected = render(case)
+ flow = ReviewFlow(case)
+ ReviewPage.texts, ReviewPage.responses = [], [True] * len(expected)
+ assert await flow.run() == 'signed'
+ assert ReviewPage.texts == expected
+ assert not ErrorPage.errors
+ finally:
+ pages.LongTextPage, pages.ErrorPage = original_page, original_error
+ pages.QuestionPage = original_question
+
+
+class ReviewUI:
+ def set_left_micron(self, micron):
+ pass
+
+ def set_right_micron(self, micron):
+ self.right_micron = micron
+
+
+class Keypad:
+ def set_active_page(self, page):
+ pass
+
+
+def test_scroll_gate():
+ Display()
+ original_ui, original_keypad = common.ui, common.keypad
+ common.ui, common.keypad = ReviewUI(), Keypad()
+ parent = lv.obj(lv.scr_act())
+ parent.set_size(230, 220)
+ parent.set_style_pad_all(0, 0)
+ parent.set_flex_flow(lv.FLEX_FLOW.COLUMN)
+ group = lv.group_create()
+ try:
+ for text, overflow in (('Short text', False), ('Long warning\n' * 50, True)):
+ page = LongTextPage(text=text, require_scroll_to_end=True)
+ page.mount(parent)
+ page.attach(group)
+ container = page.container.lvgl_root
+ assert (container.get_scroll_bottom() > 0) == overflow
+ assert (common.ui.right_micron is None) == overflow
+ page.right_action(True)
+ assert not page.done
+ page.right_action(False)
+ assert page.done != overflow
+ if overflow:
+ container.scroll_to_y(container.get_scroll_bottom() // 2, lv.ANIM.OFF)
+ page.right_action(False)
+ assert not page.done
+ container.scroll_to_y(container.get_scroll_y() + container.get_scroll_bottom(), lv.ANIM.OFF)
+ assert common.ui.right_micron == microns.Forward
+ container.scroll_to_y(0, lv.ANIM.OFF)
+ page.right_action(False)
+ assert page.done and page.result is True
+ page.detach()
+ page.unmount()
+
+ page = LongTextPage(text='Long warning\n' * 50)
+ page.mount(parent)
+ page.attach(group)
+ page.right_action(False)
+ assert page.done and page.result is True
+ page.detach()
+ page.unmount()
+ finally:
+ parent.delete()
+ group._del()
+ common.ui, common.keypad = original_ui, original_keypad
+
+
+asyncio.run(run_flow_tests())
+test_scroll_gate()
+return_value.write(b'OK')Why this scored 29/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.