Port scenario review in 'test_sign'

This commit is contained in:
Charles-Edouard de la Vergne
2024-04-29 16:14:49 +02:00
parent 9af7c08614
commit fb036cef55
9 changed files with 33 additions and 57 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

+33 -57
View File
@@ -9,7 +9,8 @@ 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
from ragger.navigator import Navigator
from ragger.navigator.navigation_scenario import NavigateWithScenario
# Values used across all tests
@@ -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,7 +150,7 @@ 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
@@ -194,7 +168,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 +179,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 +195,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 +211,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 +231,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 +252,13 @@ 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 +273,11 @@ 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 +288,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 +330,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 +350,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)