@@ -150,6 +150,11 @@ def not_registrable(lhs: pt.abi.Uint64, rhs: pt.Expr, *, output: pt.abi.Uint64):
150150 return output .set (lhs .get () * rhs )
151151
152152
153+ @pt .ABIReturnSubroutine
154+ def txn_amount (t : pt .abi .PaymentTransaction , * , output : pt .abi .Uint64 ):
155+ return output .set (t .get ().amount ())
156+
157+
153158GOOD_SUBROUTINE_CASES : list [pt .ABIReturnSubroutine | pt .SubroutineFnWrapper ] = [
154159 add ,
155160 sub ,
@@ -164,6 +169,7 @@ def not_registrable(lhs: pt.abi.Uint64, rhs: pt.Expr, *, output: pt.abi.Uint64):
164169 dummy_doing_nothing ,
165170 eine_constant ,
166171 take_abi_and_log ,
172+ txn_amount ,
167173]
168174
169175ON_COMPLETE_CASES : list [pt .EnumInt ] = [
@@ -411,6 +417,7 @@ def test_wrap_handler_method_call():
411417 ONLY_ABI_SUBROUTINE_CASES = list (
412418 filter (lambda x : isinstance (x , pt .ABIReturnSubroutine ), GOOD_SUBROUTINE_CASES )
413419 )
420+
414421 for abi_subroutine in ONLY_ABI_SUBROUTINE_CASES :
415422 wrapped : pt .Expr = ASTBuilder .wrap_handler (True , abi_subroutine )
416423 actual : pt .TealBlock = assemble_helper (wrapped )
@@ -422,35 +429,55 @@ def test_wrap_handler_method_call():
422429 )
423430 ]
424431
425- loading : list [pt .Expr ]
432+ app_args = [
433+ arg for arg in args if arg .type_spec () not in pt .abi .TransactionTypeSpecs
434+ ]
435+
436+ app_arg_cnt = len (app_args )
437+
438+ txn_args = [
439+ arg for arg in args if arg .type_spec () in pt .abi .TransactionTypeSpecs
440+ ]
426441
427- if abi_subroutine .subroutine .argument_count () > pt .METHOD_ARG_NUM_CUTOFF :
442+ loading : list [pt .Expr ] = []
443+
444+ if app_arg_cnt > pt .METHOD_ARG_NUM_CUTOFF :
428445 sdk_last_arg = pt .abi .TupleTypeSpec (
429- * [
430- spec
431- for spec in typing .cast (
432- list [pt .abi .TypeSpec ],
433- abi_subroutine .subroutine .expected_arg_types ,
434- )[pt .METHOD_ARG_NUM_CUTOFF - 1 :]
435- ]
446+ * [arg .type_spec () for arg in app_args [pt .METHOD_ARG_NUM_CUTOFF - 1 :]]
436447 ).new_instance ()
448+
437449 loading = [
438450 arg .decode (pt .Txn .application_args [index + 1 ])
439- for index , arg in enumerate (args [: pt .METHOD_ARG_NUM_CUTOFF - 1 ])
451+ for index , arg in enumerate (app_args [: pt .METHOD_ARG_NUM_CUTOFF - 1 ])
440452 ]
453+
441454 loading .append (
442455 sdk_last_arg .decode (pt .Txn .application_args [pt .METHOD_ARG_NUM_CUTOFF ])
443456 )
444- for i in range (pt .METHOD_ARG_NUM_CUTOFF - 1 , len (args )):
445- loading .append (
446- sdk_last_arg [i - pt .METHOD_ARG_NUM_CUTOFF + 1 ].store_into (args [i ])
447- )
448457 else :
449458 loading = [
450459 arg .decode (pt .Txn .application_args [index + 1 ])
451- for index , arg in enumerate (args )
460+ for index , arg in enumerate (app_args )
452461 ]
453462
463+ if len (txn_args ) > 0 :
464+ loading .extend (
465+ [
466+ typing .cast (pt .abi .Transaction , txn_arg ).set (
467+ pt .Txn .group_index () - pt .Int (len (txn_args ) - idx )
468+ )
469+ for idx , txn_arg in enumerate (txn_args )
470+ ]
471+ )
472+
473+ if app_arg_cnt > pt .METHOD_ARG_NUM_CUTOFF :
474+ loading .extend (
475+ [
476+ sdk_last_arg [idx ].store_into (val )
477+ for idx , val in enumerate (app_args [pt .METHOD_ARG_NUM_CUTOFF - 1 :])
478+ ]
479+ )
480+
454481 evaluate : pt .Expr
455482 if abi_subroutine .type_of () != "void" :
456483 output_temp = abi_subroutine .output_kwarg_info .abi_type .new_instance ()
0 commit comments