From ca97ccbe860599c6f8df625f4910c74fea3f5fe9 Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Tue, 18 Apr 2023 11:30:43 -0700 Subject: [PATCH] Use asset/app IDs when accessing ABI reference args (#701) * Use creatable indexes when accessing ABI args * changelog --- CHANGELOG.md | 2 ++ pyteal/ast/abi/reference_type.py | 8 ++++---- pyteal/ast/abi/reference_type_test.py | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a5b5e5b6..ffcf55b59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ## Changed +* Stop using slot indexes for assets and apps when accessing properties of ABI reference type arguments. ([#701](https://github.com/algorand/pyteal/pull/701)) + # v0.24.0 ## Added diff --git a/pyteal/ast/abi/reference_type.py b/pyteal/ast/abi/reference_type.py index 7e9c5307c..ff76636f8 100644 --- a/pyteal/ast/abi/reference_type.py +++ b/pyteal/ast/abi/reference_type.py @@ -124,7 +124,7 @@ def asset_holding(self, asset: "Expr | Asset") -> AssetHoldingObject: must evaluate to uint64). """ if isinstance(asset, Asset): - asset_ref = asset.referenced_index() + asset_ref = asset.asset_id() else: asset_ref = asset return AssetHoldingObject(asset_ref, self.referenced_index()) @@ -172,11 +172,11 @@ def holding(self, account: Expr | Account) -> AssetHoldingObject: account_ref = account.referenced_index() else: account_ref = account - return AssetHoldingObject(self.referenced_index(), account_ref) + return AssetHoldingObject(self.asset_id(), account_ref) def params(self) -> AssetParamObject: """Get information about the asset's parameters.""" - return AssetParamObject(self.referenced_index()) + return AssetParamObject(self.asset_id()) Asset.__module__ = "pyteal.abi" @@ -209,7 +209,7 @@ def application_id(self) -> Expr: def params(self) -> AppParamObject: """Get information about the application's parameters.""" - return AppParamObject(self.referenced_index()) + return AppParamObject(self.application_id()) Application.__module__ = "pyteal.abi" diff --git a/pyteal/ast/abi/reference_type_test.py b/pyteal/ast/abi/reference_type_test.py index cbbc45d34..c8db31e5e 100644 --- a/pyteal/ast/abi/reference_type_test.py +++ b/pyteal/ast/abi/reference_type_test.py @@ -147,7 +147,7 @@ def test_Account_params(): def test_Account_asset_holding(): value = abi.Account() - assets = ((pt.Int(6), pt.Int(6)), (a := abi.Asset(), a.referenced_index())) + assets = ((pt.Int(6), pt.Int(6)), (a := abi.Asset(), a.asset_id())) for asset, expected_asset in assets: holding = value.asset_holding(asset) @@ -234,7 +234,7 @@ def test_Asset_holding(): assert type(holding) is pt.AssetHoldingObject - expected_asset = value.referenced_index() + expected_asset = value.asset_id() actual_asset = holding._asset actual_account = holding._account @@ -253,7 +253,7 @@ def test_Asset_params(): assert type(params) is pt.AssetParamObject - expected = value.referenced_index() + expected = value.asset_id() actual = params._asset with pt.TealComponent.Context.ignoreExprEquality(): @@ -318,7 +318,7 @@ def test_Application_params(): assert type(params) is pt.AppParamObject - expected = value.referenced_index() + expected = value.application_id() actual = params._app with pt.TealComponent.Context.ignoreExprEquality():