Skip to content

Commit

Permalink
EnumInt.clone wasn't needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeph Grunschlag committed Mar 17, 2023
1 parent 678a045 commit 6a49be7
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 16 deletions.
5 changes: 0 additions & 5 deletions pyteal/ast/int.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,5 @@ def __str__(self):
def type_of(self):
return TealType.uint64

def clone(self) -> "EnumInt":
"""TODO: this is an experimental hack for source mapping"""
# return EnumInt(self.name)
return self


EnumInt.__module__ = "pyteal"
2 changes: 1 addition & 1 deletion pyteal/ast/opup.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _construct_itxn(self, inner_fee: Optional[Expr]) -> Expr:
else:
# TODO: cloning the DeleteApplication this is a hack for sourcemampping
fields |= {
TxnField.on_completion: OnComplete.DeleteApplication.clone(),
TxnField.on_completion: OnComplete.DeleteApplication,
TxnField.approval_program: ON_CALL_APP,
TxnField.clear_state_program: ON_CALL_APP,
}
Expand Down
20 changes: 10 additions & 10 deletions pyteal/ast/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def is_never(self) -> bool:

def approval_cond(self) -> Expr | int:
config_oc_pairs: list[tuple[CallConfig, EnumInt]] = [
(self.no_op, OnComplete.NoOp.clone()),
(self.opt_in, OnComplete.OptIn.clone()),
(self.close_out, OnComplete.CloseOut.clone()),
(self.update_application, OnComplete.UpdateApplication.clone()),
(self.delete_application, OnComplete.DeleteApplication.clone()),
(self.no_op, OnComplete.NoOp),
(self.opt_in, OnComplete.OptIn),
(self.close_out, OnComplete.CloseOut),
(self.update_application, OnComplete.UpdateApplication),
(self.delete_application, OnComplete.DeleteApplication),
]
if all(config == CallConfig.NEVER for config, _ in config_oc_pairs):
return 0
Expand Down Expand Up @@ -224,11 +224,11 @@ def is_empty(self) -> bool:

def approval_construction(self) -> Optional[Expr]:
oc_action_pair: list[tuple[EnumInt, OnCompleteAction]] = [
(OnComplete.NoOp.clone(), self.no_op),
(OnComplete.OptIn.clone(), self.opt_in),
(OnComplete.CloseOut.clone(), self.close_out),
(OnComplete.UpdateApplication.clone(), self.update_application),
(OnComplete.DeleteApplication.clone(), self.delete_application),
(OnComplete.NoOp, self.no_op),
(OnComplete.OptIn, self.opt_in),
(OnComplete.CloseOut, self.close_out),
(OnComplete.UpdateApplication, self.update_application),
(OnComplete.DeleteApplication, self.delete_application),
]
if all(oca.is_empty() for _, oca in oc_action_pair):
return None
Expand Down
194 changes: 194 additions & 0 deletions tests/unit/sourcemap_constructs311_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ def recursive_subroutine_example(pt):
return fib(pt.Int(10))


def big_opups_example(pt):
from examples.application.opup import (
approval_program_explicit_ensure,
approval_program_oncall_ensure,
approval_program_explicit_maximize,
approval_program_oncall_maximize,
)

return pt.Seq(
approval_program_explicit_ensure(),
approval_program_oncall_ensure(),
approval_program_explicit_maximize(),
approval_program_oncall_maximize(),
)


CONSTRUCTS_LATEST_VERSION = 8


Expand Down Expand Up @@ -1982,6 +1998,184 @@ def test_constructs_handles_latest_pyteal():
"Application",
dict(frame_pointers=True),
),
( # 43: OpUps
big_opups_example,
[
[P, C],
("txn ApplicationID", "Txn.application_id()"),
("int 0", "Int(0)"),
("!=", "Txn.application_id() != Int(0)"),
("bnz main_l16", "If(Txn.application_id() != Int(0))"),
("main_l1:", "If(Txn.application_id() != Int(0))"),
("int 1", "Approve()"),
("return", "Approve()"),
("txn ApplicationID", "Txn.application_id()"),
("int 0", "Int(0)"),
("!=", "Txn.application_id() != Int(0)"),
("main_l2:", "If(Txn.application_id() != Int(0))"),
("int 1", "Approve()"),
("return", "Approve()"),
("txn ApplicationID", "Txn.application_id()"),
("int 0", "Int(0)"),
("!=", "Txn.application_id() != Int(0)"),
("main_l3:", "If(Txn.application_id() != Int(0))"),
("int 1", "Approve()"),
("return", "Approve()"),
("txn ApplicationID", "Txn.application_id()"),
("int 0", "Int(0)"),
("!=", "Txn.application_id() != Int(0)"),
("int 0", "opup.maximize_budget(Int(3000))"),
("store 3", "opup.maximize_budget(Int(3000))"),
("main_l5:", "opup.maximize_budget(Int(3000))"),
("load 3", "opup.maximize_budget(Int(3000))"),
("int 3000", "Int(3000)"),
("global MinTxnFee", "opup.maximize_budget(Int(3000))"),
("/", "opup.maximize_budget(Int(3000))"),
("<", "opup.maximize_budget(Int(3000))"),
("bnz main_l7", "opup.maximize_budget(Int(3000))"),
(
"byte base64(iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=)",
"Bytes('base64', 'iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=')",
),
(
"byte base64(if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==)",
"Bytes('base64', 'if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==')",
),
(
"addr 7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224",
"Addr('7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224')",
),
("ed25519verify", "Ed25519Verify(args[0], args[1], args[2])"),
("pop", "Pop(Ed25519Verify(args[0], args[1], args[2]))"),
("b main_l20", C),
("main_l7:", "opup.maximize_budget(Int(3000))"),
("itxn_begin", "opup.maximize_budget(Int(3000))"),
("int appl", "opup.maximize_budget(Int(3000))"),
("itxn_field TypeEnum", "opup.maximize_budget(Int(3000))"),
("int DeleteApplication", "opup.maximize_budget(Int(3000))"),
("itxn_field OnCompletion", "opup.maximize_budget(Int(3000))"),
("byte 0x068101", "opup.maximize_budget(Int(3000))"),
("itxn_field ApprovalProgram", "opup.maximize_budget(Int(3000))"),
("byte 0x068101", "opup.maximize_budget(Int(3000))"),
("itxn_field ClearStateProgram", "opup.maximize_budget(Int(3000))"),
("itxn_submit", "opup.maximize_budget(Int(3000))"),
("load 3", "opup.maximize_budget(Int(3000))"),
("int 1", "opup.maximize_budget(Int(3000))"),
("+", "opup.maximize_budget(Int(3000))"),
("store 3", "opup.maximize_budget(Int(3000))"),
("b main_l5", "opup.maximize_budget(Int(3000))"),
("int 0", "opup.maximize_budget(Int(3000))"),
("store 2", "opup.maximize_budget(Int(3000))"),
("main_l9:", "opup.maximize_budget(Int(3000))"),
("load 2", "opup.maximize_budget(Int(3000))"),
("int 3000", "Int(3000)"),
("global MinTxnFee", "opup.maximize_budget(Int(3000))"),
("/", "opup.maximize_budget(Int(3000))"),
("<", "opup.maximize_budget(Int(3000))"),
("bnz main_l11", "opup.maximize_budget(Int(3000))"),
(
"byte base64(iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=)",
"Bytes('base64', 'iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=')",
),
(
"byte base64(if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==)",
"Bytes('base64', 'if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==')",
),
(
"addr 7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224",
"Addr('7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224')",
),
("ed25519verify", "Ed25519Verify(args[0], args[1], args[2])"),
("pop", "Pop(Ed25519Verify(args[0], args[1], args[2]))"),
("b main_l3", C),
("main_l11:", "opup.maximize_budget(Int(3000))"),
("itxn_begin", "opup.maximize_budget(Int(3000))"),
("int appl", "opup.maximize_budget(Int(3000))"),
("itxn_field TypeEnum", "opup.maximize_budget(Int(3000))"),
("int 1", "Int(1)"),
("itxn_field ApplicationID", "opup.maximize_budget(Int(3000))"),
("itxn_submit", "opup.maximize_budget(Int(3000))"),
("load 2", "opup.maximize_budget(Int(3000))"),
("int 1", "opup.maximize_budget(Int(3000))"),
("+", "opup.maximize_budget(Int(3000))"),
("store 2", "opup.maximize_budget(Int(3000))"),
("b main_l9", "opup.maximize_budget(Int(3000))"),
("int 2000", "Int(2000)"),
("int 10", "opup.ensure_budget(Int(2000))"),
("+", "opup.ensure_budget(Int(2000))"),
("store 1", "opup.ensure_budget(Int(2000))"),
("main_l13:", "opup.ensure_budget(Int(2000))"),
("load 1", "opup.ensure_budget(Int(2000))"),
("global OpcodeBudget", "opup.ensure_budget(Int(2000))"),
(">", "opup.ensure_budget(Int(2000))"),
("bnz main_l15", "opup.ensure_budget(Int(2000))"),
(
"byte base64(iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=)",
"Bytes('base64', 'iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=')",
),
(
"byte base64(if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==)",
"Bytes('base64', 'if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==')",
),
(
"addr 7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224",
"Addr('7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224')",
),
("ed25519verify", "Ed25519Verify(args[0], args[1], args[2])"),
("pop", "Pop(Ed25519Verify(args[0], args[1], args[2]))"),
("b main_l2", C),
("main_l15:", "opup.ensure_budget(Int(2000))"),
("itxn_begin", "opup.ensure_budget(Int(2000))"),
("int appl", "opup.ensure_budget(Int(2000))"),
("itxn_field TypeEnum", "opup.ensure_budget(Int(2000))"),
("int DeleteApplication", "opup.ensure_budget(Int(2000))"),
("itxn_field OnCompletion", "opup.ensure_budget(Int(2000))"),
("byte 0x068101", "opup.ensure_budget(Int(2000))"),
("itxn_field ApprovalProgram", "opup.ensure_budget(Int(2000))"),
("byte 0x068101", "opup.ensure_budget(Int(2000))"),
("itxn_field ClearStateProgram", "opup.ensure_budget(Int(2000))"),
("itxn_submit", "opup.ensure_budget(Int(2000))"),
("b main_l13", "opup.ensure_budget(Int(2000))"),
("main_l16:", "If(Txn.application_id() != Int(0))"),
("int 2000", "Int(2000)"),
("int 10", "opup.ensure_budget(Int(2000))"),
("+", "opup.ensure_budget(Int(2000))"),
("store 0", "opup.ensure_budget(Int(2000))"),
("main_l17:", "opup.ensure_budget(Int(2000))"),
("load 0", "opup.ensure_budget(Int(2000))"),
("global OpcodeBudget", "opup.ensure_budget(Int(2000))"),
(">", "opup.ensure_budget(Int(2000))"),
("bnz main_l19", "opup.ensure_budget(Int(2000))"),
(
"byte base64(iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=)",
"Bytes('base64', 'iZWMx72KvU6Bw6sPAWQFL96YH+VMrBA0XKWD9XbZOZI=')",
),
(
"byte base64(if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==)",
"Bytes('base64', 'if8ooA+32YZc4SQBvIDDY8tgTatPoq4IZ8Kr+We1t38LR2RuURmaVu9D4shbi4VvND87PUqq5/0vsNFEGIIEDA==')",
),
(
"addr 7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224",
"Addr('7JOPVEP3ABJUW5YZ5WFIONLPWTZ5MYX5HFK4K7JLGSIAG7RRB42MNLQ224')",
),
("ed25519verify", "Ed25519Verify(args[0], args[1], args[2])"),
("pop", "Pop(Ed25519Verify(args[0], args[1], args[2]))"),
("b main_l1", C),
("main_l19:", "opup.ensure_budget(Int(2000))"),
("itxn_begin", "opup.ensure_budget(Int(2000))"),
("int appl", "opup.ensure_budget(Int(2000))"),
("itxn_field TypeEnum", "opup.ensure_budget(Int(2000))"),
("int 1", "Int(1)"),
("itxn_field ApplicationID", "opup.ensure_budget(Int(2000))"),
("itxn_submit", "opup.ensure_budget(Int(2000))"),
("b main_l17", "opup.ensure_budget(Int(2000))"),
("main_l20:", "opup.ensure_budget(Int(2000))"),
("int 1", "Approve()"),
("return", "Approve()"),
],
6,
"Application",
),
]


Expand Down

0 comments on commit 6a49be7

Please sign in to comment.