This directory contains examples demonstrating how to use algorand-python-testing to test smart contracts written in Algorand Python.
algorand-python-testing provides a powerful framework for unit testing Algorand smart contracts written in Algorand Python. It allows developers to emulate AVM behavior in a Python interpreter, making it easier to write and run tests for your Algorand applications.
- Test Environment Setup: Use the
contextfixture to set up a test environment that emulates AVM behavior. - Arrange, Act, Assert Pattern: Examples follow the 'arrange, act, assert' pattern for clear and structured tests.
- Asset and Account Creation: Easily create test assets and accounts using
context.any.assetandcontext.any.account. - State Manipulation: Test global and local state changes in your smart contracts.
- ABI Method Testing: Examples of how to test ABI methods in your smart contracts.
To run the examples in a self-contained manner:
- Install hatch
- From the root of the repo, run:
hatch run examples:test examples/<example_directory>Replace <example_directory> with the specific example you want to run (e.g., auction, abi, etc.).
When writing tests for your Algorand smart contracts:
- Use the
contextfixture to set up your test environment. - Create test assets and accounts as needed using
context.any.assetandcontext.any.account. - Interact with your smart contract methods.
- Assert the expected outcomes, including state changes and transaction results.
For detailed examples, refer to the individual test files in each example directory.
If you have additional examples or improvements, feel free to contribute by submitting a pull request.
- Follow the contribution guidelines.
- Create a new folder under
examples/with your contract/signature and test files. - If you are contributing a smart contract example make sure to name the file
contract.py. For logic signatures, name itsignature.py. - For test files use
test_contract.pyortest_signature.pyrespectively. - Use the default PR template when opening a PR, and describe what sort of example are you adding as well as which feature of
algorand-python-testingit demonstrates.