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: algorand-python-testing preview integration #28

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ audit = { commands = [
], description = 'Audit with pip-audit' }
lint = { commands = [
'poetry run black --check .',
'poetry run ruff .',
'poetry run ruff check .',
'poetry run mypy',
], description = 'Perform linting' }
audit-teal = { commands = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ node_modules

# AlgoKit
debug_traces/

.algokit/static-analysis/tealer/
.algokit/sources
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
entry: poetry run ruff
language: system
types: [ python ]
args: [ --fix ]
args: [ "check", "--fix" ]
require_serial: false
additional_dependencies: [ ]
minimum_pre_commit_version: '0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ For pull requests and pushes to `main` branch against this repository the follow
- Code formatting is checked using [Black](https://github.com/psf/black)
- Linting is checked using [Ruff](https://github.com/charliermarsh/ruff)
- Types are checked using [mypy](https://mypy-lang.org/)
- Python tests are executed using [pytest](https://docs.pytest.org/)
- The base framework for testing is [pytest](https://docs.pytest.org/), and the project includes two separate kinds of tests:
- - `Algorand Python` smart contract unit tests, that are run using [`algorand-python-testing`](https://pypi.org/project/algorand-python-testing/), which are executed in a Python intepreter emulating major AVM behaviour
- - Python `ApplicationClient` tests that are run against `algokit localnet` and test the behaviour in a real network enviornment
- Smart contract artifacts are built
- Smart contract artifacts are checked for [output stability](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/articles/output_stability.md)
- Smart contract is deployed to a AlgoKit LocalNet instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
algokit-utils = "^2.2.0"
algokit-utils = "^2.3.0"
python-dotenv = "^1.0.0"
algorand-python = "^1.0.0"
algorand-python-testing = {git = "https://github.com/algorandfoundation/puya.git", rev = "feat/unit-testing", subdirectory = "algopy_testing"}

[tool.poetry.group.dev.dependencies]
algokit-client-generator = "^1.1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

from dotenv import load_dotenv

from smart_contracts.config import contracts
from smart_contracts.helpers.build import build
from smart_contracts.helpers.deploy import deploy
from smart_contracts.helpers.util import find_app_spec_file
from smart_contracts._helpers.build import build
from smart_contracts._helpers.deploy import deploy
from smart_contracts._helpers.util import find_app_spec_file

# Uncomment the following lines to enable auto generation of AVM Debugger compliant sourcemap and simulation trace file.
# Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of
# Algorand transactions in atomic groups -> https://github.com/algorandfoundation/algokit-avm-vscode-debugger
# from algokit_utils.config import config
# config.configure(debug=True, trace_all=True)
from smart_contracts.config import contracts
logging.basicConfig(
level=logging.DEBUG, format="%(asctime)s %(levelname)-10s: %(message)s"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from shutil import rmtree

from smart_contracts.helpers.util import find_app_spec_file
from smart_contracts._helpers.util import find_app_spec_file

logger = logging.getLogger(__name__)
deployment_extension = "py"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections.abc import Generator

import pytest
from algopy_testing import AlgopyTestContext, algopy_testing_context

from smart_contracts.hello_world.contract import HelloWorld


@pytest.fixture()
def context() -> Generator[AlgopyTestContext, None, None]:
with algopy_testing_context() as ctx:
yield ctx
ctx.reset()


def test_hello(context: AlgopyTestContext) -> None:
# Arrange
dummy_input = context.any_string()
contract = HelloWorld()

# Act
output = contract.hello(dummy_input)

# Assert
assert output == f"Hello, {dummy_input}"
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ audit = { commands = [
], description = 'Audit with pip-audit' }
lint = { commands = [
'poetry run black --check .',
'poetry run ruff .',
'poetry run ruff check .',
'poetry run mypy',
], description = 'Perform linting' }
audit-teal = { commands = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ node_modules

# AlgoKit
debug_traces/

.algokit/static-analysis/tealer/
.algokit/sources
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
entry: poetry run ruff
language: system
types: [ python ]
args: [ --fix ]
args: [ "check", "--fix" ]
require_serial: false
additional_dependencies: [ ]
minimum_pre_commit_version: '0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ For pull requests and pushes to `main` branch against this repository the follow
- Code formatting is checked using [Black](https://github.com/psf/black)
- Linting is checked using [Ruff](https://github.com/charliermarsh/ruff)
- Types are checked using [mypy](https://mypy-lang.org/)
- Typescript `ApplicationClient` tests against `algokit localnet` are executed using [jest](https://jestjs.io/)
- Smart contract artifacts are built
- Smart contract artifacts are checked for [output stability](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/articles/output_stability.md)
- Smart contract is deployed to a AlgoKit LocalNet instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
algokit-utils = "^2.2.0"
algokit-utils = "^2.3.0"
python-dotenv = "^1.0.0"
algorand-python = "^1.0.0"
algorand-python-testing = {git = "https://github.com/algorandfoundation/puya.git", rev = "feat/unit-testing", subdirectory = "algopy_testing"}

[tool.poetry.group.dev.dependencies]
black = {extras = ["d"], version = "*"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from dotenv import load_dotenv

from smart_contracts.config import contracts
from smart_contracts.helpers.build import build
from smart_contracts._helpers.build import build

logging.basicConfig(
level=logging.DEBUG, format="%(asctime)s %(levelname)-10s: %(message)s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from shutil import rmtree

from smart_contracts.helpers.util import find_app_spec_file
from smart_contracts._helpers.util import find_app_spec_file

logger = logging.getLogger(__name__)
deployment_extension = "ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ node_modules

# AlgoKit
debug_traces/

.algokit/static-analysis/tealer/
.algokit/sources
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
algokit-utils = "^2.2.0"
algokit-utils = "^2.3.0"
python-dotenv = "^1.0.0"
algorand-python = "^1.0.0"
algorand-python-testing = {git = "https://github.com/algorandfoundation/puya.git", rev = "feat/unit-testing", subdirectory = "algopy_testing"}

[tool.poetry.group.dev.dependencies]
algokit-client-generator = "^1.1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from dotenv import load_dotenv

from smart_contracts._helpers.build import build
from smart_contracts._helpers.deploy import deploy
from smart_contracts._helpers.util import find_app_spec_file
from smart_contracts.config import contracts
from smart_contracts.helpers.build import build
from smart_contracts.helpers.deploy import deploy
from smart_contracts.helpers.util import find_app_spec_file

# Uncomment the following lines to enable auto generation of AVM Debugger compliant sourcemap and simulation trace file.
# Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from shutil import rmtree

from smart_contracts.helpers.util import find_app_spec_file
from smart_contracts._helpers.util import find_app_spec_file

logger = logging.getLogger(__name__)
deployment_extension = "py"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ node_modules

# AlgoKit
debug_traces/

.algokit/static-analysis/tealer/
.algokit/sources
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
algokit-utils = "^2.2.0"
algokit-utils = "^2.3.0"
python-dotenv = "^1.0.0"
algorand-python = "^1.0.0"
algorand-python-testing = {git = "https://github.com/algorandfoundation/puya.git", rev = "feat/unit-testing", subdirectory = "algopy_testing"}

[tool.poetry.group.dev.dependencies]
puyapy = "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from dotenv import load_dotenv

from smart_contracts.config import contracts
from smart_contracts.helpers.build import build
from smart_contracts._helpers.build import build

logging.basicConfig(
level=logging.DEBUG, format="%(asctime)s %(levelname)-10s: %(message)s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from shutil import rmtree

from smart_contracts.helpers.util import find_app_spec_file
from smart_contracts._helpers.util import find_app_spec_file

logger = logging.getLogger(__name__)
deployment_extension = "ts"
Expand Down
2 changes: 1 addition & 1 deletion examples/production_python/.algokit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ audit = { commands = [
], description = 'Audit with pip-audit' }
lint = { commands = [
'poetry run black --check .',
'poetry run ruff .',
'poetry run ruff check .',
'poetry run mypy',
], description = 'Perform linting' }
audit-teal = { commands = [
Expand Down
2 changes: 1 addition & 1 deletion examples/production_python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ node_modules

# AlgoKit
debug_traces/

.algokit/static-analysis/tealer/
.algokit/sources
2 changes: 1 addition & 1 deletion examples/production_python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
entry: poetry run ruff
language: system
types: [ python ]
args: [ --fix ]
args: [ "check", "--fix" ]
require_serial: false
additional_dependencies: [ ]
minimum_pre_commit_version: '0'
Expand Down
4 changes: 3 additions & 1 deletion examples/production_python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ For pull requests and pushes to `main` branch against this repository the follow
- Code formatting is checked using [Black](https://github.com/psf/black)
- Linting is checked using [Ruff](https://github.com/charliermarsh/ruff)
- Types are checked using [mypy](https://mypy-lang.org/)
- Python tests are executed using [pytest](https://docs.pytest.org/)
- The base framework for testing is [pytest](https://docs.pytest.org/), and the project includes two separate kinds of tests:
- - `Algorand Python` smart contract unit tests, that are run using [`algorand-python-testing`](https://pypi.org/project/algorand-python-testing/), which are executed in a Python intepreter emulating major AVM behaviour
- - Python `ApplicationClient` tests that are run against `algokit localnet` and test the behaviour in a real network enviornment
- Smart contract artifacts are built
- Smart contract artifacts are checked for [output stability](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/articles/output_stability.md)
- Smart contract is deployed to a AlgoKit LocalNet instance
Expand Down
3 changes: 2 additions & 1 deletion examples/production_python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
algokit-utils = "^2.2.0"
algokit-utils = "^2.3.0"
python-dotenv = "^1.0.0"
algorand-python = "^1.0.0"
algorand-python-testing = {git = "https://github.com/algorandfoundation/puya.git", rev = "feat/unit-testing", subdirectory = "algopy_testing"}

[tool.poetry.group.dev.dependencies]
algokit-client-generator = "^1.1.3"
Expand Down
6 changes: 3 additions & 3 deletions examples/production_python/smart_contracts/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from dotenv import load_dotenv

from smart_contracts._helpers.build import build
from smart_contracts._helpers.deploy import deploy
from smart_contracts._helpers.util import find_app_spec_file
from smart_contracts.config import contracts
from smart_contracts.helpers.build import build
from smart_contracts.helpers.deploy import deploy
from smart_contracts.helpers.util import find_app_spec_file

# Uncomment the following lines to enable auto generation of AVM Debugger compliant sourcemap and simulation trace file.
# Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from shutil import rmtree

from smart_contracts.helpers.util import find_app_spec_file
from smart_contracts._helpers.util import find_app_spec_file

logger = logging.getLogger(__name__)
deployment_extension = "py"
Expand Down
25 changes: 25 additions & 0 deletions examples/production_python/tests/hello_world_client_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections.abc import Generator

import pytest
from algopy_testing import AlgopyTestContext, algopy_testing_context

from smart_contracts.hello_world.contract import HelloWorld


@pytest.fixture()
def context() -> Generator[AlgopyTestContext, None, None]:
with algopy_testing_context() as ctx:
yield ctx
ctx.reset()


def test_hello(context: AlgopyTestContext) -> None:
# Arrange
dummy_input = context.any_string()
contract = HelloWorld()

# Act
output = contract.hello(dummy_input)

# Assert
assert output == f"Hello, {dummy_input}"
2 changes: 1 addition & 1 deletion examples/starter_python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ node_modules

# AlgoKit
debug_traces/

.algokit/static-analysis/tealer/
.algokit/sources
3 changes: 2 additions & 1 deletion examples/starter_python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
algokit-utils = "^2.2.0"
algokit-utils = "^2.3.0"
python-dotenv = "^1.0.0"
algorand-python = "^1.0.0"
algorand-python-testing = {git = "https://github.com/algorandfoundation/puya.git", rev = "feat/unit-testing", subdirectory = "algopy_testing"}

[tool.poetry.group.dev.dependencies]
algokit-client-generator = "^1.1.3"
Expand Down
6 changes: 3 additions & 3 deletions examples/starter_python/smart_contracts/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from dotenv import load_dotenv

from smart_contracts._helpers.build import build
from smart_contracts._helpers.deploy import deploy
from smart_contracts._helpers.util import find_app_spec_file
from smart_contracts.config import contracts
from smart_contracts.helpers.build import build
from smart_contracts.helpers.deploy import deploy
from smart_contracts.helpers.util import find_app_spec_file

# Uncomment the following lines to enable auto generation of AVM Debugger compliant sourcemap and simulation trace file.
# Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from shutil import rmtree

from smart_contracts.helpers.util import find_app_spec_file
from smart_contracts._helpers.util import find_app_spec_file

logger = logging.getLogger(__name__)
deployment_extension = "py"
Expand Down
2 changes: 1 addition & 1 deletion template_content/.algokit.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ lint = { commands = [
'poetry run black --check .',
{%- endif %}
{%- if python_linter == 'ruff' %}
'poetry run ruff .',
'poetry run ruff check .',
{%- elif python_linter == 'flake8' %}
'poetry run flake8 .',
{%- endif %}
Expand Down
Loading
Loading