From 69c7b79390eb6cfa443c9a242df5ba94bf88c3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Palmer?= Date: Tue, 5 Nov 2024 11:16:16 +0100 Subject: [PATCH] [test] gathering test related to the sign instructions --- tests/integration/nano/nanosp/__init__.py | 0 .../test_apdu_sign.py} | 76 +++++++++++++++++-- .../nano/test_sign_micheline_without_hash.py | 42 ---------- .../nano/test_sign_with_small_packet.py | 64 ---------------- 4 files changed, 69 insertions(+), 113 deletions(-) delete mode 100644 tests/integration/nano/nanosp/__init__.py rename tests/integration/nano/{nanosp/test_nanosp_regression_press_right_works_across_apdu_recieves.py => test_sign/test_apdu_sign.py} (50%) mode change 100755 => 100644 delete mode 100755 tests/integration/nano/test_sign_micheline_without_hash.py delete mode 100755 tests/integration/nano/test_sign_with_small_packet.py diff --git a/tests/integration/nano/nanosp/__init__.py b/tests/integration/nano/nanosp/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/integration/nano/nanosp/test_nanosp_regression_press_right_works_across_apdu_recieves.py b/tests/integration/nano/test_sign/test_apdu_sign.py old mode 100755 new mode 100644 similarity index 50% rename from tests/integration/nano/nanosp/test_nanosp_regression_press_right_works_across_apdu_recieves.py rename to tests/integration/nano/test_sign/test_apdu_sign.py index b84c329cc..efa8083d7 --- a/tests/integration/nano/nanosp/test_nanosp_regression_press_right_works_across_apdu_recieves.py +++ b/tests/integration/nano/test_sign/test_apdu_sign.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2023 Functori +# Copyright 2024 Functori +# Copyright 2024 Trilitech # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,19 +14,80 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Check no need to click right two times between APDUs during signing flow""" - -from pathlib import Path +"""Gathering of tests related to Sign instructions.""" from conftest import requires_device +from utils.account import Account +from utils.app import send_and_navigate, Screen, ScreenText, TezosAppScreen, DEFAULT_ACCOUNT +from utils.message import Message, MichelineExpr, Transaction + +def test_sign_micheline_without_hash(app: TezosAppScreen): + """Check signing micheline wihout getting hash""" + test_name = "test_sign_micheline_without_hash" + + app.assert_screen(Screen.HOME) + + message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}]) + + data = app.sign(DEFAULT_ACCOUNT, + message, + with_hash=False, + path=test_name) + + app.checker.check_signature( + account=DEFAULT_ACCOUNT, + message=message, + with_hash=False, + data=data) -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT -from utils.message import MichelineExpr + app.quit() + +def test_sign_with_small_packet(app: TezosAppScreen): + """Check signing using small packet instead of full size packets""" + test_name = "test_sign_with_small_packet" + + app.setup_expert_mode() + + def check_sign_with_small_packet( + account: Account, + message: Message, + path: str) -> None: + + app.assert_screen(Screen.HOME) + + data = send_and_navigate( + send=lambda: app.backend.sign(account, message, apdu_size=10), + navigate=lambda: app.navigate_until_text(ScreenText.SIGN_ACCEPT, path)) + + app.checker.check_signature( + account, + message, + with_hash=False, + data=data) + + message = Transaction( + source = 'tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu', + fee = 50000, + counter = 8, + gas_limit = 54, + storage_limit = 45, + destination = 'KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT', + amount = 240000, + entrypoint = 'do', + parameter = {'prim': 'CAR'} + ) + + check_sign_with_small_packet( + account=DEFAULT_ACCOUNT, + message=message, + path=test_name) + + app.quit() @requires_device("nanosp") def test_nanosp_regression_press_right_works_across_apdu_recieves(app: TezosAppScreen): """Check no need to click right two times between APDUs during signing flow""" - test_name = Path(__file__).stem + test_name = "test_nanosp_regression_press_right_works_across_apdu_recieves" app.assert_screen(Screen.HOME) diff --git a/tests/integration/nano/test_sign_micheline_without_hash.py b/tests/integration/nano/test_sign_micheline_without_hash.py deleted file mode 100755 index 5b8dee986..000000000 --- a/tests/integration/nano/test_sign_micheline_without_hash.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2023 Functori - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Check signing micheline wihout getting hash""" - -from pathlib import Path - -from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT -from utils.message import MichelineExpr - -def test_sign_micheline_without_hash(app: TezosAppScreen): - """Check signing micheline wihout getting hash""" - test_name = Path(__file__).stem - - app.assert_screen(Screen.HOME) - - message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}]) - - data = app.sign(DEFAULT_ACCOUNT, - message, - with_hash=False, - path=test_name) - - app.checker.check_signature( - account=DEFAULT_ACCOUNT, - message=message, - with_hash=False, - data=data) - - app.quit() diff --git a/tests/integration/nano/test_sign_with_small_packet.py b/tests/integration/nano/test_sign_with_small_packet.py deleted file mode 100755 index ee02faaca..000000000 --- a/tests/integration/nano/test_sign_with_small_packet.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2023 Functori - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Check signing using small packet instead of full size packets""" - -from pathlib import Path - -from utils.account import Account -from utils.app import send_and_navigate, Screen, ScreenText, TezosAppScreen, DEFAULT_ACCOUNT -from utils.message import Message, Transaction - -def test_sign_with_small_packet(app: TezosAppScreen): - """Check signing using small packet instead of full size packets""" - test_name = Path(__file__).stem - - app.setup_expert_mode() - - def check_sign_with_small_packet( - account: Account, - message: Message, - path: str) -> None: - - app.assert_screen(Screen.HOME) - - data = send_and_navigate( - send=lambda: app.backend.sign(account, message, apdu_size=10), - navigate=lambda: app.navigate_until_text(ScreenText.SIGN_ACCEPT, path)) - - app.checker.check_signature( - account, - message, - with_hash=False, - data=data) - - message = Transaction( - source = 'tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu', - fee = 50000, - counter = 8, - gas_limit = 54, - storage_limit = 45, - destination = 'KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT', - amount = 240000, - entrypoint = 'do', - parameter = {'prim': 'CAR'} - ) - - check_sign_with_small_packet( - account=DEFAULT_ACCOUNT, - message=message, - path=test_name) - - app.quit()