Port scenario review in 'test_sign'

This commit is contained in:
Charles-Edouard de la Vergne
2024-04-16 23:45:17 +02:00
parent e428657f01
commit 3c169dc896
9 changed files with 51 additions and 61 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -1,16 +1,17 @@
from pathlib import Path
from web3 import Web3
from ragger.error import ExceptionRAPDU
from ragger.backend import BackendInterface
from ragger.firmware import Firmware
from ragger.navigator import Navigator
from ragger.navigator.navigation_scenario import NavigateWithScenario
from client.client import EthAppClient, StatusWord
import client.response_parser as ResponseParser
from client.settings import SettingID, settings_toggle
from client.utils import recover_transaction
from ragger.error import ExceptionRAPDU
from ragger.backend import BackendInterface
from ragger.firmware import Firmware
from ragger.navigator import Navigator, NavInsID
# Values used across all tests
CHAIN_ID = 1
@@ -31,7 +32,7 @@ AMOUNT2 = 0.31415
def common(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
default_screenshot_path: Path,
tx_params: dict,
test_name: str = "",
@@ -44,22 +45,11 @@ def common(firmware: Firmware,
with app_client.sign(path, tx_params):
if firmware.device.startswith("nano"):
next_action = NavInsID.RIGHT_CLICK
confirm_action = NavInsID.BOTH_CLICK
end_text = "Accept"
else:
next_action = NavInsID.USE_CASE_REVIEW_TAP
confirm_action = NavInsID.USE_CASE_REVIEW_CONFIRM
end_text = "Sign"
if test_name:
navigator.navigate_until_text_and_compare(next_action,
[confirm_action],
end_text,
default_screenshot_path,
test_name)
else:
navigator.navigate_until_text(next_action, [confirm_action], end_text)
scenario_navigator.review_approve(default_screenshot_path, test_name, end_text, (test_name != ""))
# verify signature
vrs = ResponseParser.signature(app_client.response().data)
@@ -67,9 +57,8 @@ def common(firmware: Firmware,
assert addr == DEVICE_ADDR
def common_reject(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
def common_reject(backend: BackendInterface,
scenario_navigator: NavigateWithScenario,
default_screenshot_path: Path,
tx_params: dict,
test_name: str,
@@ -78,22 +67,7 @@ def common_reject(firmware: Firmware,
try:
with app_client.sign(path, tx_params):
if firmware.device.startswith("nano"):
next_action = NavInsID.RIGHT_CLICK
confirm_action = NavInsID.BOTH_CLICK
navigator.navigate_until_text_and_compare(next_action,
[confirm_action],
"Reject",
default_screenshot_path,
test_name)
else:
instructions = [NavInsID.USE_CASE_REVIEW_TAP] * 2
instructions += [NavInsID.USE_CASE_CHOICE_REJECT,
NavInsID.USE_CASE_CHOICE_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS]
navigator.navigate_and_compare(default_screenshot_path,
test_name,
instructions)
scenario_navigator.review_reject(default_screenshot_path, test_name)
except ExceptionRAPDU as e:
assert e.status == StatusWord.CONDITION_NOT_SATISFIED
@@ -119,7 +93,7 @@ def common_fail(backend: BackendInterface,
def test_legacy(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
default_screenshot_path: Path):
tx_params: dict = {
"nonce": NONCE,
@@ -129,7 +103,7 @@ def test_legacy(firmware: Firmware,
"value": Web3.to_wei(AMOUNT, "ether"),
"chainId": CHAIN_ID
}
common(firmware, backend, navigator, default_screenshot_path, tx_params)
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params)
# Transfer amount >= 2^87 Eth on Ethereum app should fail
@@ -148,7 +122,7 @@ def test_legacy_send_error(backend: BackendInterface):
# Transfer bsc
def test_legacy_send_bsc(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
tx_params: dict = {
@@ -159,15 +133,15 @@ def test_legacy_send_bsc(firmware: Firmware,
"value": Web3.to_wei(AMOUNT2, "ether"),
"chainId": 56
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, BIP32_PATH2)
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params, test_name, BIP32_PATH2)
# Transfer on network 112233445566 on Ethereum
def test_legacy_chainid(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str,
default_screenshot_path: Path):
backend: BackendInterface,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
tx_params: dict = {
"nonce": NONCE2,
"gasPrice": Web3.to_wei(GAS_PRICE, 'gwei'),
@@ -176,13 +150,15 @@ def test_legacy_chainid(firmware: Firmware,
"value": Web3.to_wei(AMOUNT2, "ether"),
"chainId": 112233445566
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, BIP32_PATH2)
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params, test_name, BIP32_PATH2)
# Try to blind sign with setting disabled
def test_legacy_contract(backend: BackendInterface):
# pylint: disable=line-too-long
buffer = bytes.fromhex("058000002c8000003c800000010000000000000000f849208506fc23ac008303dc3194f650c3d88d12db855b8bf7d11be6c55a4e07dcc980a4a1712d6800000000000000000000000000000000000000000000000000000000000acbc7018080")
# pylint: enable=line-too-long
app_client = EthAppClient(backend)
try:
@@ -194,7 +170,7 @@ def test_legacy_contract(backend: BackendInterface):
def test_1559(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
default_screenshot_path: Path):
tx_params: dict = {
"nonce": NONCE,
@@ -205,12 +181,12 @@ def test_1559(firmware: Firmware,
"value": Web3.to_wei(AMOUNT, "ether"),
"chainId": CHAIN_ID
}
common(firmware, backend, navigator, default_screenshot_path, tx_params)
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params)
def test_sign_simple(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
tx_params: dict = {
@@ -221,12 +197,12 @@ def test_sign_simple(firmware: Firmware,
"value": Web3.to_wei(AMOUNT2, "ether"),
"chainId": CHAIN_ID
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
def test_sign_limit_nonce(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
tx_params: dict = {
@@ -237,12 +213,13 @@ def test_sign_limit_nonce(firmware: Firmware,
"value": 0x08762,
"chainId": CHAIN_ID
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
def test_sign_nonce_display(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
@@ -256,12 +233,13 @@ def test_sign_nonce_display(firmware: Firmware,
"value": Web3.to_wei(AMOUNT2, "ether"),
"chainId": CHAIN_ID
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
def test_sign_blind_simple(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
settings_toggle(firmware, navigator, [SettingID.BLIND_SIGNING])
@@ -276,12 +254,19 @@ def test_sign_blind_simple(firmware: Firmware,
"chainId": CHAIN_ID,
"data": data.encode('utf-8').hex()
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
common(firmware,
backend,
scenario_navigator,
default_screenshot_path,
tx_params,
test_name,
"m/44'/60'/1'/0/0")
def test_sign_blind_and_nonce_display(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
settings_toggle(firmware, navigator, [SettingID.NONCE, SettingID.BLIND_SIGNING])
@@ -296,12 +281,17 @@ def test_sign_blind_and_nonce_display(firmware: Firmware,
"chainId": CHAIN_ID,
"data": data.encode('utf-8').hex()
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
common(firmware,
backend,
scenario_navigator,
default_screenshot_path,
tx_params,
test_name,
"m/44'/60'/1'/0/0")
def test_sign_reject(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
def test_sign_reject(backend: BackendInterface,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
tx_params: dict = {
@@ -312,7 +302,7 @@ def test_sign_reject(firmware: Firmware,
"value": Web3.to_wei(AMOUNT2, "ether"),
"chainId": CHAIN_ID
}
common_reject(firmware, backend, navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
common_reject(backend, scenario_navigator, default_screenshot_path, tx_params, test_name, "m/44'/60'/1'/0/0")
def test_sign_error_transaction_type(backend: BackendInterface):
@@ -354,7 +344,7 @@ def test_sign_blind_error_disabled(backend: BackendInterface):
def test_sign_eip_2930(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str,
default_screenshot_path: Path):
@@ -374,4 +364,4 @@ def test_sign_eip_2930(firmware: Firmware,
}
],
}
common(firmware, backend, navigator, default_screenshot_path, tx_params, test_name)
common(firmware, backend, scenario_navigator, default_screenshot_path, tx_params, test_name)