Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
9339659
feat: work in progress on asset, application related state ops
aorumbayev Jul 12, 2024
96b0f55
test: adding extra tests
aorumbayev Jul 15, 2024
4a3f6c5
feat: extra tests and implementation wrappers around AppLocal
aorumbayev Jul 24, 2024
b47e6e7
chore: wip
aorumbayev Jul 25, 2024
834e478
chore: update src/algopy_testing/op.py
aorumbayev Jul 25, 2024
6473839
Merge remote-tracking branch 'origin/main' into feat/state_ops
aorumbayev Jul 25, 2024
6d8dc69
feat: adding acctparamsget; extra tests; pr comments
aorumbayev Jul 25, 2024
5ac0ab5
refactor: adding final bits around AcctParamsGet; unit tests and fixes
aorumbayev Jul 26, 2024
f27d612
refactor: adding lookup by index to acct/app/asset get ops; tweaking ci
aorumbayev Jul 26, 2024
59f4759
Merge branch 'main' into feat/state_ops
aorumbayev Jul 26, 2024
762eeda
refactor: addressing pr comments
aorumbayev Jul 30, 2024
8ec62b9
chore: fixing failing test
aorumbayev Jul 30, 2024
81439fb
Merge branch 'main' into feat/state_ops
aorumbayev Jul 30, 2024
c4dad80
refactor: simplifying test_context validation
aorumbayev Jul 30, 2024
ecf4f9c
use specific enum types in box example with latest puya version
daniel-makerx Jul 31, 2024
afacb2f
include box types in algopy_testing
daniel-makerx Jul 31, 2024
c6463ce
fix inconsistent usage of field names on application fields
daniel-makerx Jul 31, 2024
9e093b3
expose fields property on application to aid debugging
daniel-makerx Jul 31, 2024
0f269e9
added section to CONTRIBUTING.md describing relationship between `alg…
daniel-makerx Jul 31, 2024
619ab5b
remove lazy algopy imports from utils
daniel-makerx Jul 31, 2024
89485a1
simplify abimethod and add TODO's
daniel-makerx Jul 31, 2024
ad8217f
add TODO for state totals
daniel-makerx Jul 31, 2024
aeb36e0
add some tests (including currently failing ones) for app transactions
daniel-makerx Jul 31, 2024
bc469bd
feat: add arc4factory
aorumbayev Jul 31, 2024
407ef88
refactor: ensuring underlying _key is properly reflected on local/glo…
aorumbayev Jul 31, 2024
a01cccf
refactor: change guards for setting keys to explicitly check for None
daniel-makerx Aug 1, 2024
b57f638
refactor: use implementation types in internal mappings
daniel-makerx Aug 1, 2024
b8da9be
refactor: remove usages of `import algopy` from op.py, remove explici…
daniel-makerx Aug 1, 2024
88dfca2
test: use non-abstract contract base
daniel-makerx Aug 1, 2024
6fdcb7b
allow empty box prefix
daniel-makerx Aug 1, 2024
3474ce4
refactor
daniel-makerx Aug 1, 2024
f8e5adc
use immutable param defaults
daniel-makerx Aug 1, 2024
1d4f304
fix: handle populating foreign arrays correctly for abi method calls
daniel-makerx Aug 1, 2024
9be08cd
refactor: remove lazy import algopy
daniel-makerx Aug 1, 2024
4a9dafd
remove irrelevant comment
daniel-makerx Aug 1, 2024
b226c9e
initialize accounts correctly
daniel-makerx Aug 1, 2024
6933f7d
build: adding post install command into examples venv in hatch settings
aorumbayev Aug 1, 2024
9c85e30
refactor: refine arc4 factory; add corresponding tests
aorumbayev Aug 1, 2024
0d8fc44
chore: adding the missing clear methods
aorumbayev Aug 1, 2024
34b44dd
chore: merging everything from docs branch except docs changes
aorumbayev Aug 3, 2024
dc133fe
chore: merge conflicts
aorumbayev Aug 3, 2024
e2d281f
chore: merge non docs changes from docs branch to simplify docs pr scope
aorumbayev Aug 3, 2024
2c66231
refactor: simplify txn implementations
daniel-makerx Aug 5, 2024
00637bd
docs: adding pep257 formatter; using reST docstrings style for contex…
aorumbayev Aug 5, 2024
bfa98d4
test: adding tests for scratch slots
aorumbayev Aug 5, 2024
184e57a
refactor: renaming set_txn_fields -> scoped_txn_fields
aorumbayev Aug 5, 2024
a0359d5
chore: adding `amount` field and open question under TODO;
aorumbayev Aug 5, 2024
710c1ec
chore: bumping ruff
aorumbayev Aug 5, 2024
eaad3f5
refactor: adding context manager for lsig args setup (similar to algo…
aorumbayev Aug 5, 2024
5596a1b
refactor: move helper classes into their own file
daniel-makerx Aug 6, 2024
2c39c79
refactor: simplify itxn loader
daniel-makerx Aug 6, 2024
913428a
refactor: isolate get_test_context to reduce circular imports
daniel-makerx Aug 6, 2024
a3cbf96
chore: using multiprocessing in refresh test artifacts script
aorumbayev Aug 6, 2024
dbc941f
refactor: adding tests for ITxn, ITxnCreate and GITxn, fixing related…
aorumbayev Aug 6, 2024
72f6284
refactor: default_creator -> default_sender; setting creator as defau…
aorumbayev Aug 6, 2024
ea041f8
chore: parsing name to op name in ITxn
aorumbayev Aug 6, 2024
a597cf3
chore: updating default extension for mypy to use ms-python
aorumbayev Aug 6, 2024
5ecad99
test: remove incorrect test and replace with TODO
daniel-makerx Aug 7, 2024
ed456ea
chore: add TODO about subroutine support
daniel-makerx Aug 7, 2024
ca06dc9
add stricter type checks for primitives
daniel-makerx Aug 7, 2024
20e2ec3
track when contracts are in a "creating" state or not
daniel-makerx Aug 7, 2024
a12df9e
todos
daniel-makerx Aug 7, 2024
95facfc
refactor: moving GITxn class to itxn.py
aorumbayev Aug 7, 2024
a1ee760
refactor: generate arc4 signatures from types
daniel-makerx Aug 7, 2024
c4023c8
only support native tuples when handling generic aliases in arc4 tuples
daniel-makerx Aug 7, 2024
2b83bef
refactor: 1/2 adding paged access to clear state program in txn fields
aorumbayev Aug 7, 2024
3a00099
refactor: consolidating txn and itxn related context attributes/methods
aorumbayev Aug 7, 2024
1fceafd
minor refactors
daniel-makerx Aug 8, 2024
075ebc1
support arc4 structs
daniel-makerx Aug 8, 2024
7fa0f5b
refactor: simplify logic sig implementation, and remove mapping
daniel-makerx Aug 8, 2024
6152c9d
refactor: fix itxn op behaviour with program pages, and other array l…
daniel-makerx Aug 8, 2024
5803b23
refactor: simplify account properties
daniel-makerx Aug 8, 2024
e7e1727
refactor: move crypto ops into their own module
daniel-makerx Aug 8, 2024
3ea53f5
refactor: move pure ops into their own module
daniel-makerx Aug 8, 2024
8228373
refactor: move other misc ops
daniel-makerx Aug 8, 2024
7d44c36
refactor: consolidating value generators; ledger and txn contexts;
aorumbayev Aug 8, 2024
5acaa41
refactor: add active group/txn properties
daniel-makerx Aug 9, 2024
68c13d2
refactor: remove nested private modules, replace usages of get_test_c…
daniel-makerx Aug 9, 2024
47b9067
refactor: move inner transactions onto transaction group
daniel-makerx Aug 9, 2024
adb4e22
refactor: remove scoped_lsig_args
daniel-makerx Aug 9, 2024
fa15509
refactor: remove maybe_active_app_id
daniel-makerx Aug 9, 2024
0cddd0b
refactor: include bool in test for uint64
daniel-makerx Aug 9, 2024
7fde7aa
refactor: ensure arc4 values always have fully parametrized types
daniel-makerx Aug 9, 2024
de3f486
refactor: use _paramatize_type
daniel-makerx Aug 9, 2024
aa83699
refactor: addressing TODOs
aorumbayev Aug 11, 2024
c3ada65
refactor: adding unit tests for global/local state with implicit keys
aorumbayev Aug 12, 2024
bcd3ee9
refactor: improving handling of initial value for implicit global/loc…
aorumbayev Aug 12, 2024
2cda537
test: extra test cases for accessing implicit/explicit keyed local/gl…
aorumbayev Aug 12, 2024
0cb6f32
refactor: wip adding txn_group_for method
aorumbayev Aug 12, 2024
738270c
chore: fix linting errors
daniel-makerx Aug 13, 2024
2ff4d05
feat: continue with txn_group_for and add a test
daniel-makerx Aug 13, 2024
55cbe57
chore: remove scoped_txn_fields methods
daniel-makerx Aug 13, 2024
2f76cf2
add some additional TODO's for scoped_execution
daniel-makerx Aug 13, 2024
41a737b
remove TODO
daniel-makerx Aug 13, 2024
dca3508
expand gaid TODO
daniel-makerx Aug 13, 2024
1638224
tweak op.exit implementation and add TODO
daniel-makerx Aug 13, 2024
3ae8c61
remove arc4 property from AlgopyTestContext
daniel-makerx Aug 13, 2024
7ed869b
add more TODOs
daniel-makerx Aug 13, 2024
b9d8a77
refactor: addressing TODOs; adding marketplace contract example (devr…
aorumbayev Aug 13, 2024
a41a356
test: fixing failing tests
aorumbayev Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
cache: "pip"

- name: Start LocalNet
run: hatch run cicd:localnet_start
run: pipx install algokit && algokit localnet start

- name: Check pre-commits
run: hatch run check
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Check Python Code (algopy_testing)
on:
workflow_call:
pull_request:
schedule:
- cron: "0 8 * * 1" # Each monday 8 AM UTC

jobs:
check-python:
Expand All @@ -21,14 +23,17 @@ jobs:
cache: "pip"

- name: Start LocalNet
run: hatch run cicd:localnet_start
run: pipx install algokit && algokit localnet start

- name: Check pre-commits
run: hatch run check

- name: Check pre-commits (examples)
run: hatch run examples:check

- name: Validate examples folder
run: hatch run validate_examples

- name: Check wheels can be built
run: hatch build

Expand Down
10 changes: 1 addition & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
repos:
- repo: local
hooks:
- id: pre-commit
- id: pre-commit (src & examples)
name: pre-commit
description: "Run pre-commit task via hatch"
entry: hatch run pre_commit
language: system
additional_dependencies: []
minimum_pre_commit_version: "0"

- id: examples-pre-commit
name: examples-pre-commit
description: "Run examples venv pre-commit task via hatch"
entry: hatch run examples:pre_commit
language: system
additional_dependencies: []
minimum_pre_commit_version: "0"
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"ms-python.python",
"charliermarsh.ruff",
"ms-python.mypy-type-checker",
"ms-python.black-formatter",
"tamasfe.even-better-toml",
"editorconfig.editorconfig"
]
}
13 changes: 7 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
"ruff.codeAction.fixViolation": {
"enable": true
},

"mypy.configFile": "pyproject.toml",
// set to empty array to use config from project
"mypy.targets": ["--cache-dir=/dev/null"],
"mypy.runUsingActiveInterpreter": true,
"cSpell.words": ["addw", "mulw"]
"mypy-type-checker.importStrategy": "fromEnvironment",
"mypy-type-checker.args": [
"--enable-incomplete-feature=Unpack",
"--config-file=pyproject.toml",
"--strict",
"--show-column-numbers"
]
}
56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,59 @@ Examples folder uses a dedicated 'venv.examples' virtual environment managed by
Project relies on [python-semantic-release](https://python-semantic-release.readthedocs.io/en/latest/) for release automation.

Releases are triggered by a `workflow_dispatch` event on the `main` branch with `prerelease` set to accordingly using the `.github/workflows/cd.yaml` file.

# Implementation vs Stubs

The canonical definition of the algopy API comes from the [`alogrand-python`](https://pypi.org/project/algorand-python/) package which consists only of typing information defined in the `algopy-stubs` module.
In this library the testing implementation should follow the "shape" of the API defined in these stubs. In particular, types, methods and attributes should reflect what is described in the stubs.

However, implementation specific details can diverge from what is described in the stubs. For example methods marked as `@staticmethod` in the stubs do not need to be static methods in the implementation.
Implementation types may provide more methods or properties than described in the stubs, the stubs are just the minimal set of what should be defined.

The `algopy_testing` module contains the implementation of the stubs and additional parts of the testing framework.
The `algopy` module is used to alias the relevant `algopy_testing` implementations into the correct namespaces defined in the stubs.

Implementations within `algopy_testing` should use `algopy_testing` types as much as possible, except for typing annotations which should use the `algopy` equivalents instead. A rule of thumb to follow is
withing the `algopy_testing` module, `import algopy` should only be used for type definitions e.g.

```python
import typing

if typing.TYPE_CHECKING:
import algopy

def do_something_with_bytes(a: algopy.Bytes) -> algopy.Bytes:
...
```

Instance checks should be done via the `algopy_testing` namespace, this will ensure any additional attributes on the implementation will be type checked correctly e.g.

```python
import algopy_testing


def do_something(value: object) -> None:
if isinstance(value, algopy_testing.Bytes):
raw_bytes: bytes = value.value
...
```

Occasionally this will require silencing Mypy warnings, within the scope of the implementation code this is considered acceptable.

```python
import typing

import algopy_testing

if typing.TYPE_CHECKING:
import algopy

def get_some_bytes() -> algopy.Bytes:
value = algopy_testing.Bytes(b"42")
# in the following statement, the return type warning is silenced as
# algopy.Bytes is an alias of algopy_testing.Bytes
return value # type: ignore[return-value]
```



14 changes: 7 additions & 7 deletions docs/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ See which `algorand-python` stubs are implemented by the `algorand-python-testin
| Primitives (UInt64, BigUInt, Bytes, String) | Implemented |
| urange | Implemented |
| All crypto ops in op.\* namespace (to be expanded in detail) | Implemented |
| Txn, GTxn, ITxn | Implemented |
| arc4.\* namespace (to be expanded in detail) | Implemented |
| uenumerate | Implemented |
| op.ITxnCreate | Implemented |
| StateTotals | Implemented |
| Txn, GTxn, ITxn | Emulated |
| Asset | Emulated |
| Account | Emulated |
| Application | Emulated |
Expand All @@ -34,10 +33,11 @@ See which `algorand-python` stubs are implemented by the `algorand-python-testin
| log | Emulated |
| itxn.\* namespace (inner transactions) | Emulated |
| gtxn.\* namespace (group transactions) | Emulated |
| op.ITxnCreate | Emulated |
| ensure_budget | Mockable |
| op.EllipticCurve | Mockable |
| op.AssetParamsGet | Mockable |
| op.AppParamsGet | Mockable |
| op.AppLocal | Mockable |
| op.AppGlobal | Mockable |
| op.AcctParamsGet | Mockable |
| op.AssetParamsGet | Emulated |
| op.AppParamsGet | Emulated |
| op.AppLocal | Emulated |
| op.AppGlobal | Emulated |
| op.AcctParamsGet | Emulated |
56 changes: 56 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Algorand Python Testing examples

This directory contains examples demonstrating how to use algorand-python-testing to test smart contracts written in Algorand Python.

## Overview

`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.

## Key Features

1. **Test Environment Setup**: Use the `context` fixture to set up a test environment that emulates AVM behavior.
2. **Arrange, Act, Assert Pattern**: Examples follow the 'arrange, act, assert' pattern for clear and structured tests.
3. **Asset and Account Creation**: Easily create test assets and accounts using `context.any.asset` and `context.any.account`.
4. **State Manipulation**: Test global and local state changes in your smart contracts.
5. **ABI Method Testing**: Examples of how to test ABI methods in your smart contracts.

## Quickstart

To run the examples in a self-contained manner:

1. Install [hatch](https://hatch.pypa.io/latest/)
2. From the root of the repo, run:

```bash
hatch run examples:test examples/<example_directory>
```

Replace `<example_directory>` with the specific example you want to run (e.g., `auction`, `abi`, etc.).

## Writing Tests

When writing tests for your Algorand smart contracts:

1. Use the `context` fixture to set up your test environment.
2. Create test assets and accounts as needed using `context.any.asset` and `context.any.account`.
3. Interact with your smart contract methods.
4. Assert the expected outcomes, including state changes and transaction results.

For detailed examples, refer to the individual test files in each example directory.

## Contributing

If you have additional examples or improvements, feel free to contribute by submitting a pull request.

1. Follow the [contribution guidelines](https://github.com/algorandfoundation/algorand-python-testing/blob/main/CONTRIBUTING.md).
2. Create a new folder under `examples/` with your contract/signature and test files.
3. If you are contributing a smart contract example make sure to name the file `contract.py`. For logic signatures, name it `signature.py`.
4. For test files use `test_contract.py` or `test_signature.py` respectively.
5. 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-testing` it demonstrates.

## Resources

- [Algorand Developer Documentation](https://developer.algorand.org/)
- [algorand-python](https://algorandfoundation.github.io/puya/)
- [algorand-python-testing](https://algorandfoundation.github.io/algorand-python-testing/)
- ['arrange, act, assert' patern](https://automationpanda.com/2020/07/07/arrange-act-assert-a-pattern-for-writing-good-tests/)
Loading