Skip to content

Commit

Permalink
Tests: update with latest change
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Apr 17, 2024
1 parent 481d776 commit 808370b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 42 deletions.
34 changes: 26 additions & 8 deletions ragger_bitcoin/ragger_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 45 additions & 32 deletions tests/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down Expand Up @@ -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


Expand All @@ -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

Expand All @@ -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

Expand All @@ -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


Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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


Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/test_sign_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sign_psbt_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 808370b

Please sign in to comment.