-
Notifications
You must be signed in to change notification settings - Fork 92
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/pydantic: Use Pydantic library for types #486
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marioevz
added
scope:tools
Scope: ethereum_test_tools package
scope:pytest
Scope: Pytest plugins
scope:tests
Scope: Test cases
type:refactor
Type: Refactor
type:feat
type: Feature
scope:fw
Scope: Framework (evm|tools|forks|pytest)
labels
Mar 26, 2024
1100+ less lines of code overall. |
Co-authored-by: danceratopz <[email protected]>
Co-authored-by: danceratopz <[email protected]>
6 tasks
danceratopz
approved these changes
Apr 4, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it. The code is much more readable. The removal of all the json_encoder
defs in types.py is such a joy.
The suggestions below are mainly a few additions to docstrings/comments.
Co-authored-by: danceratopz <[email protected]>
Co-authored-by: danceratopz <[email protected]>
Co-authored-by: danceratopz <[email protected]>
7 tasks
15 tasks
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)
scope:pytest
Scope: Pytest plugins
scope:tests
Scope: Test cases
scope:tools
Scope: ethereum_test_tools package
type:feat
type: Feature
type:refactor
Type: Refactor
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🗒️ Description
Simplify code by using Pydantic library.
Affected Files Description
src/ethereum_test_tools/common/base_types.py
A pydantic schema was defined as
ToStringSchema
which all base types inherit in order to be properly serializable.src/ethereum_test_tools/common/types.py
The following types have been transformed into pydantic base models:
Types Storage and Alloc were defined as
RootModel
types due to the nature of them containing non-fixed keys in their dictionaries.Type generics were used to simplify the creation of inherited types where the only change was the number encoding, such as
WithdrawalGeneric
,EnvironmentGeneric
andTransactionGeneric
, which have been used to createFixtureWithdrawal
,FixtureEnvironment
, andFixtureTransaction
, respectively.Many type methods have been refactored into cached properties, such as the transaction's RLP, in order to reduce the number of times this same value has to be computed.
Models
TransactionReceipt
,RejectedTransaction
,Result
,TransitionToolOutput
, are types that are used to parse the responses from the transition tool.src/ethereum_test_tools/spec/state/types.py, src/ethereum_test_tools/spec/state/state_test.py
State test types and its fixture types have been refactored to use pydantic models.
src/ethereum_test_tools/spec/blockchain/types.py
Blockchain test types and its fixture types have been refactored to use pydantic models.
TODOs
There is still room for improvement but this can be left for to subsequent PRs:
evm_transition_tool
library.🔗 Related Issues
None
✅ Checklist
mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.