Skip to content

Commit

Permalink
fix: handle TMPL_ variables with an underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx committed Oct 31, 2023
1 parent 1f573d4 commit 367ffce
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/algokit_utils/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
24 changes: 24 additions & 0 deletions tests/app_multi_underscore_template_var.py
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions tests/test_app_client_template_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 367ffce

Please sign in to comment.