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): add pydantic models for json fixture files #501

Merged
merged 18 commits into from
Apr 12, 2024

Conversation

danceratopz
Copy link
Member

@danceratopz danceratopz commented Apr 11, 2024

🗒️ Description

This PR fixes a couple of issues when deserializing json fixtures (loading them into a pydantic model) and adds new models for interacting with json fixture files. It also adds a script that can be used to verify the framework's serialization/deserialization of json fixtures files on disk using their hashes.

Adds rich as a dependency. To add rich, install the new script entry point, execute:

pip install --force-reinstall -e .
checkfixtures -i fixtures/

🔗 Related Issues

  • Will help consume.

✅ 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: All converted JSON/YML tests from ethereum/tests have been added to converted-ethereum-tests.txt.
  • 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.

This required:
1. Changing the from_pipe_str() BeforeValidator method to convert the serialized exception string back to an Exception enum instance (or list).
2. Modifying the annotated types to also accept single TransactionException or BlockchainException types so that they are also correctly coerced via from_pipe_str().
This fixes src/ethereum_test_tools/tests/test_types.py::TestPydanticModelConversion::test_json_serialization[transaction_t8n_to_none].

An additional class TransactionTransitionToolConverter now specifies how an evm transition tool should validate and serialize the to field. Whilst this didn't break test generation, it caused deserialization to fail on individual Transaction models.
The incorrect field name was specified. This only became apparent when deserializing fixtures, as the info field is not present when the hash gets generated after filling.

Patches up existing tests and also adds a dedicated test for this: src/ethereum_test_tools/tests/test_spec_base.py::test_json_dict
@danceratopz danceratopz added type:feat type: Feature scope:fw Scope: Framework (evm|tools|forks|pytest) labels Apr 11, 2024
@danceratopz danceratopz marked this pull request as ready for review April 11, 2024 23:16
Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

src/ethereum_test_tools/spec/file/types.py Outdated Show resolved Hide resolved
src/cli/check_fixtures.py Outdated Show resolved Hide resolved
@marioevz marioevz merged commit 5592062 into main Apr 12, 2024
9 checks passed
@marioevz marioevz deleted the feat/add-fixture-file-pydantic-models branch May 3, 2024 21:52
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.

None yet

2 participants