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

Adds a dictionary of event args/data to Event type for easier access to variables #60

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

kibagateaux
Copy link

@kibagateaux kibagateaux commented Jan 23, 2023

Description

Updates Event type in boa/vyper/events.py
Allows access to event data with event variable names e.g. contract.get_logs()[0].args_map['my_event_variable']

  • creates internal function Event._get_ordered_args from current Event.__repr__ code
  • refactors Event.__repr__ to use Event._get_ordered_args
  • add args_map property to Event type
  • generates args_map dictionary from Event._get_ordered_args
  • adds caching to _get_ordered_args and args_map

TODO

[x] Convert event values to appropriate type. Currently all values are strings which makes comparing numbers cumbersome (always have to do event.args_map['my_int'] == str(my_int))

Testing

  • Currently no testing for events. Would appreciate advice on how you guys want that setup.
  • Have implemented in my own repo and my tests are passing successfully. Can clone and run ape test --network=::foundry --cache-clear -m "event_emissions"

@kibagateaux kibagateaux force-pushed the fix/event-data-access branch from dc9478d to 48641f5 Compare January 23, 2023 19:22
@kibagateaux kibagateaux force-pushed the fix/event-data-access branch from 605887d to 9c1f958 Compare January 23, 2023 20:29
@kibagateaux kibagateaux force-pushed the fix/event-data-access branch from 683ade0 to 481b7f5 Compare January 24, 2023 07:46
@kibagateaux kibagateaux force-pushed the fix/event-data-access branch from 426549c to b2da209 Compare January 25, 2023 15:58
@kibagateaux kibagateaux force-pushed the fix/event-data-access branch from b2da209 to ee50b01 Compare January 25, 2023 16:02
return dict(self._get_ordered_args())

@functools.cached_property
def _get_ordered_args(self) -> List[Tuple[str, str | int]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is a cached property, I’d just call it something else other than a getter. ‘ordered_args’ is good enough.

@bout3fiddy
Copy link
Contributor

It’s missing a pre-commit run. Also some simple tests using a mock contract will help quite a bit! Something like what you have in your repo, but minimal.

@kibagateaux kibagateaux force-pushed the fix/event-data-access branch from 0454021 to 0798330 Compare July 5, 2023 10:54
@kibagateaux kibagateaux force-pushed the fix/event-data-access branch from 0798330 to 7dea3c3 Compare July 5, 2023 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants