Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
feat: improve testnet and mainnet deployment experience (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
negar-abbasi authored Jun 26, 2023
1 parent 2189b53 commit 2a5085b
Show file tree
Hide file tree
Showing 73 changed files with 651 additions and 771 deletions.
166 changes: 83 additions & 83 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
beaker-pyteal = "^1.0.0"
algokit-utils = {version = "^1.2.0b8", allow-prereleases = true}
algokit-utils = "^1.3"
python-dotenv = "^1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion template_content/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
beaker-pyteal = "^1.0.0"
algokit-utils = "^1.2"
algokit-utils = "^1.3"
python-dotenv = "^1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import logging

from algokit_utils import (
Account,
ApplicationSpecification,
OnSchemaBreak,
OnUpdate,
OperationPerformed,
TransferParameters,
is_localnet,
transfer,
)
import algokit_utils
from algosdk.util import algos_to_microalgos
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
Expand All @@ -21,14 +12,15 @@ logger = logging.getLogger(__name__)
# define contracts to build and/or deploy
contracts = [helloworld.app]


# define deployment behaviour based on supplied app spec
def deploy(
algod_client: AlgodClient,
indexer_client: IndexerClient,
app_spec: ApplicationSpecification,
deployer: Account,
app_spec: algokit_utils.ApplicationSpecification,
deployer: algokit_utils.Account,
) -> None:
is_local = is_localnet(algod_client)
is_mainnet = algokit_utils.is_mainnet(algod_client)
match app_spec.contract.name:
case "HelloWorldApp":
from smart_contracts.artifacts.HelloWorldApp.client import (
Expand All @@ -42,19 +34,23 @@ def deploy(
)
deploy_response = app_client.deploy(
on_schema_break=(
OnSchemaBreak.ReplaceApp if is_local else OnSchemaBreak.Fail
algokit_utils.OnSchemaBreak.AppendApp
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=OnUpdate.UpdateApp if is_local else OnUpdate.Fail,
allow_delete=is_local,
allow_update=is_local,
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)

# if only just created, fund smart contract account
if deploy_response.action_taken in [
OperationPerformed.Create,
OperationPerformed.Replace,
algokit_utils.OperationPerformed.Create,
algokit_utils.OperationPerformed.Replace,
]:
transfer_parameters = TransferParameters(
transfer_parameters = algokit_utils.TransferParameters(
from_account=deployer,
to_address=app_client.app_address,
micro_algos=algos_to_microalgos(1),
Expand All @@ -63,7 +59,7 @@ def deploy(
f"New app created, funding with "
f"{transfer_parameters.micro_algos}µ algos"
)
transfer(algod_client, transfer_parameters)
algokit_utils.transfer(algod_client, transfer_parameters)

name = "world"
response = app_client.hello(name=name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function deploy(name: (typeof contracts)[number], appSpec: AppSpec)
},
algod,
)
const isLocal = await algokit.isLocalNet(algod)
const isMainNet = await algokit.isMainNet(algod)
const appClient = new HelloWorldAppClient(
{
resolveBy: 'creatorAndName',
Expand All @@ -32,10 +32,10 @@ export async function deploy(name: (typeof contracts)[number], appSpec: AppSpec)
// Edit this to add the custom deployment logic for each contract
case 'HelloWorldApp':
const app = await appClient.deploy({
allowDelete: isLocal,
allowUpdate: isLocal,
onSchemaBreak: isLocal ? 'replace' : 'fail',
onUpdate: isLocal ? 'update' : 'fail',
allowDelete: !isMainNet,
allowUpdate: !isMainNet,
onSchemaBreak: isMainNet ? 'append' : 'replace',
onUpdate: isMainNet ? 'append' : 'update',
})
// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"format": "prettier --write ."
},
"dependencies": {
"@algorandfoundation/algokit-utils": "^2.0.0"
"@algorandfoundation/algokit-utils": "^2.2.1"
},
"devDependencies": {
"dotenv": "^16.0.3",
Expand Down
2 changes: 1 addition & 1 deletion tests_generated/test_default_parameters/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
beaker-pyteal = "^1.0.0"
algokit-utils = "^1.2"
algokit-utils = "^1.3"
python-dotenv = "^1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
38 changes: 17 additions & 21 deletions tests_generated/test_default_parameters/smart_contracts/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import logging

from algokit_utils import (
Account,
ApplicationSpecification,
OnSchemaBreak,
OnUpdate,
OperationPerformed,
TransferParameters,
is_localnet,
transfer,
)
import algokit_utils
from algosdk.util import algos_to_microalgos
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
Expand All @@ -21,14 +12,15 @@
# define contracts to build and/or deploy
contracts = [helloworld.app]


# define deployment behaviour based on supplied app spec
def deploy(
algod_client: AlgodClient,
indexer_client: IndexerClient,
app_spec: ApplicationSpecification,
deployer: Account,
app_spec: algokit_utils.ApplicationSpecification,
deployer: algokit_utils.Account,
) -> None:
is_local = is_localnet(algod_client)
is_mainnet = algokit_utils.is_mainnet(algod_client)
match app_spec.contract.name:
case "HelloWorldApp":
from smart_contracts.artifacts.HelloWorldApp.client import (
Expand All @@ -42,19 +34,23 @@ def deploy(
)
deploy_response = app_client.deploy(
on_schema_break=(
OnSchemaBreak.ReplaceApp if is_local else OnSchemaBreak.Fail
algokit_utils.OnSchemaBreak.AppendApp
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=OnUpdate.UpdateApp if is_local else OnUpdate.Fail,
allow_delete=is_local,
allow_update=is_local,
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)

# if only just created, fund smart contract account
if deploy_response.action_taken in [
OperationPerformed.Create,
OperationPerformed.Replace,
algokit_utils.OperationPerformed.Create,
algokit_utils.OperationPerformed.Replace,
]:
transfer_parameters = TransferParameters(
transfer_parameters = algokit_utils.TransferParameters(
from_account=deployer,
to_address=app_client.app_address,
micro_algos=algos_to_microalgos(1),
Expand All @@ -63,7 +59,7 @@ def deploy(
f"New app created, funding with "
f"{transfer_parameters.micro_algos}µ algos"
)
transfer(algod_client, transfer_parameters)
algokit_utils.transfer(algod_client, transfer_parameters)

name = "world"
response = app_client.hello(name=name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
beaker-pyteal = "^1.0.0"
algokit-utils = "^1.2"
algokit-utils = "^1.3"
python-dotenv = "^1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import logging

from algokit_utils import (
Account,
ApplicationSpecification,
OnSchemaBreak,
OnUpdate,
OperationPerformed,
TransferParameters,
is_localnet,
transfer,
)
import algokit_utils
from algosdk.util import algos_to_microalgos
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
Expand All @@ -21,14 +12,15 @@
# define contracts to build and/or deploy
contracts = [helloworld.app]


# define deployment behaviour based on supplied app spec
def deploy(
algod_client: AlgodClient,
indexer_client: IndexerClient,
app_spec: ApplicationSpecification,
deployer: Account,
app_spec: algokit_utils.ApplicationSpecification,
deployer: algokit_utils.Account,
) -> None:
is_local = is_localnet(algod_client)
is_mainnet = algokit_utils.is_mainnet(algod_client)
match app_spec.contract.name:
case "HelloWorldApp":
from smart_contracts.artifacts.HelloWorldApp.client import (
Expand All @@ -42,19 +34,23 @@ def deploy(
)
deploy_response = app_client.deploy(
on_schema_break=(
OnSchemaBreak.ReplaceApp if is_local else OnSchemaBreak.Fail
algokit_utils.OnSchemaBreak.AppendApp
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=OnUpdate.UpdateApp if is_local else OnUpdate.Fail,
allow_delete=is_local,
allow_update=is_local,
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)

# if only just created, fund smart contract account
if deploy_response.action_taken in [
OperationPerformed.Create,
OperationPerformed.Replace,
algokit_utils.OperationPerformed.Create,
algokit_utils.OperationPerformed.Replace,
]:
transfer_parameters = TransferParameters(
transfer_parameters = algokit_utils.TransferParameters(
from_account=deployer,
to_address=app_client.app_address,
micro_algos=algos_to_microalgos(1),
Expand All @@ -63,7 +59,7 @@ def deploy(
f"New app created, funding with "
f"{transfer_parameters.micro_algos}µ algos"
)
transfer(algod_client, transfer_parameters)
algokit_utils.transfer(algod_client, transfer_parameters)

name = "world"
response = app_client.hello(name=name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
beaker-pyteal = "^1.0.0"
algokit-utils = "^1.2"
algokit-utils = "^1.3"
python-dotenv = "^1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function deploy(name: (typeof contracts)[number], appSpec: AppSpec)
},
algod,
)
const isLocal = await algokit.isLocalNet(algod)
const isMainNet = await algokit.isMainNet(algod)
const appClient = new HelloWorldAppClient(
{
resolveBy: 'creatorAndName',
Expand All @@ -32,10 +32,10 @@ export async function deploy(name: (typeof contracts)[number], appSpec: AppSpec)
// Edit this to add the custom deployment logic for each contract
case 'HelloWorldApp':
const app = await appClient.deploy({
allowDelete: isLocal,
allowUpdate: isLocal,
onSchemaBreak: isLocal ? 'replace' : 'fail',
onUpdate: isLocal ? 'update' : 'fail',
allowDelete: !isMainNet,
allowUpdate: !isMainNet,
onSchemaBreak: isMainNet ? 'append' : 'replace',
onUpdate: isMainNet ? 'append' : 'update',
})
// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"format": "prettier --write ."
},
"dependencies": {
"@algorandfoundation/algokit-utils": "^2.0.0"
"@algorandfoundation/algokit-utils": "^2.2.1"
},
"devDependencies": {
"dotenv": "^16.0.3",
Expand Down
2 changes: 1 addition & 1 deletion tests_generated/test_ide_vscode-False/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
beaker-pyteal = "^1.0.0"
algokit-utils = "^1.2"
algokit-utils = "^1.3"
python-dotenv = "^1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
Loading

0 comments on commit 2a5085b

Please sign in to comment.