Skip to content

Commit

Permalink
chore: regen artifacts (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev authored Jul 11, 2024
1 parent ec1417b commit 08e0d5d
Show file tree
Hide file tree
Showing 35 changed files with 404 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 2.1.2
_commit: 2.1.4
_src_path: gh:algorandfoundation/algokit-beaker-default-template
author_email: None
author_name: None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "https://aka.ms/codetour-schema",
"title": "Getting Started with Your AlgoKit Project",
"steps": [
{
"file": "README.md",
"description": "Welcome to your brand new AlgoKit template-based project. In this tour, we will guide you through the main features and capabilities included in the template.",
"line": 3
},
{
"file": "README.md",
"description": "Start by ensuring you have followed the setup of pre-requisites.",
"line": 9
},
{
"file": "smart_contracts/__main__.py",
"description": "This is the main entry point for building your smart contracts. The default template includes a starter 'Hello World' contract that is deployed via the `algokit-utils` package (either `ts` or `py`, depending on your choice). To create a new smart contract, you can use the [`algokit generate`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md) command and invoke a pre-bundled generator template by running `algokit generate smart-contract`. This action will create a new folder in the `smart_contracts` directory, named after your project. Each folder contains a `contract.py` file, which is the entry point for your contract implementation, and `deploy_config.py` | `deployConfig.ts` files (depending on the language chosen for the template), that perform the deployment of the contract.",
"line": 26
},
{
"file": "smart_contracts/hello_world/deploy_config.py",
"description": "The default deployment scripts invoke a sample method on the starter contract that demonstrates how to interact with your deployed Algorand on-chain applications using the [`AlgoKit Typed Clients`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md#1-typed-clients) feature.",
"line": 32
},
{
"file": "tests/hello_world_test.py",
"description": "If you opted to include unit tests, the default tests provided demonstrate an example of mocking, setting up fixtures, and testing smart contract calls on an AlgoKit typed client.",
"line": 36
},
{
"file": ".env.localnet.template",
"description": "Environment files are a crucial mechanism that allows you to set up the [`algokit deploy`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/deploy.md) feature to simplify deploying your contracts in CI/CD environments (please note we still recommend careful evaluation when it comes to deployment to MainNet). Clone the file and remove the `.template` suffix to apply the changes to deployment scripts and launch configurations. The network prefix `localnet|testnet|mainnet` is primarily optimized for `algokit deploy`. The order of loading the variables is `.env.{network}` < `.env`.",
"line": 2
},
{
"file": ".algokit.toml",
"description": "This is the configuration file used by AlgoKit to determine version requirements, `algokit deploy` settings, and references to custom generators.",
"line": 5
},
{
"file": ".vscode/launch.json",
"description": "Refer to the pre-bundled Visual Studio launch configurations, offering various options on how to execute the build and deployment of your smart contracts.",
"line": 5
},
{
"file": ".vscode/extensions.json",
"description": "We highly recommend installing the recommended extensions to get the most out of this template starter project in your VSCode IDE.",
"line": 3
},
{
"file": "smart_contracts/__main__.py",
"description": "Uncomment the following lines to enable complementary utilities that will generate artifacts required for the [AlgoKit AVM Debugger](https://github.com/algorandfoundation/algokit-avm-vscode-debugger) VSCode plugin available on the [VSCode Extension Marketplace](https://marketplace.visualstudio.com/items?itemName=algorandfoundation.algokit-avm-vscode-debugger). A new folder will be automatically created in the `.algokit` directory with source maps of all TEAL contracts in this workspace, as well as traces that will appear in a folder at the root of the workspace. You can then use the traces as entry points to trigger the debug extension. Make sure to have the `.algokit.toml` file available at the root of the workspace.",
"line": 13
},
{
"file": "smart_contracts/_helpers/__init__.py",
"description": "This folder contains helper scripts for contract management. These automate tasks like compiling, generating clients, and deploying. Usually, you won't need to edit these files, but advanced users can expand them for custom needs.",
"line": 1
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

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.build import build
from smart_contracts._helpers.config import contracts
from smart_contracts._helpers.deploy import deploy

# 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
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 1.2.2
_commit: 1.2.4
_src_path: gh:algorandfoundation/algokit-python-template
author_email: None
author_name: None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def deploy(
app_spec: algokit_utils.ApplicationSpecification,
deployer: algokit_utils.Account,
) -> None:
from smart_contracts.artifacts.{{ contract_name }}.client import (
from smart_contracts.artifacts.{{ contract_name }}.{{ contract_name }}_client import (
{{ contract_name.split('_')|map('capitalize')|join }}Client,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "https://aka.ms/codetour-schema",
"title": "Getting Started with Your AlgoKit Project",
"steps": [
{
"file": "README.md",
"description": "Welcome to your brand new AlgoKit template-based project. In this tour, we will guide you through the main features and capabilities included in the template.",
"line": 3
},
{
"file": "README.md",
"description": "Start by ensuring you have followed the setup of pre-requisites.",
"line": 9
},
{
"file": ".algokit.toml",
"description": "This is the main configuration file used by algokit-cli to manage the project. The default template includes a starter 'Hello World' contract that is deployed via the `algokit-utils` package (either `ts` or `py`, depending on your choice). To create a new smart contract, you can use the [`algokit generate`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md) command and invoke a pre-bundled generator template by running `algokit generate smart-contract` (see how it is defined in the `.algokit.toml`, you can create your own generators if needed). This action will create a new folder in the `smart_contracts` directory, named after your project. Each folder contains a `contract.py` file, which is the entry point for your contract implementation, and `deploy_config.py` | `deployConfig.ts` files (depending on the language chosen for the template), that perform the deployment of the contract. Additionally you can define custom commands to run (similar to `npm` scripts), see definitions under `[project]` section in `.algokit.toml`.",
"line": 1
},
{
"file": "smart_contracts/hello_world/deploy_config.py",
"description": "The default deployment scripts invoke a sample method on the starter contract that demonstrates how to interact with your deployed Algorand on-chain applications using the [`AlgoKit Typed Clients`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md#1-typed-clients) feature. The invocation if deploy is aliased in `.algokit.toml` file, allowing simple deployments via `algokit project deploy` command.",
"line": 32
},
{
"file": "tests/hello_world_test.py",
"description": "If you opted to include unit tests, the default tests provided demonstrate an example of mocking, setting up fixtures, and testing smart contract calls on an AlgoKit typed client.",
"line": 36
},
{
"file": ".env.localnet.template",
"description": "Environment files are a crucial mechanism that allows you to set up the [`algokit deploy`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/deploy.md) feature to simplify deploying your contracts in CI/CD environments (please note we still recommend careful evaluation when it comes to deployment to MainNet). Clone the file and remove the `.template` suffix to apply the changes to deployment scripts and launch configurations. The network prefix `localnet|testnet|mainnet` is primarily optimized for `algokit deploy`. The order of loading the variables is `.env.{network}` < `.env`.",
"line": 2
},
{
"file": ".vscode/launch.json",
"description": "Refer to the pre-bundled Visual Studio launch configurations, offering various options on how to execute the build and deployment of your smart contracts. Alternatively execute `algokit project run` to see list of available custom commands.",
"line": 5
},
{
"file": ".vscode/extensions.json",
"description": "We highly recommend installing the recommended extensions to get the most out of this template starter project in your VSCode IDE.",
"line": 3
},
{
"file": "smart_contracts/__main__.py",
"description": "Uncomment the following lines to enable complementary utilities that will generate artifacts required for the [AlgoKit AVM Debugger](https://github.com/algorandfoundation/algokit-avm-vscode-debugger) VSCode plugin available on the [VSCode Extension Marketplace](https://marketplace.visualstudio.com/items?itemName=algorandfoundation.algokit-avm-vscode-debugger). A new folder will be automatically created in the `.algokit` directory with source maps of all TEAL contracts in this workspace, as well as traces that will appear in a folder at the root of the workspace. You can then use the traces as entry points to trigger the debug extension. Make sure to have the `.algokit.toml` file available at the root of the workspace.",
"line": 15
}
{
"file": "smart_contracts/_helpers/__init__.py",
"description": "This folder contains helper scripts for contract management. These automate tasks like compiling, generating clients, and deploying. Usually, you won't need to edit these files, but advanced users can expand them for custom needs.",
"line": 1
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

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.config import contracts
from smart_contracts._helpers.deploy import deploy

# 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 Expand Up @@ -36,7 +35,14 @@ def main(action: str) -> None:
for contract in contracts:
logger.info(f"Deploying app {contract.name}")
output_dir = artifact_path / contract.name
app_spec_file_name = find_app_spec_file(output_dir)
app_spec_file_name = next(
(
file.name
for file in output_dir.iterdir()
if file.is_file() and file.suffixes == [".arc32", ".json"]
),
None,
)
if app_spec_file_name is None:
raise Exception("Could not deploy app, .arc32.json file not found")
app_spec_path = output_dir / app_spec_file_name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import logging
import subprocess
from pathlib import Path
from shutil import rmtree

logger = logging.getLogger(__name__)
deployment_extension = "py"


def _get_output_path(output_dir: Path, deployment_extension: str) -> Path:
return output_dir / Path(
"{contract_name}"
+ ("_client" if deployment_extension == "py" else "Client")
+ f".{deployment_extension}"
)


def build(output_dir: Path, contract_path: Path) -> Path:
output_dir = output_dir.resolve()
if output_dir.exists():
rmtree(output_dir)
output_dir.mkdir(exist_ok=True, parents=True)
logger.info(f"Exporting {contract_path} to {output_dir}")

build_result = subprocess.run(
[
"algokit",
"--no-color",
"compile",
"python",
contract_path.absolute(),
f"--out-dir={output_dir}",
"--output-arc32",
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
if build_result.returncode:
raise Exception(f"Could not build contract:\n{build_result.stdout}")

app_spec_file_names = [file.name for file in output_dir.glob("*.arc32.json")]

for app_spec_file_name in app_spec_file_names:
if app_spec_file_name is None:
raise Exception(
"Could not generate typed client, .arc32.json file not found"
)
print(app_spec_file_name)
generate_result = subprocess.run(
[
"algokit",
"generate",
"client",
output_dir,
"--output",
_get_output_path(output_dir, deployment_extension),
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
if generate_result.returncode:
if "No such command" in generate_result.stdout:
raise Exception(
"Could not generate typed client, requires AlgoKit 2.0.0 or "
"later. Please update AlgoKit"
)
else:
raise Exception(
f"Could not generate typed client:\n{generate_result.stdout}"
)

return output_dir / app_spec_file_name
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def deploy(
app_spec: algokit_utils.ApplicationSpecification,
deployer: algokit_utils.Account,
) -> None:
from smart_contracts.artifacts.hello_world.client import (
from smart_contracts.artifacts.hello_world.hello_world_client import (
HelloWorldClient,
)

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient

from smart_contracts.artifacts.hello_world.client import HelloWorldClient
from smart_contracts.artifacts.hello_world.hello_world_client import HelloWorldClient


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 2.1.2
_commit: 2.1.4
_src_path: gh:algorandfoundation/algokit-beaker-default-template
author_email: None
author_name: None
Expand Down
Loading

0 comments on commit 08e0d5d

Please sign in to comment.