From 07173511e0fa735db178d27b6340b9ecd9250c58 Mon Sep 17 00:00:00 2001 From: grdddj Date: Thu, 21 Oct 2021 11:11:14 +0200 Subject: [PATCH] decode_data renaming and docstring, renaming unit test file --- core/src/apps/ethereum/helpers.py | 3 ++- core/src/apps/ethereum/layout.py | 8 ++++---- ...yped_data.py => test_apps.ethereum.sign_typed_data.py} | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) rename core/tests/{test_apps.ethereum.typed_data.py => test_apps.ethereum.sign_typed_data.py} (99%) diff --git a/core/src/apps/ethereum/helpers.py b/core/src/apps/ethereum/helpers.py index 61750a0bfdb..8042054929e 100644 --- a/core/src/apps/ethereum/helpers.py +++ b/core/src/apps/ethereum/helpers.py @@ -95,7 +95,8 @@ def get_type_name(field: EthereumFieldType) -> str: return TYPE_TRANSLATION_DICT[data_type] -def decode_data(data: bytes, type_name: str) -> str: +def decode_typed_data(data: bytes, type_name: str) -> str: + """Used by sign_typed_data module to show data to user.""" if type_name.startswith("bytes"): return hexlify(data).decode() elif type_name == "string": diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 65c88b4e73a..9a8f8668e9e 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -17,7 +17,7 @@ from apps.common.confirm import confirm from . import networks, tokens -from .helpers import address_from_bytes, decode_data, get_type_name +from .helpers import address_from_bytes, decode_typed_data, get_type_name if False: from typing import Awaitable, Iterable, Optional @@ -127,8 +127,8 @@ async def confirm_hash(ctx: Context, primary_type: str, typed_data_hash: bytes) async def should_show_domain(ctx: Context, name: bytes, version: bytes) -> bool: page = Text("Typed Data", ui.ICON_SEND, icon_color=ui.GREEN) - domain_name = decode_data(name, "string") - domain_version = decode_data(version, "string") + domain_name = decode_typed_data(name, "string") + domain_version = decode_typed_data(version, "string") page.bold(f"Name: {domain_name}") page.normal(f"Version: {domain_version}") @@ -202,7 +202,7 @@ async def confirm_typed_value( array_str = "" description = f"{name}{array_str} ({type_name})" - data = decode_data(value, type_name) + data = decode_typed_data(value, type_name) if field.data_type in (EthereumDataType.ADDRESS, EthereumDataType.BYTES): await confirm_blob( diff --git a/core/tests/test_apps.ethereum.typed_data.py b/core/tests/test_apps.ethereum.sign_typed_data.py similarity index 99% rename from core/tests/test_apps.ethereum.typed_data.py rename to core/tests/test_apps.ethereum.sign_typed_data.py index 2675a803969..382213acfc1 100644 --- a/core/tests/test_apps.ethereum.typed_data.py +++ b/core/tests/test_apps.ethereum.sign_typed_data.py @@ -18,7 +18,7 @@ ) from apps.ethereum.helpers import ( get_type_name, - decode_data, + decode_typed_data, ) @@ -726,7 +726,7 @@ def test_get_type_name(self): res = get_type_name(field) self.assertEqual(res, expected) - def test_decode_data(self): + def test_decode_typed_data(self): VECTORS = ( # data, type_name, expected (b"\x4a\x56", "bytes", "4a56"), (b"Hello, Bob!", "string", "Hello, Bob!"), @@ -744,7 +744,7 @@ def test_decode_data(self): ) for data, type_name, expected in VECTORS: - res = decode_data(data, type_name) + res = decode_typed_data(data, type_name) self.assertEqual(res, expected)