-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stack usage optim : use slices, not arrays in Tx struct.
Code cleanup.
- Loading branch information
1 parent
ee1e3c8
commit aa56193
Showing
68 changed files
with
152 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-21 Bytes
(96%)
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-48 Bytes
(91%)
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-83 Bytes
(84%)
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-207 Bytes
(62%)
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-80 Bytes
(85%)
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-535 Bytes
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00006.png
Binary file not shown.
Binary file removed
BIN
-500 Bytes
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00007.png
Binary file not shown.
Binary file removed
BIN
-413 Bytes
tests/snapshots/nanos/test_get_public_key_confirm_accepted/00008.png
Binary file not shown.
Binary file modified
BIN
-21 Bytes
(96%)
tests/snapshots/nanos/test_get_public_key_confirm_refused/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-48 Bytes
(91%)
tests/snapshots/nanos/test_get_public_key_confirm_refused/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-83 Bytes
(84%)
tests/snapshots/nanos/test_get_public_key_confirm_refused/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-207 Bytes
(62%)
tests/snapshots/nanos/test_get_public_key_confirm_refused/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-195 Bytes
(64%)
tests/snapshots/nanos/test_get_public_key_confirm_refused/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-80 Bytes
(85%)
tests/snapshots/nanos/test_get_public_key_confirm_refused/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-500 Bytes
tests/snapshots/nanos/test_get_public_key_confirm_refused/00007.png
Binary file not shown.
Binary file removed
BIN
-413 Bytes
tests/snapshots/nanos/test_get_public_key_confirm_refused/00008.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,141 +1,142 @@ | ||
# import pytest | ||
|
||
# from application_client.boilerplate_transaction import Transaction | ||
# from application_client.boilerplate_command_sender import BoilerplateCommandSender, Errors | ||
# from application_client.boilerplate_response_unpacker import unpack_get_public_key_response, unpack_sign_tx_response | ||
# from ragger.error import ExceptionRAPDU | ||
# from ragger.navigator import NavInsID | ||
# from utils import ROOT_SCREENSHOT_PATH, check_signature_validity | ||
|
||
# # In this tests we check the behavior of the device when asked to sign a transaction | ||
|
||
|
||
# # In this test se send to the device a transaction to sign and validate it on screen | ||
# # The transaction is short and will be sent in one chunk | ||
# # We will ensure that the displayed information is correct by using screenshots comparison | ||
# def test_sign_tx_short_tx(firmware, backend, navigator, test_name): | ||
# # Use the app interface instead of raw interface | ||
# client = BoilerplateCommandSender(backend) | ||
# # The path used for this entire test | ||
# path: str = "m/44'/1'/0'/0/0" | ||
|
||
# # First we need to get the public key of the device in order to build the transaction | ||
# rapdu = client.get_public_key(path=path) | ||
# _, public_key, _, _ = unpack_get_public_key_response(rapdu.data) | ||
|
||
# # Create the transaction that will be sent to the device for signing | ||
# transaction = Transaction( | ||
# nonce=1, | ||
# to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", | ||
# value=666, | ||
# memo="For u EthDev" | ||
# ).serialize() | ||
|
||
# # Send the sign device instruction. | ||
# # As it requires on-screen validation, the function is asynchronous. | ||
# # It will yield the result when the navigation is done | ||
# with client.sign_tx(path=path, transaction=transaction): | ||
# # Validate the on-screen request by performing the navigation appropriate for this device | ||
# if firmware.device.startswith("nano"): | ||
# navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK, | ||
# [NavInsID.BOTH_CLICK], | ||
# "Approve", | ||
# ROOT_SCREENSHOT_PATH, | ||
# test_name) | ||
# else: | ||
# navigator.navigate_until_text_and_compare(NavInsID.USE_CASE_REVIEW_TAP, | ||
# [NavInsID.USE_CASE_REVIEW_CONFIRM, | ||
# NavInsID.USE_CASE_STATUS_DISMISS], | ||
# "Hold to sign", | ||
# ROOT_SCREENSHOT_PATH, | ||
# test_name) | ||
|
||
# # The device as yielded the result, parse it and ensure that the signature is correct | ||
# response = client.get_async_response().data | ||
# _, der_sig, _ = unpack_sign_tx_response(response) | ||
# assert check_signature_validity(public_key, der_sig, transaction) | ||
|
||
|
||
# # In this test se send to the device a transaction to sign and validate it on screen | ||
# # This test is mostly the same as the previous one but with different values. | ||
# # In particular the long memo will force the transaction to be sent in multiple chunks | ||
# def test_sign_tx_long_tx(firmware, backend, navigator, test_name): | ||
# # Use the app interface instead of raw interface | ||
# client = BoilerplateCommandSender(backend) | ||
# path: str = "m/44'/1'/0'/0/0" | ||
|
||
# rapdu = client.get_public_key(path=path) | ||
# _, public_key, _, _ = unpack_get_public_key_response(rapdu.data) | ||
|
||
# transaction = Transaction( | ||
# nonce=1, | ||
# to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", | ||
# value=666, | ||
# memo=("This is a very long memo. " | ||
# "It will force the app client to send the serialized transaction to be sent in chunk. " | ||
# "As the maximum chunk size is 255 bytes we will make this memo greater than 255 characters. " | ||
# "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam.") | ||
# ).serialize() | ||
|
||
# with client.sign_tx(path=path, transaction=transaction): | ||
# if firmware.device.startswith("nano"): | ||
# navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK, | ||
# [NavInsID.BOTH_CLICK], | ||
# "Approve", | ||
# ROOT_SCREENSHOT_PATH, | ||
# test_name) | ||
# else: | ||
# navigator.navigate_until_text_and_compare(NavInsID.USE_CASE_REVIEW_TAP, | ||
# [NavInsID.USE_CASE_REVIEW_CONFIRM, | ||
# NavInsID.USE_CASE_STATUS_DISMISS], | ||
# "Hold to sign", | ||
# ROOT_SCREENSHOT_PATH, | ||
# test_name) | ||
# response = client.get_async_response().data | ||
# _, der_sig, _ = unpack_sign_tx_response(response) | ||
# assert check_signature_validity(public_key, der_sig, transaction) | ||
|
||
|
||
# # Transaction signature refused test | ||
# # The test will ask for a transaction signature that will be refused on screen | ||
# def test_sign_tx_refused(firmware, backend, navigator, test_name): | ||
# # Use the app interface instead of raw interface | ||
# client = BoilerplateCommandSender(backend) | ||
# path: str = "m/44'/1'/0'/0/0" | ||
|
||
# rapdu = client.get_public_key(path=path) | ||
# _, pub_key, _, _ = unpack_get_public_key_response(rapdu.data) | ||
|
||
# transaction = Transaction( | ||
# nonce=1, | ||
# to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", | ||
# value=666, | ||
# memo="This transaction will be refused by the user" | ||
# ).serialize() | ||
|
||
# if firmware.device.startswith("nano"): | ||
# with pytest.raises(ExceptionRAPDU) as e: | ||
# with client.sign_tx(path=path, transaction=transaction): | ||
# navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK, | ||
# [NavInsID.BOTH_CLICK], | ||
# "Reject", | ||
# ROOT_SCREENSHOT_PATH, | ||
# test_name) | ||
|
||
# # Assert that we have received a refusal | ||
# assert e.value.status == Errors.SW_DENY | ||
# assert len(e.value.data) == 0 | ||
# else: | ||
# for i in range(3): | ||
# instructions = [NavInsID.USE_CASE_REVIEW_TAP] * i | ||
# instructions += [NavInsID.USE_CASE_REVIEW_REJECT, | ||
# NavInsID.USE_CASE_CHOICE_CONFIRM, | ||
# NavInsID.USE_CASE_STATUS_DISMISS] | ||
# with pytest.raises(ExceptionRAPDU) as e: | ||
# with client.sign_tx(path=path, transaction=transaction): | ||
# navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, | ||
# test_name + f"/part{i}", | ||
# instructions) | ||
# # Assert that we have received a refusal | ||
# assert e.value.status == Errors.SW_DENY | ||
# assert len(e.value.data) == 0 | ||
import pytest | ||
|
||
from application_client.boilerplate_transaction import Transaction | ||
from application_client.boilerplate_command_sender import BoilerplateCommandSender, Errors | ||
from application_client.boilerplate_response_unpacker import unpack_get_public_key_response, unpack_sign_tx_response | ||
from ragger.error import ExceptionRAPDU | ||
from ragger.navigator import NavInsID | ||
from utils import ROOT_SCREENSHOT_PATH, check_signature_validity | ||
|
||
# In this tests we check the behavior of the device when asked to sign a transaction | ||
|
||
|
||
# In this test se send to the device a transaction to sign and validate it on screen | ||
# The transaction is short and will be sent in one chunk | ||
# We will ensure that the displayed information is correct by using screenshots comparison | ||
def test_sign_tx_short_tx(firmware, backend, navigator, test_name): | ||
# Use the app interface instead of raw interface | ||
client = BoilerplateCommandSender(backend) | ||
# The path used for this entire test | ||
path: str = "m/44'/1'/0'/0/0" | ||
|
||
# First we need to get the public key of the device in order to build the transaction | ||
rapdu = client.get_public_key(path=path) | ||
_, public_key, _, _ = unpack_get_public_key_response(rapdu.data) | ||
|
||
# Create the transaction that will be sent to the device for signing | ||
transaction = Transaction( | ||
nonce=1, | ||
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", | ||
value=666, | ||
memo="For u EthDev" | ||
).serialize() | ||
|
||
# Send the sign device instruction. | ||
# As it requires on-screen validation, the function is asynchronous. | ||
# It will yield the result when the navigation is done | ||
with client.sign_tx(path=path, transaction=transaction): | ||
# Validate the on-screen request by performing the navigation appropriate for this device | ||
if firmware.device.startswith("nano"): | ||
navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK, | ||
[NavInsID.BOTH_CLICK], | ||
"Approve", | ||
ROOT_SCREENSHOT_PATH, | ||
test_name) | ||
else: | ||
navigator.navigate_until_text_and_compare(NavInsID.USE_CASE_REVIEW_TAP, | ||
[NavInsID.USE_CASE_REVIEW_CONFIRM, | ||
NavInsID.USE_CASE_STATUS_DISMISS], | ||
"Hold to sign", | ||
ROOT_SCREENSHOT_PATH, | ||
test_name) | ||
|
||
# The device as yielded the result, parse it and ensure that the signature is correct | ||
response = client.get_async_response().data | ||
_, der_sig, _ = unpack_sign_tx_response(response) | ||
|
||
assert check_signature_validity(public_key, der_sig, transaction) | ||
|
||
|
||
# In this test se send to the device a transaction to sign and validate it on screen | ||
# This test is mostly the same as the previous one but with different values. | ||
# In particular the long memo will force the transaction to be sent in multiple chunks | ||
def test_sign_tx_long_tx(firmware, backend, navigator, test_name): | ||
# Use the app interface instead of raw interface | ||
client = BoilerplateCommandSender(backend) | ||
path: str = "m/44'/1'/0'/0/0" | ||
|
||
rapdu = client.get_public_key(path=path) | ||
_, public_key, _, _ = unpack_get_public_key_response(rapdu.data) | ||
|
||
transaction = Transaction( | ||
nonce=1, | ||
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", | ||
value=666, | ||
memo=("This is a very long memo. " | ||
"It will force the app client to send the serialized transaction to be sent in chunk. " | ||
"As the maximum chunk size is 255 bytes we will make this memo greater than 255 characters. " | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam.") | ||
).serialize() | ||
|
||
with client.sign_tx(path=path, transaction=transaction): | ||
if firmware.device.startswith("nano"): | ||
navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK, | ||
[NavInsID.BOTH_CLICK], | ||
"Approve", | ||
ROOT_SCREENSHOT_PATH, | ||
test_name) | ||
else: | ||
navigator.navigate_until_text_and_compare(NavInsID.USE_CASE_REVIEW_TAP, | ||
[NavInsID.USE_CASE_REVIEW_CONFIRM, | ||
NavInsID.USE_CASE_STATUS_DISMISS], | ||
"Hold to sign", | ||
ROOT_SCREENSHOT_PATH, | ||
test_name) | ||
response = client.get_async_response().data | ||
_, der_sig, _ = unpack_sign_tx_response(response) | ||
assert check_signature_validity(public_key, der_sig, transaction) | ||
|
||
|
||
# Transaction signature refused test | ||
# The test will ask for a transaction signature that will be refused on screen | ||
def test_sign_tx_refused(firmware, backend, navigator, test_name): | ||
# Use the app interface instead of raw interface | ||
client = BoilerplateCommandSender(backend) | ||
path: str = "m/44'/1'/0'/0/0" | ||
|
||
rapdu = client.get_public_key(path=path) | ||
_, pub_key, _, _ = unpack_get_public_key_response(rapdu.data) | ||
|
||
transaction = Transaction( | ||
nonce=1, | ||
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", | ||
value=666, | ||
memo="This transaction will be refused by the user" | ||
).serialize() | ||
|
||
if firmware.device.startswith("nano"): | ||
with pytest.raises(ExceptionRAPDU) as e: | ||
with client.sign_tx(path=path, transaction=transaction): | ||
navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK, | ||
[NavInsID.BOTH_CLICK], | ||
"Reject", | ||
ROOT_SCREENSHOT_PATH, | ||
test_name) | ||
|
||
# Assert that we have received a refusal | ||
assert e.value.status == Errors.SW_DENY | ||
assert len(e.value.data) == 0 | ||
else: | ||
for i in range(3): | ||
instructions = [NavInsID.USE_CASE_REVIEW_TAP] * i | ||
instructions += [NavInsID.USE_CASE_REVIEW_REJECT, | ||
NavInsID.USE_CASE_CHOICE_CONFIRM, | ||
NavInsID.USE_CASE_STATUS_DISMISS] | ||
with pytest.raises(ExceptionRAPDU) as e: | ||
with client.sign_tx(path=path, transaction=transaction): | ||
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, | ||
test_name + f"/part{i}", | ||
instructions) | ||
# Assert that we have received a refusal | ||
assert e.value.status == Errors.SW_DENY | ||
assert len(e.value.data) == 0 |