Skip to content

Commit 9783369

Browse files
Added Ragger tests for the new trusted name field
1 parent c25fb0a commit 9783369

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

tests/ragger/test_gcs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,9 @@ def test_gcs_batch_complex(scenario_navigator: NavigateWithScenario) -> None:
26412641
backend = scenario_navigator.backend
26422642
app_client = EthAppClient(backend)
26432643

2644+
with app_client.get_public_addr(bip32_path="m/44'/60'/0'/0/0", display=False):
2645+
pass
2646+
_, wallet_addr, _ = ResponseParser.pk_addr(app_client.response().data)
26442647
tokens = [
26452648
{
26462649
"ticker": "USDT",
@@ -2819,7 +2822,8 @@ def test_gcs_batch_complex(scenario_navigator: NavigateWithScenario) -> None:
28192822
tn_type=TrustedNameType.ACCOUNT,
28202823
tn_source=TrustedNameSource.MULTISIG_ADDRESS_BOOK,
28212824
chain_id=tx_params["chainId"],
2822-
challenge=ResponseParser.challenge(app_client.get_challenge().data)))
2825+
challenge=ResponseParser.challenge(app_client.get_challenge().data),
2826+
owner=wallet_addr))
28232827

28242828
# compute instructions hash
28252829
sub_inst_hash = compute_inst_hash(sub_fields)

tests/ragger/test_trusted_name.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from pathlib import Path
2+
import json
3+
24
import pytest
35
from web3 import Web3
46

@@ -13,11 +15,12 @@
1315

1416
from client.utils import CoinType
1517
import client.response_parser as ResponseParser
16-
from client.client import EthAppClient
18+
from client.client import EthAppClient, SignMode
1719
from client.status_word import StatusWord
1820
from client.dynamic_networks import DynamicNetwork
1921
from client.trusted_name import TrustedName, TrustedNameType, TrustedNameSource
2022

23+
from constants import ABIS_FOLDER
2124

2225
# Values used across all tests
2326
CHAIN_ID = 1
@@ -305,3 +308,55 @@ def test_trusted_name_v2_expired(backend: BackendInterface, app_version: tuple[i
305308
challenge=challenge,
306309
not_valid_after=app_version))
307310
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

Comments
 (0)