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

feat(fw): Implement ModelGenerator, implement Transactions and Withdrawals #435

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

marioevz
Copy link
Member

@marioevz marioevz commented Feb 9, 2024

🗒️ Description

Adds a ModelGenerator class which can be used to implement generators of pydantic models, such as Transaction and Withdrawal.

ModelGenerator is used as:

class Transactions(ModelGenerator, model=Transaction, index_field="nonce"):
    pass

and generates a new class that takes the same arguments for instantiation, but also takes an Iterable in each field.

When an Iterable is provided, a generator is instantiated that produces one instance of the model per element.

ModelGenerator automatically detects which fields of the model are already supposed to be lists (iterables), and accepts a new field with an _iter suffix and treats each as an iterator to generate the lists.

E.g. In the Transaction class, the field access_list is already supposed to be a list, so the ModelGenerator accepts a new field called access_list_iter where the user can specify the iterable for this field that generates the access_list field for each generated transaction.

This PR implements Transactions and Withdrawals, and modifies usages in many tests as examples.

🔗 Related Issues

None

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

@marioevz marioevz added type:feat type: Feature scope:fw Scope: Framework (evm|tools|forks|pytest) labels Feb 9, 2024
@spencer-tb
Copy link
Contributor

Super nice!

@marioevz marioevz force-pushed the transactions-iterator branch from b8ec99e to 4ec7d20 Compare February 11, 2024 21:39
@marioevz marioevz changed the title feat(fw): Transactions Iterator Class feat(fw): Implement DataclassGenerator, implement Transactions and Withdrawals Feb 11, 2024
Copy link
Contributor

@spencer-tb spencer-tb left a comment

Choose a reason for hiding this comment

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

Really nice, I checked to see if we could use these in other tests but couldn't find anything!

I wondered if we could do something similar for pre/post accounts, or even blocks but I don't think the value is weighted.

We should add tests for withdrawals tests/test_withdrawals.py and add a section to the documentation for this.

When I update: #61 - I will use Transactions - so I can mention these in the documentation too

@marioevz
Copy link
Member Author

When I update: #61 - I will use Transactions - so I can mention these in the documentation too

Yes please 👍 we definitely need some examples in the docs for this.

I think the Blocks case should be doable. I haven't thought too much about it but I don't see why this could not be done.

@marioevz marioevz marked this pull request as draft April 3, 2024 15:21
@marioevz
Copy link
Member Author

marioevz commented Apr 3, 2024

This PR is affected by the pydantic changes, so potentially needs to be reworked.

Converting into draft until rework is done.

@marioevz marioevz force-pushed the transactions-iterator branch from 8cfbece to bb90231 Compare April 3, 2024 16:45
@marioevz
Copy link
Member Author

marioevz commented Apr 3, 2024

Rebased on top of #486, which was surprisingly easy, but now it requires that PR to be merged first.

@marioevz marioevz changed the title feat(fw): Implement DataclassGenerator, implement Transactions and Withdrawals feat(fw): Implement ModelGenerator, implement Transactions and Withdrawals Apr 3, 2024
@marioevz marioevz force-pushed the transactions-iterator branch from bb90231 to cfb4407 Compare April 3, 2024 21:40
@marioevz marioevz force-pushed the transactions-iterator branch from a41a283 to da07dd9 Compare April 4, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:fw Scope: Framework (evm|tools|forks|pytest) type:feat type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants