Skip to content

Commit efc812f

Browse files
Improve Ragger test for expired trusted name
1 parent f14c164 commit efc812f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tests/ragger/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
from os import path
44
import warnings
55
import glob
6+
import re
7+
8+
import pytest
69

710
from ragger.conftest import configuration
811

12+
913
#######################
1014
# CONFIGURATION START #
1115
#######################
@@ -14,6 +18,7 @@
1418
# ragger.configuration.OPTIONAL_CONFIGURATION
1519
# Please refer to ragger/conftest/configuration.py for their descriptions and accepted values
1620

21+
1722
def pytest_addoption(parser):
1823
parser.addoption("--with_lib_mode", action="store_true", help="Run the test with Library Mode")
1924

@@ -42,6 +47,15 @@ def pytest_addoption(parser):
4247
collect_ignore += [f for f in testFiles if "test_clone" in f]
4348

4449

50+
@pytest.fixture(name="app_version")
51+
def app_version_fixture(request) -> tuple[int, int, int]:
52+
with open(Path(__file__).parent.parent.parent / "Makefile") as f:
53+
parsed = dict()
54+
for m in re.findall(r"^APPVERSION_(\w)\s*=\s*(\d*)$", f.read(), re.MULTILINE):
55+
parsed[m[0]] = int(m[1])
56+
return (parsed["M"], parsed["N"], parsed["P"])
57+
58+
4559
#####################
4660
# CONFIGURATION END #
4761
#####################

tests/ragger/test_trusted_name.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,28 @@ def test_trusted_name_v2_missing_challenge(firmware: Firmware, backend: BackendI
284284
assert e.value.status == StatusWord.INVALID_DATA
285285

286286

287-
def test_trusted_name_v2_expired(firmware: Firmware, backend: BackendInterface):
287+
def test_trusted_name_v2_expired(firmware: Firmware, backend: BackendInterface, app_version: tuple[int, int, int]):
288288
app_client = EthAppClient(backend)
289289
challenge = common(firmware, app_client)
290290

291+
# convert to list and reverse
292+
app_version = list(app_version)
293+
app_version.reverse()
294+
# simulate a previous version number by decrementing the first non-zero value
295+
for idx, v in enumerate(app_version):
296+
if v > 0:
297+
app_version[idx] -= 1
298+
break
299+
# reverse and convert back
300+
app_version.reverse()
301+
app_version = tuple(app_version)
302+
291303
with pytest.raises(ExceptionRAPDU) as e:
292304
app_client.provide_trusted_name_v2(ADDR,
293305
NAME,
294306
TrustedNameType.ACCOUNT,
295307
TrustedNameSource.ENS,
296308
CHAIN_ID,
297309
challenge=challenge,
298-
not_valid_after=(0, 1, 2))
310+
not_valid_after=app_version)
299311
assert e.value.status == StatusWord.INVALID_DATA

0 commit comments

Comments
 (0)