From 530bc80c40777172eba0a006ac6c367eaf6d49e3 Mon Sep 17 00:00:00 2001 From: Sarah GLINER Date: Thu, 11 Apr 2024 11:32:43 +0200 Subject: [PATCH] Tests: update with latest change --- ragger_bitcoin/ragger_instructions.py | 34 +++++++++--- tests/instructions.py | 77 ++++++++++++++++----------- tests/test_sign_psbt.py | 2 +- tests/test_sign_psbt_v1.py | 2 +- 4 files changed, 73 insertions(+), 42 deletions(-) diff --git a/ragger_bitcoin/ragger_instructions.py b/ragger_bitcoin/ragger_instructions.py index 08e157d2b..956802d2c 100644 --- a/ragger_bitcoin/ragger_instructions.py +++ b/ragger_bitcoin/ragger_instructions.py @@ -42,34 +42,52 @@ def navigate_end_of_flow(self, save_screenshot=True): self.new_request("Processing", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot) - def confirm_transaction(self, save_screenshot=True): - self.new_request("Sign", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_CONFIRM, + def review_start(self, output_count: int = 1, save_screenshot=True): + self.new_request("Review", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot) - self.new_request("TRANSACTION", NavInsID.USE_CASE_REVIEW_TAP, - NavInsID.USE_CASE_STATUS_DISMISS, + for _ in range(0, output_count): + self.new_request("Amount", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, + save_screenshot=save_screenshot) + def review_fees(self, fees_on_same_request: bool = True, save_screenshot=True): + if fees_on_same_request: + self.same_request("Fees", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, + save_screenshot=save_screenshot) + else: + self.new_request("Fees", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot) - def same_request_confirm_transaction(self, save_screenshot=True): + def confirm_transaction(self, save_screenshot=True): self.same_request("Sign", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_CONFIRM, save_screenshot=save_screenshot) self.new_request("TRANSACTION", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_STATUS_DISMISS, save_screenshot=save_screenshot) + def review_message(self, page_count=1, save_screenshot=True): + self.new_request("Review", NavInsID.USE_CASE_REVIEW_TAP, + NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot) + self.same_request("Message", NavInsID.USE_CASE_REVIEW_TAP, + NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot) + for _ in range(1, page_count): + self.new_request("Message", NavInsID.USE_CASE_REVIEW_TAP, + NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot) + def confirm_message(self, save_screenshot=True): - self.new_request("Sign", NavInsID.USE_CASE_REVIEW_TAP, + self.same_request("Sign", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_CONFIRM, save_screenshot=save_screenshot) self.new_request("MESSAGE", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_STATUS_DISMISS, save_screenshot=save_screenshot) def confirm_wallet(self, save_screenshot=True): - self.new_request("Approve", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_CONFIRM, + self.new_request("Approve", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_CHOICE_CONFIRM, save_screenshot=save_screenshot) self.same_request("WALLET", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_STATUS_DISMISS, save_screenshot=save_screenshot) def reject_message(self, save_screenshot=True): - self.new_request("Sign", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_REJECT, + self.new_request("Review", NavInsID.USE_CASE_REVIEW_TAP, + NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot) + self.same_request("Message", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_REJECT, save_screenshot=save_screenshot) self.same_request("Reject", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_CHOICE_CONFIRM, save_screenshot=save_screenshot) diff --git a/tests/instructions.py b/tests/instructions.py index ad0711b3c..fe428ca80 100644 --- a/tests/instructions.py +++ b/tests/instructions.py @@ -11,7 +11,9 @@ def message_instruction_approve(model: Firmware) -> Instructions: instructions.nano_skip_screen("Path") instructions.same_request("Sign") else: + instructions.review_message() instructions.confirm_message() + return instructions @@ -26,10 +28,7 @@ def message_instruction_approve_long(model: Firmware) -> Instructions: instructions.new_request("Processing") instructions.new_request("Sign") else: - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_message(page_count=5) instructions.confirm_message() return instructions @@ -146,7 +145,21 @@ def sign_psbt_instruction_tap(model: Firmware) -> Instructions: if model.name.startswith("nano"): return instructions - instructions.navigate_end_of_flow() + instructions.review_start() + return instructions + + +def sign_psbt_instruction_approve_opreturn(model: Firmware) -> Instructions: + instructions = Instructions(model) + + if model.name.startswith("nano"): + instructions.new_request("Continue") + instructions.new_request("Sign") + else: + instructions.review_start() + instructions.same_request("Address", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP) + instructions.review_fees(fees_on_same_request=False) + instructions.confirm_transaction() return instructions @@ -157,7 +170,8 @@ def sign_psbt_instruction_approve(model: Firmware) -> Instructions: instructions.new_request("Continue") instructions.same_request("Sign") else: - instructions.navigate_end_of_flow() + instructions.review_start() + instructions.review_fees() instructions.confirm_transaction() return instructions @@ -169,8 +183,8 @@ def sign_psbt_instruction_approve_2(model: Firmware) -> Instructions: instructions.new_request("Continue") instructions.new_request("Sign") else: - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_start() + instructions.review_fees(fees_on_same_request=False) instructions.confirm_transaction() return instructions @@ -183,10 +197,10 @@ def sign_psbt_instruction_approve_3(model: Firmware) -> Instructions: instructions.new_request("Continue") instructions.same_request("Sign") else: - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_start() instructions.warning_accept() - instructions.same_request_confirm_transaction() + instructions.review_fees() + instructions.confirm_transaction() return instructions @@ -199,7 +213,8 @@ def sign_psbt_instruction_approve_4(model: Firmware) -> Instructions: instructions.same_request("Sign") else: instructions.warning_accept() - instructions.navigate_end_of_flow() + instructions.review_start() + instructions.review_fees() instructions.confirm_transaction() return instructions @@ -210,7 +225,7 @@ def sign_psbt_instruction_approve_5(model: Firmware) -> Instructions: if model.name.startswith("nano"): instructions.new_request("Sign") else: - instructions.navigate_end_of_flow() + instructions.review_start() instructions.confirm_transaction() return instructions @@ -224,8 +239,8 @@ def sign_psbt_instruction_approve_6(model: Firmware) -> Instructions: instructions.new_request("Sign") else: instructions.confirm_wallet() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_start() + instructions.review_fees(fees_on_same_request=False) instructions.confirm_transaction() return instructions @@ -239,7 +254,8 @@ def sign_psbt_instruction_approve_7(model: Firmware) -> Instructions: instructions.same_request("Sign") else: instructions.confirm_wallet() - instructions.navigate_end_of_flow() + instructions.review_start() + instructions.review_fees() instructions.confirm_transaction() return instructions @@ -255,7 +271,8 @@ def sign_psbt_instruction_approve_8(model: Firmware) -> Instructions: else: instructions.confirm_wallet() instructions.warning_accept() - instructions.navigate_end_of_flow() + instructions.review_start() + instructions.review_fees() instructions.confirm_transaction() return instructions @@ -268,8 +285,8 @@ def sign_psbt_instruction_approve_9(model: Firmware) -> Instructions: instructions.new_request("Continue") instructions.same_request("Sign") else: - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_start(output_count=2) + instructions.review_fees() instructions.confirm_transaction() return instructions @@ -287,11 +304,8 @@ def sign_psbt_instruction_approve_external_inputs(model: Firmware) -> Instructio instructions.same_request("Sign") else: instructions.warning_accept() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_start(output_count=5) + instructions.review_fees() instructions.confirm_transaction() return instructions @@ -308,10 +322,8 @@ def sign_psbt_instruction_approve_external_inputs_2(model: Firmware) -> Instruct instructions.same_request("Sign") else: instructions.warning_accept() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_start(output_count=4) + instructions.review_fees() instructions.confirm_transaction() return instructions @@ -325,8 +337,8 @@ def sign_psbt_instruction_approve_10(model: Firmware) -> Instructions: instructions.new_request("Sign") else: instructions.warning_accept() - instructions.navigate_end_of_flow() - instructions.navigate_end_of_flow() + instructions.review_start() + instructions.review_fees(fees_on_same_request=False) instructions.confirm_transaction() return instructions @@ -340,6 +352,7 @@ def e2e_register_wallet_instruction(model: Firmware, n_keys) -> Instructions: else: for _ in range(n_keys + 1): instructions.choice_confirm(save_screenshot=False) + instructions.choice_confirm(save_screenshot=False) return instructions @@ -352,7 +365,7 @@ def e2e_sign_psbt_instruction(model: Firmware) -> Instructions: instructions.new_request("Sign", save_screenshot=False) else: instructions.confirm_wallet(save_screenshot=False) - instructions.navigate_end_of_flow(save_screenshot=False) - instructions.navigate_end_of_flow(save_screenshot=False) + instructions.review_start(save_screenshot=False) + instructions.review_fees(fees_on_same_request=False, save_screenshot=False) instructions.confirm_transaction(save_screenshot=False) return instructions diff --git a/tests/test_sign_psbt.py b/tests/test_sign_psbt.py index 089634949..e5a77d3c8 100644 --- a/tests/test_sign_psbt.py +++ b/tests/test_sign_psbt.py @@ -701,7 +701,7 @@ def test_sign_psbt_with_opreturn(navigator: Navigator, firmware: Firmware, clien psbt.deserialize(psbt_b64) hww_sigs = client.sign_psbt(psbt, wallet, None, navigator, - instructions=sign_psbt_instruction_approve_2(firmware), + instructions=sign_psbt_instruction_approve_opreturn(firmware), testname=test_name) assert len(hww_sigs) == 1 diff --git a/tests/test_sign_psbt_v1.py b/tests/test_sign_psbt_v1.py index f8af8c5c5..aa3afce09 100644 --- a/tests/test_sign_psbt_v1.py +++ b/tests/test_sign_psbt_v1.py @@ -448,7 +448,7 @@ def test_sign_psbt_with_opreturn_v1(navigator: Navigator, firmware: Firmware, cl psbt.deserialize(psbt_b64) hww_sigs = client.sign_psbt(psbt, wallet, None, navigator, - instructions=sign_psbt_instruction_approve_2(firmware), + instructions=sign_psbt_instruction_approve_opreturn(firmware), testname=test_name) assert len(hww_sigs) == 1