Skip to content

Commit

Permalink
test: implement message signing test
Browse files Browse the repository at this point in the history
- Update sign_message test with new payload and signature
- Modify command sender to simplify message signing method
- Add screenshot navigation for cross-device testing
- Remove account number and wallet type from signing flow
- Add snapshot images for NanoSP and NanoX devices
  • Loading branch information
keiff3r committed Feb 12, 2025
1 parent 75152dd commit 8f7908a
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/application_client/everscale_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ def get_address_with_confirmation(self, account_number: int, wallet_type: Wallet


@contextmanager
def sign_message(self, account_number: int, wallet_type: WalletType, message: bytes) -> Generator[None, None, None]:
def sign_message(self, payload: bytes) -> Generator[None, None, None]:
with self.backend.exchange_async(cla=CLA,
ins=InsType.SIGN_MESSAGE,
p1=P1.P1_CONFIRM,
p2=P2.P2_LAST,
data=account_number.to_bytes(4, "big") + wallet_type.to_bytes(1, "big") + message) as response:
data=payload) as response:
yield response

@contextmanager
Expand Down
Binary file added tests/snapshots/nanosp/test_sign_message/00000.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 added tests/snapshots/nanosp/test_sign_message/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 added tests/snapshots/nanosp/test_sign_message/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 added tests/snapshots/nanosp/test_sign_message/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 added tests/snapshots/nanosp/test_sign_message/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 added tests/snapshots/nanosp/test_sign_message/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 added tests/snapshots/nanox/test_sign_message/00000.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 added tests/snapshots/nanox/test_sign_message/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 added tests/snapshots/nanox/test_sign_message/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 added tests/snapshots/nanox/test_sign_message/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 added tests/snapshots/nanox/test_sign_message/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 added tests/snapshots/nanox/test_sign_message/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 13 additions & 7 deletions tests/test_sign_message_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from application_client.everscale_command_sender import EverscaleCommandSender, Errors, WalletType
from application_client.everscale_response_unpacker import unpack_get_public_key_response, unpack_sign_tx_response
from utils import check_signature_validity
from utils import navigate_until_text_and_compare

# In this tests we check the behavior of the device when asked to sign a transaction

Expand All @@ -18,26 +18,32 @@
# We will ensure that the displayed information is correct by using screenshots comparison

# TODO: Add a valid raw message and a valid expected signature
def test_sign_message(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None:
@pytest.mark.active_test_scope
def test_sign_message(backend: BackendInterface, navigator: Navigator, default_screenshot_path: str, test_name: str) -> None:
# Use the app interface instead of raw interface
client = EverscaleCommandSender(backend)
account_number = 0
wallet_type = WalletType.WALLET_V3
# First we need to get the public key of the device in order to build the transaction
rapdu = client.get_public_key(account_number=account_number)
_, public_key, _, _ = unpack_get_public_key_response(rapdu.data)

# Message to sign
message = b"Hello, world!"
payload = bytes.fromhex("00000000001111111111111111111111111111111111111111111111111111111111111111")

# 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_message(account_number=account_number, wallet_type=wallet_type, message=message):
with client.sign_message(payload=payload):
# Validate the on-screen request by performing the navigation appropriate for this device
scenario_navigator.review_approve()
navigate_until_text_and_compare(
backend.firmware,
navigator,
"message.",
default_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 der_sig.hex() == "0000000000000000000000000000000000000000000000000000000000000000"
assert der_sig.hex() == "d2edfcb178abad8df455f605d2887e6fed24ed1d2462e1fc216fad55f2e60fa372239ce950b7ab944a2eb80a2bcfaadfa02f870c6b3ed6df29fa9bc7419a730f"

0 comments on commit 8f7908a

Please sign in to comment.