Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ensure contract log str and repr work #969

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ape/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def __str__(self) -> str:
args = " ".join(f"{key}={val}" for key, val in self.event_arguments.items())
return f"{self.event_name} {args}"

def __repr__(self) -> str:
return f"<{str(self)}>"

def __getattr__(self, item: str) -> Any:
"""
Access properties from the log via ``.`` access.
Expand Down
10 changes: 10 additions & 0 deletions tests/functional/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def test_contract_log_serialization_with_hex_strings_and_non_checksum_addresses(
assert obj.transaction_index == TXN_INDEX


def test_contract_log_str(log):
obj = ContractLog.parse_obj(log.dict())
assert str(obj) == "MyEvent foo=0 bar=1"
antazoey marked this conversation as resolved.
Show resolved Hide resolved


def test_contract_log_repr(log):
obj = ContractLog.parse_obj(log.dict())
assert repr(obj) == "<MyEvent foo=0 bar=1>"


def test_contract_log_access(log):
assert "foo" in log
assert "bar" in log
Expand Down