Skip to content

Commit

Permalink
decode_data renaming and docstring, renaming unit test file
Browse files Browse the repository at this point in the history
  • Loading branch information
grdddj committed Oct 21, 2021
1 parent 2b5a0f1 commit 0717351
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion core/src/apps/ethereum/helpers.py
Expand Up @@ -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":
Expand Down
8 changes: 4 additions & 4 deletions core/src/apps/ethereum/layout.py
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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(
Expand Down
Expand Up @@ -18,7 +18,7 @@
)
from apps.ethereum.helpers import (
get_type_name,
decode_data,
decode_typed_data,
)


Expand Down Expand Up @@ -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!"),
Expand All @@ -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)


Expand Down

0 comments on commit 0717351

Please sign in to comment.