|
1 | 1 | from pathlib import Path |
| 2 | +import json |
| 3 | + |
2 | 4 | import pytest |
3 | 5 | from web3 import Web3 |
4 | 6 |
|
|
13 | 15 |
|
14 | 16 | from client.utils import CoinType |
15 | 17 | import client.response_parser as ResponseParser |
16 | | -from client.client import EthAppClient |
| 18 | +from client.client import EthAppClient, SignMode |
17 | 19 | from client.status_word import StatusWord |
18 | 20 | from client.dynamic_networks import DynamicNetwork |
19 | 21 | from client.trusted_name import TrustedName, TrustedNameType, TrustedNameSource |
20 | 22 |
|
| 23 | +from constants import ABIS_FOLDER |
21 | 24 |
|
22 | 25 | # Values used across all tests |
23 | 26 | CHAIN_ID = 1 |
@@ -305,3 +308,55 @@ def test_trusted_name_v2_expired(backend: BackendInterface, app_version: tuple[i |
305 | 308 | challenge=challenge, |
306 | 309 | not_valid_after=app_version)) |
307 | 310 | assert e.value.status == StatusWord.INVALID_DATA |
| 311 | + |
| 312 | + |
| 313 | +def test_trusted_name_mab_idle(backend: BackendInterface) -> None: |
| 314 | + app_client = EthAppClient(backend) |
| 315 | + |
| 316 | + with pytest.raises(ExceptionRAPDU) as e: |
| 317 | + # This will fail since outside of signing a TX/message, the derivation path is unset/empty |
| 318 | + app_client.provide_trusted_name(TrustedName(2, |
| 319 | + ADDR, |
| 320 | + NAME, |
| 321 | + tn_type=TrustedNameType.ACCOUNT, |
| 322 | + tn_source=TrustedNameSource.MULTISIG_ADDRESS_BOOK, |
| 323 | + chain_id=CHAIN_ID, |
| 324 | + challenge=ResponseParser.challenge(app_client.get_challenge().data), |
| 325 | + owner=b"\x11" * 20)) |
| 326 | + assert e.value.status == StatusWord.INVALID_DATA |
| 327 | + |
| 328 | + |
| 329 | +def test_trusted_name_mab_wrong_owner(backend: BackendInterface) -> None: |
| 330 | + app_client = EthAppClient(backend) |
| 331 | + |
| 332 | + with Path(f"{ABIS_FOLDER}/erc20.json").open() as file: |
| 333 | + contract = Web3().eth.contract( |
| 334 | + abi=json.load(file), |
| 335 | + address=None |
| 336 | + ) |
| 337 | + data = contract.encode_abi("transfer", [ |
| 338 | + bytes.fromhex("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"), |
| 339 | + int(100 * pow(10, 6)), |
| 340 | + ]) |
| 341 | + tx_params = { |
| 342 | + "chainId": 1, |
| 343 | + "nonce": 1337, |
| 344 | + "maxPriorityFeePerGas": Web3.to_wei(0, "gwei"), |
| 345 | + "maxFeePerGas": Web3.to_wei(2.55, "gwei"), |
| 346 | + "gas": 94548, |
| 347 | + "to": bytes.fromhex("dAC17F958D2ee523a2206206994597C13D831ec7"), |
| 348 | + "value": Web3.to_wei(0, "ether"), |
| 349 | + "data": data, |
| 350 | + } |
| 351 | + with app_client.sign("m/44'/60'/0'/0/0", tx_params, mode=SignMode.STORE): |
| 352 | + pass |
| 353 | + with pytest.raises(ExceptionRAPDU) as e: |
| 354 | + app_client.provide_trusted_name(TrustedName(2, |
| 355 | + ADDR, |
| 356 | + NAME, |
| 357 | + tn_type=TrustedNameType.ACCOUNT, |
| 358 | + tn_source=TrustedNameSource.MULTISIG_ADDRESS_BOOK, |
| 359 | + chain_id=tx_params["chainId"], |
| 360 | + challenge=ResponseParser.challenge(app_client.get_challenge().data), |
| 361 | + owner=b"\x00" * 20)) |
| 362 | + assert e.value.status == StatusWord.INVALID_DATA |
0 commit comments