Skip to content

Commit 7e1f288

Browse files
committed
Re-add validations to get the tests to pass
1 parent 490624e commit 7e1f288

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

eth/validation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def validate_is_bytes(value: bytes, title: str="Value") -> None:
5151
)
5252

5353

54+
def validate_is_bytes_or_view(value: Union[bytes, memoryview],
55+
title: str="Value") -> None:
56+
if isinstance(value, bytes):
57+
return
58+
if isinstance(value, memoryview):
59+
return
60+
raise ValidationError(
61+
"{title} must be bytes or memoryview. Got {0}".format(type(value), title=title)
62+
)
63+
64+
5465
def validate_is_integer(value: Union[int, bool], title: str="Value") -> None:
5566
if not isinstance(value, int) or isinstance(value, bool):
5667
raise ValidationError(

eth/vm/computation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from eth.validation import (
4242
validate_canonical_address,
4343
validate_is_bytes,
44+
validate_is_bytes_or_view,
4445
validate_uint256,
4546
)
4647
from eth.vm.code_stream import (
@@ -447,11 +448,11 @@ def add_log_entry(
447448
account: Address,
448449
topics: List[int],
449450
data: Union[bytes, memoryview]) -> None:
450-
data = bytes(data)
451451
validate_canonical_address(account, title="Log entry address")
452452
for topic in topics:
453453
validate_uint256(topic, title="Log entry topic")
454-
validate_is_bytes(data, title="Log entry data")
454+
validate_is_bytes_or_view(data, title="Log entry data")
455+
data = bytes(data)
455456
self._log_entries.append(
456457
(self.transaction_context.get_next_log_counter(), account, topics, data))
457458

eth/vm/message.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from eth.validation import (
1010
validate_canonical_address,
1111
validate_is_bytes,
12+
validate_is_bytes_or_view,
1213
validate_is_integer,
1314
validate_gte,
1415
validate_uint256,
@@ -52,7 +53,7 @@ def __init__(self,
5253
validate_uint256(value, title="Message.value")
5354
self.value = value
5455

55-
# validate_is_bytes(data, title="Message.data")
56+
validate_is_bytes_or_view(data, title="Message.data")
5657
self.data = data
5758

5859
validate_is_integer(depth, title="Message.depth")

0 commit comments

Comments
 (0)