diff --git a/pyteal/__init__.pyi b/pyteal/__init__.pyi index ccba1bb67..5e49e918e 100644 --- a/pyteal/__init__.pyi +++ b/pyteal/__init__.pyi @@ -29,7 +29,6 @@ from pyteal.config import ( __all__ = [ "ABIReturnSubroutine", - "ASTBuilder", "AccountParam", "Add", "Addr", diff --git a/pyteal/ast/__init__.py b/pyteal/ast/__init__.py index f288bdacc..68c6fd149 100644 --- a/pyteal/ast/__init__.py +++ b/pyteal/ast/__init__.py @@ -140,7 +140,6 @@ from pyteal.ast.ecdsa import EcdsaCurve, EcdsaVerify, EcdsaDecompress, EcdsaRecover from pyteal.ast.router import ( Router, - ASTBuilder, CallConfig, MethodConfig, OnCompleteAction, @@ -288,7 +287,6 @@ "Break", "Continue", "Router", - "ASTBuilder", "CallConfig", "MethodConfig", "OnCompleteAction", diff --git a/pyteal/ast/router.py b/pyteal/ast/router.py index 79d1ce845..6954b8720 100644 --- a/pyteal/ast/router.py +++ b/pyteal/ast/router.py @@ -537,7 +537,7 @@ def method( func: Callable = None, /, *, - overriding_name: str = None, + name: str = None, no_op: CallConfig = CallConfig.CALL, opt_in: CallConfig = CallConfig.NEVER, close_out: CallConfig = CallConfig.NEVER, @@ -555,7 +555,7 @@ def wrap(_func): update_application=update_application, delete_application=delete_application, ) - self.add_method_handler(wrapped_subroutine, overriding_name, call_configs) + self.add_method_handler(wrapped_subroutine, name, call_configs) if not func: return wrap diff --git a/pyteal/ast/router_test.py b/pyteal/ast/router_test.py index 16c9be55f..20cf4af4d 100644 --- a/pyteal/ast/router_test.py +++ b/pyteal/ast/router_test.py @@ -1,4 +1,6 @@ import pyteal as pt +from pyteal.ast.router import ASTBuilder + import itertools import pytest @@ -6,6 +8,7 @@ import typing import algosdk.abi as sdk_abi + options = pt.CompileOptions(version=5) @@ -188,7 +191,7 @@ def power_set(no_dup_list: list, length_override: int = None): def full_perm_gen(non_dup_list: list, perm_length: int): if perm_length < 0: - raise + raise pt.TealInputError("input permutation length must be non-negative") elif perm_length == 0: yield [] return @@ -413,7 +416,7 @@ def test_wrap_handler_bare_call(): pt.Log(pt.Bytes("message")), ] for bare_call in BARE_CALL_CASES: - wrapped: pt.Expr = pt.ASTBuilder.wrap_handler(False, bare_call) + wrapped: pt.Expr = ASTBuilder.wrap_handler(False, bare_call) match bare_call: case pt.Expr(): if bare_call.has_return(): @@ -453,24 +456,24 @@ def test_wrap_handler_bare_call(): ] for error_case, error_msg in ERROR_CASES: with pytest.raises(pt.TealInputError) as bug: - pt.ASTBuilder.wrap_handler(False, error_case) + ASTBuilder.wrap_handler(False, error_case) assert error_msg in str(bug) def test_wrap_handler_method_call(): with pytest.raises(pt.TealInputError) as bug: - pt.ASTBuilder.wrap_handler(True, not_registrable) + ASTBuilder.wrap_handler(True, not_registrable) assert "method call ABIReturnSubroutine is not routable" in str(bug) with pytest.raises(pt.TealInputError) as bug: - pt.ASTBuilder.wrap_handler(True, safe_clear_state_delete) + ASTBuilder.wrap_handler(True, safe_clear_state_delete) assert "method call should be only registering ABIReturnSubroutine" in str(bug) ONLY_ABI_SUBROUTINE_CASES = list( filter(lambda x: isinstance(x, pt.ABIReturnSubroutine), GOOD_SUBROUTINE_CASES) ) for abi_subroutine in ONLY_ABI_SUBROUTINE_CASES: - wrapped: pt.Expr = pt.ASTBuilder.wrap_handler(True, abi_subroutine) + wrapped: pt.Expr = ASTBuilder.wrap_handler(True, abi_subroutine) assembled_wrapped: pt.TealBlock = assemble_helper(wrapped) args: list[pt.abi.BaseType] = [ @@ -539,8 +542,4 @@ def test_contract_json_obj(): method_list.append(sdk_abi.Method.from_signature(subroutine.method_signature())) sdk_contract = sdk_abi.Contract(contract_name, method_list) contract = router.contract_construct() - assert sdk_contract.desc == contract.desc - assert sdk_contract.name == contract.name - assert sdk_contract.networks == contract.networks - for method in sdk_contract.methods: - assert method in contract.methods + assert contract == sdk_contract diff --git a/pyteal/compiler/compiler_test.py b/pyteal/compiler/compiler_test.py index dac8aefe5..4eb239673 100644 --- a/pyteal/compiler/compiler_test.py +++ b/pyteal/compiler/compiler_test.py @@ -2274,44 +2274,42 @@ def all_laid_to_args( router.add_method_handler(all_laid_to_args) - actual_ap_compiled, actual_csp_compiled, _ = router.compile_program( - version=6, assembleConstants=True - ) + actual_ap_compiled, actual_csp_compiled, _ = router.compile_program(version=6) + print(actual_ap_compiled) + print(actual_csp_compiled) expected_ap = """#pragma version 6 -intcblock 0 1 -bytecblock 0x151f7c75 txna ApplicationArgs 0 -pushbytes 0xfe6bdf69 // "add(uint64,uint64)uint64" +method "add(uint64,uint64)uint64" == bnz main_l12 txna ApplicationArgs 0 -pushbytes 0x78b488b7 // "sub(uint64,uint64)uint64" +method "sub(uint64,uint64)uint64" == bnz main_l11 txna ApplicationArgs 0 -pushbytes 0xe2f188c5 // "mul(uint64,uint64)uint64" +method "mul(uint64,uint64)uint64" == bnz main_l10 txna ApplicationArgs 0 -pushbytes 0x16e80f08 // "div(uint64,uint64)uint64" +method "div(uint64,uint64)uint64" == bnz main_l9 txna ApplicationArgs 0 -pushbytes 0x4dfc58ae // "mod(uint64,uint64)uint64" +method "mod(uint64,uint64)uint64" == bnz main_l8 txna ApplicationArgs 0 -pushbytes 0x487ce2fd // "all_laid_to_args(uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64)uint64" +method "all_laid_to_args(uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64)uint64" == bnz main_l7 err main_l7: txn OnCompletion -intc_0 // NoOp +int NoOp == txn ApplicationID -intc_0 // 0 +int 0 != && assert @@ -2360,11 +2358,11 @@ def all_laid_to_args( txna ApplicationArgs 15 store 44 load 44 -intc_0 // 0 +int 0 extract_uint64 store 45 load 44 -pushint 8 // 8 +int 8 extract_uint64 store 46 load 30 @@ -2385,19 +2383,19 @@ def all_laid_to_args( load 46 callsub alllaidtoargs_5 store 47 -bytec_0 // 0x151f7c75 +byte 0x151f7c75 load 47 itob concat log -intc_1 // 1 +int 1 return main_l8: txn OnCompletion -intc_0 // NoOp +int NoOp == txn ApplicationID -intc_0 // 0 +int 0 != && assert @@ -2411,19 +2409,19 @@ def all_laid_to_args( load 25 callsub mod_4 store 26 -bytec_0 // 0x151f7c75 +byte 0x151f7c75 load 26 itob concat log -intc_1 // 1 +int 1 return main_l9: txn OnCompletion -intc_0 // NoOp +int NoOp == txn ApplicationID -intc_0 // 0 +int 0 != && assert @@ -2437,19 +2435,19 @@ def all_laid_to_args( load 19 callsub div_3 store 20 -bytec_0 // 0x151f7c75 +byte 0x151f7c75 load 20 itob concat log -intc_1 // 1 +int 1 return main_l10: txn OnCompletion -intc_0 // NoOp +int NoOp == txn ApplicationID -intc_0 // 0 +int 0 != && assert @@ -2463,19 +2461,19 @@ def all_laid_to_args( load 13 callsub mul_2 store 14 -bytec_0 // 0x151f7c75 +byte 0x151f7c75 load 14 itob concat log -intc_1 // 1 +int 1 return main_l11: txn OnCompletion -intc_0 // NoOp +int NoOp == txn ApplicationID -intc_0 // 0 +int 0 != && assert @@ -2489,19 +2487,19 @@ def all_laid_to_args( load 7 callsub sub_1 store 8 -bytec_0 // 0x151f7c75 +byte 0x151f7c75 load 8 itob concat log -intc_1 // 1 +int 1 return main_l12: txn OnCompletion -intc_0 // NoOp +int NoOp == txn ApplicationID -intc_0 // 0 +int 0 != && assert @@ -2515,12 +2513,12 @@ def all_laid_to_args( load 1 callsub add_0 store 2 -bytec_0 // 0x151f7c75 +byte 0x151f7c75 load 2 itob concat log -intc_1 // 1 +int 1 return // add @@ -2633,17 +2631,16 @@ def all_laid_to_args( assert expected_ap == actual_ap_compiled expected_csp = """#pragma version 6 -intcblock 0 txn NumAppArgs -intc_0 // 0 +int 0 == bnz main_l2 err main_l2: txn ApplicationID -intc_0 // 0 +int 0 != assert -pushint 1 // 1 +int 1 return""".strip() assert expected_csp == actual_csp_compiled