Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hexbytes/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def hexstr_to_bytes(hexstr: str) -> bytes:

try:
ascii_hex = padded_hex.encode("ascii")
except UnicodeDecodeError as err:
except UnicodeEncodeError as err:
raise ValueError(
f"hex string {padded_hex} may only contain [0-9a-fA-F] characters"
) from err
Expand Down
7 changes: 7 additions & 0 deletions tests/core/test_hexbytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def test_invalid_integer_inputs(integer):
assert str(integer) in message


def test_invalid_non_ascii_hexstr():
with pytest.raises(ValueError) as exc_info:
HexBytes("0x0é")

assert "may only contain [0-9a-fA-F] characters" in str(exc_info.value)


@given(st.integers(min_value=0))
def test_integer_inputs(integer):
wrapped = HexBytes(integer)
Expand Down