From 367ffceef92674cee2f808b7b921bbbf12e94169 Mon Sep 17 00:00:00 2001 From: Daniel McGregor Date: Tue, 31 Oct 2023 10:47:25 +0800 Subject: [PATCH] fix: handle TMPL_ variables with an underscore --- src/algokit_utils/deploy.py | 2 +- tests/app_multi_underscore_template_var.py | 24 ++++++++++++++++++++++ tests/test_app_client_template_values.py | 23 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/app_multi_underscore_template_var.py diff --git a/src/algokit_utils/deploy.py b/src/algokit_utils/deploy.py index 84f11748..d63f2b82 100644 --- a/src/algokit_utils/deploy.py +++ b/src/algokit_utils/deploy.py @@ -71,7 +71,7 @@ """Template variable name used to control if a smart contract is updatable or not at deployment""" DELETABLE_TEMPLATE_NAME = f"TMPL_{_DELETABLE}" """Template variable name used to control if a smart contract is deletable or not at deployment""" -_TOKEN_PATTERN = re.compile(r"TMPL_[A-Z]+") +_TOKEN_PATTERN = re.compile(r"TMPL_[A-Z_]+") TemplateValue: TypeAlias = int | str | bytes TemplateValueDict: TypeAlias = dict[str, TemplateValue] """Dictionary of `dict[str, int | str | bytes]` representing template variable names and values""" diff --git a/tests/app_multi_underscore_template_var.py b/tests/app_multi_underscore_template_var.py new file mode 100644 index 00000000..2fc13ede --- /dev/null +++ b/tests/app_multi_underscore_template_var.py @@ -0,0 +1,24 @@ +import beaker +import pyteal + +app = beaker.Application("MultiUnderscoreApp") + + +@app.external +def some_value(*, output: pyteal.abi.Uint64) -> pyteal.Expr: + return output.set(pyteal.Tmpl.Int("TMPL_SOME_VALUE")) + + +@app.update(bare=True, authorize=beaker.Authorize.only_creator()) +def update() -> pyteal.Expr: + return pyteal.Assert(pyteal.Tmpl.Int("TMPL_UPDATABLE"), comment="is updatable") + + +@app.delete(bare=True, authorize=beaker.Authorize.only_creator()) +def delete() -> pyteal.Expr: + return pyteal.Assert(pyteal.Tmpl.Int("TMPL_DELETABLE"), comment="is deletable") + + +@app.create(bare=True) +def create() -> pyteal.Expr: + return pyteal.Approve() diff --git a/tests/test_app_client_template_values.py b/tests/test_app_client_template_values.py index c8321922..0bf5ab70 100644 --- a/tests/test_app_client_template_values.py +++ b/tests/test_app_client_template_values.py @@ -146,3 +146,26 @@ def test_deploy_with_missing_template_values( client.deploy( allow_delete=True, allow_update=True, create_args=algokit_utils.ABICreateCallArgs(method="create") ) + + +def test_deploy_with_multi_underscore_template_value( + algod_client: "AlgodClient", + indexer_client: "IndexerClient", + funded_account: algokit_utils.Account, +) -> None: + from tests.app_multi_underscore_template_var import app + + some_value = 123 + app_spec = app.build(algod_client) + client = algokit_utils.ApplicationClient( + algod_client, + app_spec, + creator=funded_account, + indexer_client=indexer_client, + app_name=get_unique_name(), + template_values={"SOME_VALUE": some_value}, + ) + + client.deploy(allow_update=True, allow_delete=True) + result = client.call("some_value") + assert result.return_value == some_value