Skip to content

Commit

Permalink
fix: do not allow specifying address for applications, it is derive…
Browse files Browse the repository at this point in the history
…d from the app_id
  • Loading branch information
daniel-makerx committed Aug 27, 2024
1 parent 94a989f commit 00fe1bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/_algopy_testing/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import typing

import algosdk.logic

from _algopy_testing.primitives import UInt64
from _algopy_testing.protocols import UInt64Backed
from _algopy_testing.utils import as_int64
Expand All @@ -23,7 +25,6 @@ class ApplicationFields(typing.TypedDict, total=False):
local_num_bytes: algopy.UInt64
extra_program_pages: algopy.UInt64
creator: algopy.Account
address: algopy.Account


AccountKey = str
Expand Down Expand Up @@ -57,6 +58,13 @@ def __init__(self, application_id: algopy.UInt64 | int = 0, /):
def id(self) -> algopy.UInt64:
return UInt64(self._id)

@property
def address(self) -> algopy.Account:
from _algopy_testing.models import Account

address = algosdk.logic.get_application_address(self._id)
return Account(address)

@property
def int_(self) -> int:
return self._id
Expand Down
5 changes: 1 addition & 4 deletions src/_algopy_testing/value_generators/avm.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ def asset(
lazy_context.ledger._asset_data[int(new_asset.id)] = AssetFields(**merged_fields) # type: ignore[typeddict-item]
return new_asset

def application( # type: ignore[misc]
def application(
self,
id: int | None = None,
address: algopy.Account | None = None,
logs: list[bytes] | None = None, # type: ignore[valid-type]
**application_fields: typing.Unpack[ApplicationFields],
) -> algopy.Application:
Expand Down Expand Up @@ -175,8 +174,6 @@ def application( # type: ignore[misc]
"local_num_bytes": _algopy_testing.UInt64(0),
"extra_program_pages": _algopy_testing.UInt64(0),
"creator": lazy_context.value.default_sender,
"address": address
or _algopy_testing.Account(algosdk.logic.get_application_address(new_app_id)),
}

# Merge provided fields with defaults, prioritizing provided fields
Expand Down
1 change: 0 additions & 1 deletion tests/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ def test_app_params_get(
local_num_bytes=algopy.UInt64(0),
extra_program_pages=algopy.UInt64(0),
creator=algopy.Account(get_localnet_default_account(algod_client).address),
address=algopy.Account(client.app_address),
)

contract = StateAppParamsContract()
Expand Down

0 comments on commit 00fe1bc

Please sign in to comment.