Skip to content

Commit 5a0c0c4

Browse files
committed
disallow assign of fixedbytes of size X to bytes of size Y when X != Y
1 parent 6446ed4 commit 5a0c0c4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/ethereum_test_base_types/conversions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Common conversion methods.
33
"""
4+
45
from re import sub
56
from typing import Any, List, Optional, SupportsBytes, TypeAlias
67

@@ -63,6 +64,8 @@ def to_fixed_size_bytes(input: FixedSizeBytesConvertible, size: int) -> bytes:
6364
input = to_bytes(input)
6465
if len(input) > size:
6566
raise Exception(f"input is too large for fixed size bytes: {len(input)} > {size}")
67+
if len(input) < size:
68+
raise Exception(f"input is too small for fixed size bytes: {len(input)} < {size}")
6669
return bytes(input).rjust(size, b"\x00")
6770

6871

src/ethereum_test_types/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,12 @@ def validate_to_as_empty_string(cls, data: Any) -> Any:
672672
"""
673673
If the `to` field is an empty string, set the model value to None.
674674
"""
675-
if isinstance(data, dict) and "to" in data and data["to"] == "":
675+
if (
676+
isinstance(data, dict)
677+
and "to" in data
678+
and isinstance(data["to"], str)
679+
and data["to"] == ""
680+
):
676681
data["to"] = None
677682
return data
678683

0 commit comments

Comments
 (0)