Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Feb 21, 2024
1 parent c097e5a commit ae3e804
Show file tree
Hide file tree
Showing 149 changed files with 1,741 additions and 2,365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useWallet } from '@txnlab/use-wallet'
import { useSnackbar } from 'notistack'
import { useState } from 'react'

import { HelloWorldClient } from '../contracts/HelloWorld'
import { HelloWorldClient } from '../contracts/hello_world'

import { getAlgodConfigFromViteEnvironment, getIndexerConfigFromViteEnvironment } from '../utils/network/getAlgoClientConfigs'

Expand Down Expand Up @@ -52,9 +52,12 @@ const AppCalls = ({ openModal, setModalState }: AppCallsInterface) => {
// Instead, you would deploy your contract on your backend and reference it by id.
// Given the simplicity of the starter contract, we are deploying it on the frontend
// for demonstration purposes.
const deployParams = {
onSchemaBreak: 'append',
onUpdate: 'append',
const isLocal = await algokit.isLocalNet(algodClient)
const deployParams: Parameters<typeof appClient.deploy>[0] = {
allowDelete: isLocal,
allowUpdate: isLocal,
onSchemaBreak: isLocal ? 'replace' : 'fail',
onUpdate: isLocal ? 'update' : 'fail',
}
await appClient.deploy(deployParams).catch((e: Error) => {
enqueueSnackbar(`Error deploying the contract: ${e.message}`, { variant: 'error' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[algokit]
min_version = "v1.8.0"
min_version = "v1.10.0"

[deploy]
command = "poetry run python -m smart_contracts deploy"
environment_secrets = [
"DEPLOYER_MNEMONIC",
"DISPENSER_MNEMONIC",
]

[deploy.localnet]
Expand All @@ -13,7 +14,3 @@ environment_secrets = []
[generate.smart_contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"

[project]
type = 'backend'
name = 'production_beaker_react-contracts'
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
from puyapy import ARC4Contract, arc4
import beaker
import pyteal as pt
{% if preset_name == 'starter' %}

app = beaker.Application("{{ contract_name }}")
{% elif preset_name == 'production' -%}
from algokit_utils import DELETABLE_TEMPLATE_NAME, UPDATABLE_TEMPLATE_NAME

class {{ contract_name.split('_')|map('capitalize')|join }}(ARC4Contract):
@arc4.abimethod()
def hello(self, name: arc4.String) -> arc4.String:
return "Hello, " + name
app = beaker.Application("{{ contract_name }}")


@app.update(authorize=beaker.Authorize.only_creator(), bare=True)
def update() -> pt.Expr:
return pt.Assert(
pt.Tmpl.Int(UPDATABLE_TEMPLATE_NAME),
comment="Check app is updatable",
)


@app.delete(authorize=beaker.Authorize.only_creator(), bare=True)
def delete() -> pt.Expr:
return pt.Assert(
pt.Tmpl.Int(DELETABLE_TEMPLATE_NAME),
comment="Check app is deletable",
)
{% endif %}

@app.external
def hello(name: pt.abi.String, *, output: pt.abi.String) -> pt.Expr:
return output.set(pt.Concat(pt.Bytes("Hello, "), name.get()))
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,38 @@ def deploy(
app_spec: algokit_utils.ApplicationSpecification,
deployer: algokit_utils.Account,
) -> None:
from smart_contracts.artifacts.hello_world.client import (
HelloWorldClient,
from smart_contracts.artifacts.{{ contract_name }}.client import (
{{ contract_name.split('_')|map('capitalize')|join }}Client,
)

app_client = HelloWorldClient(
app_client = {{ contract_name.split('_')|map('capitalize')|join }}Client(
algod_client,
creator=deployer,
indexer_client=indexer_client,
)


{%- if preset_name == 'starter' %}
app_client.deploy(
on_schema_break=algokit_utils.OnSchemaBreak.AppendApp,
on_update=algokit_utils.OnUpdate.AppendApp,
)
{%- elif preset_name == 'production' %}
is_mainnet = algokit_utils.is_mainnet(algod_client)
app_client.deploy(
on_schema_break=(
algokit_utils.OnSchemaBreak.AppendApp
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)
{%- endif %}

name = "world"
response = app_client.hello(name=name)
logger.info(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 0.4.0-20-gfaa6d61
_src_path: gh:algorandfoundation/algokit-puya-template
_commit: 1.12.0-25-gbe89a2c
_src_path: gh:algorandfoundation/algokit-beaker-default-template
author_email: None
author_name: None
contract_name: hello_world
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "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
}
]
}
Loading

0 comments on commit ae3e804

Please sign in to comment.