From 4bdf0e3c7af52360bd890dd47b32472c6388726d Mon Sep 17 00:00:00 2001 From: Coline Date: Fri, 24 Jun 2022 13:38:28 +0200 Subject: [PATCH] feat: apdu_as_string in utils --- tests/speculos/ethereum_client/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/speculos/ethereum_client/utils.py b/tests/speculos/ethereum_client/utils.py index d5d05a4..72c63c9 100644 --- a/tests/speculos/ethereum_client/utils.py +++ b/tests/speculos/ethereum_client/utils.py @@ -13,6 +13,16 @@ UINT16_MAX: int = 65535 # Association tableau si écran nanos ou nanox PATH_IMG = {"nanos": "nanos", "nanox": "nanox", "nanosp": "nanox"} +def apdu_as_string(apdu: str) -> bytes: + buffer: bytearray = bytearray(len(apdu) // 2) + + for i in range(0, len(apdu), 2): + str_extract: str = apdu[i: i + 2] + buffer[i // 2] = int(str_extract, 16) + + return bytes(buffer) + + def save_screenshot(cmd, path: str): screenshot = cmd.client.get_screenshot() img = Image.open(io.BytesIO(screenshot))