Skip to content

Commit 28d7831

Browse files
update tests according to PR remarks
1 parent 799ec65 commit 28d7831

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

tests/test_name_version.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from application_client.kaspa_command_sender import KaspaCommandSender
22
from application_client.kaspa_response_unpacker import unpack_get_app_and_version_response
3+
from utils import verify_version
34

45

56
# Test a specific APDU asking BOLOS (and not the app) the name and version of the current app
6-
def test_get_app_and_version(backend, backend_name):
7+
def test_get_app_and_version(backend):
78
# Use the app interface instead of raw interface
89
client = KaspaCommandSender(backend)
910
# Send the special instruction to BOLOS
@@ -12,4 +13,4 @@ def test_get_app_and_version(backend, backend_name):
1213
app_name, version = unpack_get_app_and_version_response(response.data)
1314

1415
assert app_name == "Kaspa"
15-
assert version == "1.2.0"
16+
verify_version(version)

tests/test_version_cmd.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
from application_client.kaspa_command_sender import KaspaCommandSender
22
from application_client.kaspa_response_unpacker import unpack_get_version_response
3-
4-
# Taken from the Makefile, to update every time the Makefile version is bumped
5-
MAJOR = 1
6-
MINOR = 2
7-
PATCH = 0
3+
from utils import verify_version
84

95
# In this test we check the behavior of the device when asked to provide the app version
106
def test_version(backend):
117
# Use the app interface instead of raw interface
128
client = KaspaCommandSender(backend)
139
# Send the GET_VERSION instruction
1410
rapdu = client.get_version()
15-
# Use an helper to parse the response, assert the values
16-
assert unpack_get_version_response(rapdu.data) == (MAJOR, MINOR, PATCH)
11+
# Use an helper to parse the response
12+
parsed_major, parsed_minor, parsed_patch = unpack_get_version_response(rapdu.data)
13+
verify_version(f"{parsed_major}.{parsed_minor}.{parsed_patch}")

tests/utils.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from pathlib import Path
2+
from typing import List
3+
import re
24

35
from secp256k1 import PublicKey
46

@@ -7,5 +9,37 @@
79
# Check if a signature of a given message is valid
810
def check_signature_validity(public_key: bytes, signature: bytes, sighash: bytes) -> bool:
911
pkey = PublicKey(public_key, True)
10-
12+
1113
return pkey.schnorr_verify(sighash, signature, None, True)
14+
15+
def verify_version(version: str) -> None:
16+
"""Verify the app version, based on defines in Makefile
17+
18+
Args:
19+
Version (str): Version to be checked
20+
"""
21+
22+
vers_dict = {}
23+
vers_str = ""
24+
lines = _read_makefile()
25+
version_re = re.compile(r"^APPVERSION_(?P<part>\w)\s?=\s?(?P<val>\d*)", re.I)
26+
for line in lines:
27+
info = version_re.match(line)
28+
if info:
29+
dinfo = info.groupdict()
30+
vers_dict[dinfo["part"]] = dinfo["val"]
31+
try:
32+
vers_str = f"{vers_dict['M']}.{vers_dict['N']}.{vers_dict['P']}"
33+
except KeyError:
34+
pass
35+
assert version == vers_str
36+
37+
38+
def _read_makefile() -> List[str]:
39+
"""Read lines from the parent Makefile """
40+
41+
parent = Path(__file__).parent.parent.resolve()
42+
makefile = f"{parent}/Makefile"
43+
with open(makefile, "r", encoding="utf-8") as f_p:
44+
lines = f_p.readlines()
45+
return lines

0 commit comments

Comments
 (0)