Skip to content

Commit c8ef39a

Browse files
authored
Add manual test for 15+ args in abi router (#375)
1 parent c56d837 commit c8ef39a

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

pyteal/ast/router_test.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def test_wrap_handler_method_call():
413413
)
414414
for abi_subroutine in ONLY_ABI_SUBROUTINE_CASES:
415415
wrapped: pt.Expr = ASTBuilder.wrap_handler(True, abi_subroutine)
416-
assembled_wrapped: pt.TealBlock = assemble_helper(wrapped)
416+
actual: pt.TealBlock = assemble_helper(wrapped)
417417

418418
args: list[pt.abi.BaseType] = [
419419
spec.new_instance()
@@ -461,9 +461,60 @@ def test_wrap_handler_method_call():
461461
else:
462462
evaluate = abi_subroutine(*args)
463463

464-
actual = assemble_helper(pt.Seq(*loading, evaluate, pt.Approve()))
464+
expected = assemble_helper(pt.Seq(*loading, evaluate, pt.Approve()))
465465
with pt.TealComponent.Context.ignoreScratchSlotEquality(), pt.TealComponent.Context.ignoreExprEquality():
466-
assert actual == assembled_wrapped
466+
assert actual == expected
467+
468+
assert pt.TealBlock.MatchScratchSlotReferences(
469+
pt.TealBlock.GetReferencedScratchSlots(actual),
470+
pt.TealBlock.GetReferencedScratchSlots(expected),
471+
)
472+
473+
474+
def test_wrap_handler_method_call_many_args():
475+
wrapped: pt.Expr = ASTBuilder.wrap_handler(True, many_args)
476+
actual: pt.TealBlock = assemble_helper(wrapped)
477+
478+
args = [pt.abi.Uint64() for _ in range(20)]
479+
last_arg = pt.abi.TupleTypeSpec(
480+
*[pt.abi.Uint64TypeSpec() for _ in range(6)]
481+
).new_instance()
482+
483+
output_temp = pt.abi.Uint64()
484+
expected_ast = pt.Seq(
485+
args[0].decode(pt.Txn.application_args[1]),
486+
args[1].decode(pt.Txn.application_args[2]),
487+
args[2].decode(pt.Txn.application_args[3]),
488+
args[3].decode(pt.Txn.application_args[4]),
489+
args[4].decode(pt.Txn.application_args[5]),
490+
args[5].decode(pt.Txn.application_args[6]),
491+
args[6].decode(pt.Txn.application_args[7]),
492+
args[7].decode(pt.Txn.application_args[8]),
493+
args[8].decode(pt.Txn.application_args[9]),
494+
args[9].decode(pt.Txn.application_args[10]),
495+
args[10].decode(pt.Txn.application_args[11]),
496+
args[11].decode(pt.Txn.application_args[12]),
497+
args[12].decode(pt.Txn.application_args[13]),
498+
args[13].decode(pt.Txn.application_args[14]),
499+
last_arg.decode(pt.Txn.application_args[15]),
500+
last_arg[0].store_into(args[14]),
501+
last_arg[1].store_into(args[15]),
502+
last_arg[2].store_into(args[16]),
503+
last_arg[3].store_into(args[17]),
504+
last_arg[4].store_into(args[18]),
505+
last_arg[5].store_into(args[19]),
506+
many_args(*args).store_into(output_temp),
507+
pt.abi.MethodReturn(output_temp),
508+
pt.Approve(),
509+
)
510+
expected = assemble_helper(expected_ast)
511+
with pt.TealComponent.Context.ignoreScratchSlotEquality(), pt.TealComponent.Context.ignoreExprEquality():
512+
assert actual == expected
513+
514+
assert pt.TealBlock.MatchScratchSlotReferences(
515+
pt.TealBlock.GetReferencedScratchSlots(actual),
516+
pt.TealBlock.GetReferencedScratchSlots(expected),
517+
)
467518

468519

469520
def test_contract_json_obj():

pyteal/ir/tealcomponent.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ def __exit__(self, *args):
6767

6868
@classmethod
6969
def ignoreScratchSlotEquality(cls):
70+
"""When comparing TealOps, do not verify the equality of any ScratchSlot arguments.
71+
72+
This is commonly used in testing to verify the that two control flow graphs contains the
73+
same operations, but may use different ScratchSlots in them. In this case, you will most
74+
likely want to also use use the following code after comparing with this option enabled:
75+
76+
.. code-block:: python
77+
TealBlock.MatchScratchSlotReferences(
78+
TealBlock.GetReferencedScratchSlots(actual),
79+
TealBlock.GetReferencedScratchSlots(expected),
80+
)
81+
82+
This ensures that the ScratchSlot usages between the two control flow graphs is
83+
equivalent. See :any:`TealBlock.MatchScratchSlotReferences` for more info.
84+
"""
7085
return cls.ScratchSlotEqualityContext()
7186

7287

0 commit comments

Comments
 (0)