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: use jinja for templating #21

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

Conversation

skellet0r
Copy link
Contributor

@skellet0r skellet0r commented Dec 23, 2021

What I did

Redid the mock ERC20 contract and used Jinja2 templating to clean/simplify the process of generating contracts with different return values / failure conditions.

Previously, we did manual string manipulation, however that is very clunky and doesn't invite modification. Using jinja however, the source modifications can be done in the contract file itself, rather than via the python format function.

This also serves as an example for future modifications / templates. Although unused by me, there could very well be ERC721, ERC777, ERC1363, ERC1155 ... and more token templates.

How I did it

Mainly using the Jinja2 documentation https://jinja.palletsprojects.com/, the templating syntax is rather simple to catch on to, and has a rich set of features (such as macros which enable DRY code).

How to verify it

I ported over an actual set of ERC20 test cases, to verify that the contract works properly (not just return values), The tests are parametrized over the set of possible variations:

Success Value: True, False, None
Failure Value: True, False, None, "revert"

Checklist

  • I have confirmed that my PR passes all linting checks
  • I have included test cases
  • I have updated the documentation (README.md)
  • I have added an entry to the changelog

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.

1 participant