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

MyPy + Jupyter Notebooks with Testing + Handle Txn Params #17

Merged
merged 84 commits into from
May 18, 2022
Merged

Conversation

tzaffi
Copy link
Contributor

@tzaffi tzaffi commented May 14, 2022

mypy

Enabling mypy by incorporating #16 and making other similar changes to new code. This makes it possible for downstream dependencies that incorporate graviton to be mypy-compliant as well.

Allow handling of Transaction Params in Logic Sig and App Dry-Runs

Previously, graviton was using the old Python SDK DryRunHelper which hard-coded the transaction information associated with a dry run. This made it impossible to write logic sigs that vallidated the transaction information in their program. This PR fixes this situation. In fact, the image below was only possible to create thanks to this new addition.

Jupyter Notebooks

Introducing notebooks/quadratic_factoring_game.ipynb which shows how to leverage graviton for creating graphs in jupyter such as below. The notebook also runs during integration testing.

image

Summary of Important Changes

  • .github/workflows/build.yml + Makefile:
    • allow testing and running jupyter notebooks
    • add mypy to lint
  • graviton/:
    • README.md - move the top-level tutorial here
    • abi_strategy.py - includes ABIStrategy which lets you generate random ABI instances as well as running mutate_for_dryrun() which emulates the logic in the roundtrip teal programs and allows for verification that abi decoding/manipulation/encoding all work as expected
    • blackbox.py:
      • pass mypy
      • allow specifying transaction params into dry-runs
      • handle ABI types
    • dryrun.py:
      • pass mypy
    • deprecated_dry_run.py: new module that contains functionality mostly used by the now deprecated DryRunTestCaseMixin
    • deprecated_dryrun_mixin.py: where the now deprecated DryRunTestCaseMixin is defined
    • dryrun.py:
      • refactor to keep only the most useful portions of the original helper
      • make mypy pass
      • allow specifying transaction parameters
      • pprint() now returns a string, in addition to printing
    • invariant.py: make mypy pass
    • models.py: new module that contains lightweight models such as the App and LSig dataclasses
    • py.typed - needed for mypy
  • mypy.ini: needed by mypy
  • notebooks: new directory for Jupyter notebooks. It contains:
    • IMAGES.md: a static file that shows examples of 3D graphs of dry-runs
    • notebooks_test.ipynb: explains how to test notebooks with pytest and includes an intentionally erroring cell with a modification of the notebook's configuration to allow it to be run in CI without failing
    • quadratic_factoring_game.ipynb: Notebook that demonstrates logic sig factoring game
  • setup.py: new Jupyter notebooks requirements, and declaration for receiving projects that this package is typed
  • tests
    • integration/
      • abi_test.py: adding the roundtrip test that iterates over teal files in tests/teal/roundtrip and based on the filename encodes a random ABI instance and runs the roundtrip teal program on it via dry-run. In particular includes "round trips" test preparer that:
      1. generates random abi-type arguments
      2. run a dry-run program against them that decode and then manipulate using a self-invertible function f and return (x, f(x), f(f(x)))
      • algod_test.py: separate out the test that algod is alive and well into a seperate integration test, for easier debugging
      • blackbox_test.py: small refactoring, mostly for mypy
      • dryrun_mixin_docs_test.py: refactoring mostly due to deprecations
      • lsig_test.py: test that was described during an April Demo and which
    • teal/ directory - many teal programs created via PyTEAL which are used for dry-run tests
      • roundtrip/ - roundtrip teal programs used by abi_test.py

Copy link
Contributor

@michaeldiamant michaeldiamant left a comment

Choose a reason for hiding this comment

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

@tzaffi Great work here to improve our correctness confidence! ☕

Add provenance note for lsig_factorizer_game_1_5_7.teal
@tzaffi tzaffi merged commit 4647e35 into main May 18, 2022
@tzaffi tzaffi deleted the t-m-j branch May 18, 2022 21:10
@tzaffi tzaffi mentioned this pull request May 24, 2022
3 tasks
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.

2 participants