Files
app-ethereum/tests/ragger/test_blind_sign.py

59 lines
1.9 KiB
Python
Raw Normal View History

from pathlib import Path
2024-03-08 17:47:55 +01:00
import json
import pytest
2024-03-26 09:43:26 +01:00
from web3 import Web3
from client.client import EthAppClient, StatusWord
2024-03-08 17:47:55 +01:00
from ragger.backend import BackendInterface
from ragger.firmware import Firmware
from ragger.navigator import Navigator, NavInsID
from ragger.error import ExceptionRAPDU
2024-03-26 09:43:26 +01:00
from constants import ABIS_FOLDER
2024-03-08 17:47:55 +01:00
# Token approval, would require loading the "internal plugin" &
# providing the token metadata from the CAL
def test_blind_sign(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
default_screenshot_path: Path):
2024-03-08 17:47:55 +01:00
app_client = EthAppClient(backend)
2024-03-26 09:43:26 +01:00
with open(f"{ABIS_FOLDER}/erc20.json", encoding="utf-8") as file:
2024-03-08 17:47:55 +01:00
contract = Web3().eth.contract(
abi=json.load(file),
address=None
)
data = contract.encodeABI("approve", [
# Uniswap Protocol: Permit2
bytes.fromhex("000000000022d473030f116ddee9f6b43ac78ba3"),
Web3.to_wei("2", "ether")
])
tx_params = {
"nonce": 235,
"maxFeePerGas": Web3.to_wei(100, "gwei"),
"maxPriorityFeePerGas": Web3.to_wei(10, "gwei"),
"gas": 44001,
# Maker: Dai Stablecoin
"to": bytes.fromhex("6b175474e89094c44da98b954eedeac495271d0f"),
"data": data,
"chainId": 1
}
with pytest.raises(ExceptionRAPDU) as e:
2024-03-08 17:47:55 +01:00
with app_client.sign("m/44'/60'/0'/0/0", tx_params):
pass
assert e.value.status == StatusWord.INVALID_DATA
2024-03-08 17:47:55 +01:00
2024-03-26 09:43:26 +01:00
moves = []
2024-03-08 17:47:55 +01:00
if firmware.device.startswith("nano"):
if firmware.device == "nanos":
moves += [NavInsID.RIGHT_CLICK]
moves += [NavInsID.BOTH_CLICK]
else:
moves += [NavInsID.USE_CASE_CHOICE_CONFIRM]
navigator.navigate_and_compare(default_screenshot_path,
2024-03-08 17:47:55 +01:00
"blind-signed_approval",
moves)