-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: typescript test support and example simulate test
* feat: adding support for typescript tests * feat: support new client generator simulate
- Loading branch information
1 parent
ad9331e
commit 6a21537
Showing
239 changed files
with
1,683 additions
and
833 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
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 @@ | ||
{{- contract_name.split('_')|join('-') -}} |
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 @@ | ||
{{- contract_name.split('_')|map('capitalize')|join -}} |
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,5 +1,5 @@ | ||
[algokit] | ||
min_version = "v1.7.3" | ||
min_version = "v1.8.0" | ||
|
||
[deploy] | ||
{%- if deployment_language == 'python' %} | ||
|
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
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
File renamed without changes.
File renamed without changes.
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
24 changes: 24 additions & 0 deletions
24
... if deployment_language == 'typescript' or use_typescript_jest %}tsconfig.json{% endif %}
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"sourceMap": true, | ||
"strict": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"esModuleInterop": true, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"allowJs": false, | ||
"allowSyntheticDefaultImports": true, | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["node_modules", "dist", "coverage"] | ||
} |
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
58 changes: 36 additions & 22 deletions
58
...%}tests{% endif %}/{% if use_python_pytest %}{{ contract_name }}_test.py{% endif %}.jinja
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,36 +1,50 @@ | ||
import algokit_utils | ||
import pytest | ||
from algokit_utils import ( | ||
ApplicationClient, | ||
ApplicationSpecification, | ||
get_localnet_default_account, | ||
) | ||
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.{{ contract_name }} import contract as {{ contract_name }}_contract | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def {{ contract_name }}_app_spec(algod_client: AlgodClient) -> ApplicationSpecification: | ||
return {{ contract_name }}_contract.app.build(algod_client) | ||
from smart_contracts.artifacts.{{ contract_name }}.client import {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def {{ contract_name }}_client( | ||
algod_client: AlgodClient, {{ contract_name }}_app_spec: ApplicationSpecification | ||
) -> ApplicationClient: | ||
client = ApplicationClient( | ||
algod_client: AlgodClient, indexer_client: IndexerClient | ||
) -> {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client: | ||
config.configure( | ||
debug=True, | ||
# trace_all=True, | ||
) | ||
|
||
client = {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client( | ||
algod_client, | ||
app_spec={{ contract_name }}_app_spec, | ||
signer=get_localnet_default_account(algod_client), | ||
{%- if preset_name == 'production' %} | ||
template_values={"UPDATABLE": 1, "DELETABLE": 1}, | ||
{%- endif %} | ||
creator=get_localnet_default_account(algod_client), | ||
indexer_client=indexer_client, | ||
) | ||
|
||
client.deploy( | ||
on_schema_break=algokit_utils.OnSchemaBreak.ReplaceApp, | ||
on_update=algokit_utils.OnUpdate.UpdateApp, | ||
allow_delete=True, | ||
allow_update=True, | ||
) | ||
client.create() | ||
return client | ||
|
||
|
||
def test_says_hello({{ contract_name }}_client: ApplicationClient) -> None: | ||
result = {{ contract_name }}_client.call({{ contract_name }}_contract.hello, name="World") | ||
def test_says_hello({{ contract_name }}_client: {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client) -> None: | ||
result = {{ contract_name }}_client.hello(name="World") | ||
|
||
assert result.return_value == "Hello, World" | ||
|
||
|
||
def test_simulate_says_hello_with_correct_budget_consumed( | ||
{{ contract_name }}_client: {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client, algod_client: AlgodClient | ||
) -> None: | ||
result = ( | ||
{{ contract_name }}_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 |
16 changes: 16 additions & 0 deletions
16
template_content/{% if use_typescript_jest %}jest.config.ts{% endif %}
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,16 @@ | ||
/* | ||
* For a detailed explanation regarding each configuration property and type check, visit: | ||
* https://jestjs.io/docs/configuration | ||
*/ | ||
import type { Config } from 'jest' | ||
|
||
const config: Config = { | ||
preset: 'ts-jest', | ||
verbose: true, | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
testPathIgnorePatterns: ['node_modules', '.venv', 'coverage'], | ||
testTimeout: 10000, | ||
} | ||
export default config |
Oops, something went wrong.