generated from algorandfoundation/algokit-beaker-default-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: algorand-python-testing preview integration (#28)
* feat: algorand-python-testing preview integration * chore: patching bugs * chore: patching artifacts
- Loading branch information
1 parent
5fdabda
commit 3a70b80
Showing
32 changed files
with
237 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,5 +176,5 @@ node_modules | |
|
||
# AlgoKit | ||
debug_traces/ | ||
|
||
.algokit/static-analysis/tealer/ | ||
.algokit/sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
examples/generators/production_python_smart_contract_python/tests/hello_world_client_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import algokit_utils | ||
import pytest | ||
from algokit_utils import get_localnet_default_account | ||
from algokit_utils.config import config | ||
from algosdk.v2client.algod import AlgodClient | ||
from algosdk.v2client.indexer import IndexerClient | ||
|
||
from smart_contracts.artifacts.hello_world.client import HelloWorldClient | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def hello_world_client( | ||
algod_client: AlgodClient, indexer_client: IndexerClient | ||
) -> HelloWorldClient: | ||
config.configure( | ||
debug=True, | ||
# trace_all=True, | ||
) | ||
|
||
client = HelloWorldClient( | ||
algod_client, | ||
creator=get_localnet_default_account(algod_client), | ||
indexer_client=indexer_client, | ||
) | ||
|
||
client.deploy( | ||
on_schema_break=algokit_utils.OnSchemaBreak.AppendApp, | ||
on_update=algokit_utils.OnUpdate.AppendApp, | ||
) | ||
return client | ||
|
||
|
||
def test_says_hello(hello_world_client: HelloWorldClient) -> None: | ||
result = hello_world_client.hello(name="World") | ||
|
||
assert result.return_value == "Hello, World" | ||
|
||
|
||
def test_simulate_says_hello_with_correct_budget_consumed( | ||
hello_world_client: HelloWorldClient, algod_client: AlgodClient | ||
) -> None: | ||
result = ( | ||
hello_world_client.compose().hello(name="World").hello(name="Jane").simulate() | ||
) | ||
|
||
assert result.abi_results[0].return_value == "Hello, World" | ||
assert result.abi_results[1].return_value == "Hello, Jane" | ||
assert result.simulate_response["txn-groups"][0]["app-budget-consumed"] < 100 |
57 changes: 17 additions & 40 deletions
57
examples/generators/production_python_smart_contract_python/tests/hello_world_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,25 @@ | ||
import algokit_utils | ||
import pytest | ||
from algokit_utils import get_localnet_default_account | ||
from algokit_utils.config import config | ||
from algosdk.v2client.algod import AlgodClient | ||
from algosdk.v2client.indexer import IndexerClient | ||
|
||
from smart_contracts.artifacts.hello_world.client import HelloWorldClient | ||
|
||
from collections.abc import Generator | ||
|
||
@pytest.fixture(scope="session") | ||
def hello_world_client( | ||
algod_client: AlgodClient, indexer_client: IndexerClient | ||
) -> HelloWorldClient: | ||
config.configure( | ||
debug=True, | ||
# trace_all=True, | ||
) | ||
|
||
client = HelloWorldClient( | ||
algod_client, | ||
creator=get_localnet_default_account(algod_client), | ||
indexer_client=indexer_client, | ||
) | ||
import pytest | ||
from algopy_testing import AlgopyTestContext, algopy_testing_context | ||
|
||
client.deploy( | ||
on_schema_break=algokit_utils.OnSchemaBreak.AppendApp, | ||
on_update=algokit_utils.OnUpdate.AppendApp, | ||
) | ||
return client | ||
from smart_contracts.hello_world.contract import HelloWorld | ||
|
||
|
||
def test_says_hello(hello_world_client: HelloWorldClient) -> None: | ||
result = hello_world_client.hello(name="World") | ||
@pytest.fixture() | ||
def context() -> Generator[AlgopyTestContext, None, None]: | ||
with algopy_testing_context() as ctx: | ||
yield ctx | ||
ctx.reset() | ||
|
||
assert result.return_value == "Hello, World" | ||
|
||
def test_hello(context: AlgopyTestContext) -> None: | ||
# Arrange | ||
dummy_input = context.any_string() | ||
contract = HelloWorld() | ||
|
||
def test_simulate_says_hello_with_correct_budget_consumed( | ||
hello_world_client: HelloWorldClient, algod_client: AlgodClient | ||
) -> None: | ||
result = ( | ||
hello_world_client.compose().hello(name="World").hello(name="Jane").simulate() | ||
) | ||
# Act | ||
output = contract.hello(dummy_input) | ||
|
||
assert result.abi_results[0].return_value == "Hello, World" | ||
assert result.abi_results[1].return_value == "Hello, Jane" | ||
assert result.simulate_response["txn-groups"][0]["app-budget-consumed"] < 100 | ||
# Assert | ||
assert output == f"Hello, {dummy_input}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,5 +176,5 @@ node_modules | |
|
||
# AlgoKit | ||
debug_traces/ | ||
|
||
.algokit/static-analysis/tealer/ | ||
.algokit/sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,5 +176,5 @@ node_modules | |
|
||
# AlgoKit | ||
debug_traces/ | ||
|
||
.algokit/static-analysis/tealer/ | ||
.algokit/sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,5 +176,5 @@ node_modules | |
|
||
# AlgoKit | ||
debug_traces/ | ||
|
||
.algokit/static-analysis/tealer/ | ||
.algokit/sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,5 +176,5 @@ node_modules | |
|
||
# AlgoKit | ||
debug_traces/ | ||
|
||
.algokit/static-analysis/tealer/ | ||
.algokit/sources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
examples/production_python/tests/hello_world_client_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import algokit_utils | ||
import pytest | ||
from algokit_utils import get_localnet_default_account | ||
from algokit_utils.config import config | ||
from algosdk.v2client.algod import AlgodClient | ||
from algosdk.v2client.indexer import IndexerClient | ||
|
||
from smart_contracts.artifacts.hello_world.client import HelloWorldClient | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def hello_world_client( | ||
algod_client: AlgodClient, indexer_client: IndexerClient | ||
) -> HelloWorldClient: | ||
config.configure( | ||
debug=True, | ||
# trace_all=True, | ||
) | ||
|
||
client = HelloWorldClient( | ||
algod_client, | ||
creator=get_localnet_default_account(algod_client), | ||
indexer_client=indexer_client, | ||
) | ||
|
||
client.deploy( | ||
on_schema_break=algokit_utils.OnSchemaBreak.AppendApp, | ||
on_update=algokit_utils.OnUpdate.AppendApp, | ||
) | ||
return client | ||
|
||
|
||
def test_says_hello(hello_world_client: HelloWorldClient) -> None: | ||
result = hello_world_client.hello(name="World") | ||
|
||
assert result.return_value == "Hello, World" | ||
|
||
|
||
def test_simulate_says_hello_with_correct_budget_consumed( | ||
hello_world_client: HelloWorldClient, algod_client: AlgodClient | ||
) -> None: | ||
result = ( | ||
hello_world_client.compose().hello(name="World").hello(name="Jane").simulate() | ||
) | ||
|
||
assert result.abi_results[0].return_value == "Hello, World" | ||
assert result.abi_results[1].return_value == "Hello, Jane" | ||
assert result.simulate_response["txn-groups"][0]["app-budget-consumed"] < 100 |
Oops, something went wrong.