Skip to content

Commit

Permalink
New global fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos committed Dec 21, 2023
1 parent fa81388 commit 5d39985
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pyteal/ast/global_.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class GlobalField(Enum):
opcode_budget = (12, "OpcodeBudget", TealType.uint64, 6)
caller_app_id = (13, "CallerApplicationID", TealType.uint64, 6)
caller_app_address = (14, "CallerApplicationAddress", TealType.bytes, 6)
asset_create_min_balance = (15, "AssetCreateMinBalance", TealType.uint64, 10)
asset_opt_in_min_balance = (16, "AssetOptInMinBalance", TealType.uint64, 10)
genesis_hash = (17, "GenesisHash", TealType.bytes, 10)

def __init__(self, id: int, name: str, type: TealType, min_version: int) -> None:
self.id = id
Expand Down Expand Up @@ -159,5 +162,26 @@ def caller_app_address(cls) -> "Global":
Requires program version 6 or higher."""
return cls(GlobalField.caller_app_address)

@classmethod
def asset_create_min_balance(cls) -> "Global":
"""Get the additional minimum balance required to create (and opt-into) an asset.
Requires program version 10 or higher."""
return cls(GlobalField.asset_create_min_balance)

@classmethod
def asset_opt_in_min_balance(cls) -> "Global":
"""Get the additional minimum balance required to opt-into an asset.
Requires program version 10 or higher."""
return cls(GlobalField.asset_opt_in_min_balance)

@classmethod
def genesis_hash(cls) -> "Global":
"""Get the genesis hash for the network.
Requires program version 10 or higher."""
return cls(GlobalField.genesis_hash)


Global.__module__ = "pyteal"
48 changes: 48 additions & 0 deletions pyteal/ast/global_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
avm3Options = pt.CompileOptions(version=3)
avm5Options = pt.CompileOptions(version=5)
avm6Options = pt.CompileOptions(version=6)
avm9Options = pt.CompileOptions(version=9)
avm10Options = pt.CompileOptions(version=10)


def test_global_min_txn_fee():
Expand Down Expand Up @@ -197,3 +199,49 @@ def test_global_caller_app_address():

with pytest.raises(pt.TealInputError):
expr.__teal__(avm5Options)


def test_global_asset_create_min_balance():
expr = pt.Global.asset_create_min_balance()
assert expr.type_of() == pt.TealType.uint64

expected = pt.TealSimpleBlock(
[pt.TealOp(expr, pt.Op.global_, "AssetCreateMinBalance")]
)

actual, _ = expr.__teal__(avm10Options)

assert actual == expected

with pytest.raises(pt.TealInputError):
expr.__teal__(avm9Options)


def test_global_asset_opt_in_min_balance():
expr = pt.Global.asset_opt_in_min_balance()
assert expr.type_of() == pt.TealType.uint64

expected = pt.TealSimpleBlock(
[pt.TealOp(expr, pt.Op.global_, "AssetOptInMinBalance")]
)

actual, _ = expr.__teal__(avm10Options)

assert actual == expected

with pytest.raises(pt.TealInputError):
expr.__teal__(avm9Options)


def test_global_genesis_hash():
expr = pt.Global.genesis_hash()
assert expr.type_of() == pt.TealType.bytes

expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.global_, "GenesisHash")])

actual, _ = expr.__teal__(avm10Options)

assert actual == expected

with pytest.raises(pt.TealInputError):
expr.__teal__(avm9Options)

0 comments on commit 5d39985

Please sign in to comment.