Skip to content

Commit

Permalink
per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed May 27, 2022
1 parent 4aa69c6 commit b964347
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 57 deletions.
1 change: 0 additions & 1 deletion pyteal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ from pyteal.config import (

__all__ = [
"ABIReturnSubroutine",
"ASTBuilder",
"AccountParam",
"Add",
"Addr",
Expand Down
2 changes: 0 additions & 2 deletions pyteal/ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
from pyteal.ast.ecdsa import EcdsaCurve, EcdsaVerify, EcdsaDecompress, EcdsaRecover
from pyteal.ast.router import (
Router,
ASTBuilder,
CallConfig,
MethodConfig,
OnCompleteAction,
Expand Down Expand Up @@ -288,7 +287,6 @@
"Break",
"Continue",
"Router",
"ASTBuilder",
"CallConfig",
"MethodConfig",
"OnCompleteAction",
Expand Down
4 changes: 2 additions & 2 deletions pyteal/ast/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
21 changes: 10 additions & 11 deletions pyteal/ast/router_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import pyteal as pt
from pyteal.ast.router import ASTBuilder

import itertools
import pytest

# import random
import typing
import algosdk.abi as sdk_abi


options = pt.CompileOptions(version=5)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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] = [
Expand Down Expand Up @@ -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
79 changes: 38 additions & 41 deletions pyteal/compiler/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit b964347

Please sign in to comment.