Skip to content

Commit

Permalink
fix: do not error when using algopy.arc4.abi_call with a method sel…
Browse files Browse the repository at this point in the history
…ector string containing no arguments
  • Loading branch information
daniel-makerx committed Aug 20, 2024
1 parent e79bef7 commit 74577c4
Show file tree
Hide file tree
Showing 40 changed files with 6,824 additions and 4,481 deletions.
4 changes: 2 additions & 2 deletions examples/sizes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
tuple_support/NestedTuples 956 613 343 613 0
tuple_support/TupleComparisons 136 68 68 68 0
tuple_support/TupleSupport 696 409 287 409 0
typed_abi_call/Greeter 2852 2437 415 2437 0
typed_abi_call/Logger 882 748 134 748 0
typed_abi_call/Greeter 3007 2588 419 2588 0
typed_abi_call/Logger 914 778 136 778 0
unary/Unary 130 67 63 67 0
unassigned_expression/Unassigned 132 107 25 107 0
undefined_phi_args/Baddie 324 284 40 284 0
Expand Down
2 changes: 1 addition & 1 deletion src/puya/awst_build/eb/arc4/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _split_signature(
if remaining:
if not name:
name = remaining
elif not args:
elif args is None:
raise CodeError(
f"invalid signature, args not well defined: {name=}, {remaining=}", location
)
Expand Down
4 changes: 4 additions & 0 deletions test_cases/typed_abi_call/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Logger(ARC4Contract):
def echo(self, value: arc4.String) -> arc4.String:
return "echo: " + value

@arc4.abimethod
def no_args(self) -> UInt64:
return UInt64(42)

@arc4.abimethod(name=LOG_METHOD_NAME)
def log_uint64(self, value: arc4.UInt64) -> None:
log(value)
Expand Down
3,192 changes: 1,665 additions & 1,527 deletions test_cases/typed_abi_call/out/Greeter.approval.mir

Large diffs are not rendered by default.

116 changes: 113 additions & 3 deletions test_cases/typed_abi_call/out/Greeter.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_cases.typed_abi_call.typed_c2c.Greeter.approval_program:
// typed_abi_call/typed_c2c.py:17
// class Greeter(ARC4Contract):
txn NumAppArgs
bz main_bare_routing@15
bz main_bare_routing@16
method "test_method_selector_kinds(application)void"
method "test_method_overload(application)void"
method "test_arg_conversion(application)void"
Expand All @@ -16,8 +16,9 @@ test_cases.typed_abi_call.typed_c2c.Greeter.approval_program:
method "test_native_uint64(application)void"
method "test_native_biguint(application)void"
method "test_native_tuple(application)void"
method "test_no_args(application)void"
txna ApplicationArgs 0
match main_test_method_selector_kinds_route@2 main_test_method_overload_route@3 main_test_arg_conversion_route@4 main_test_15plus_args_route@5 main_test_void_route@6 main_test_ref_types_route@7 main_test_native_string_route@8 main_test_native_bytes_route@9 main_test_native_uint64_route@10 main_test_native_biguint_route@11 main_test_native_tuple_route@12
match main_test_method_selector_kinds_route@2 main_test_method_overload_route@3 main_test_arg_conversion_route@4 main_test_15plus_args_route@5 main_test_void_route@6 main_test_ref_types_route@7 main_test_native_string_route@8 main_test_native_bytes_route@9 main_test_native_uint64_route@10 main_test_native_biguint_route@11 main_test_native_tuple_route@12 main_test_no_args_route@13
err // reject transaction

main_test_method_selector_kinds_route@2:
Expand Down Expand Up @@ -232,7 +233,26 @@ main_test_native_tuple_route@12:
int 1
return

main_bare_routing@15:
main_test_no_args_route@13:
// typed_abi_call/typed_c2c.py:215
// @arc4.abimethod()
txn OnCompletion
!
assert // OnCompletion is NoOp
txn ApplicationID
assert // is not creating
// typed_abi_call/typed_c2c.py:17
// class Greeter(ARC4Contract):
txna ApplicationArgs 1
btoi
txnas Applications
// typed_abi_call/typed_c2c.py:215
// @arc4.abimethod()
callsub test_no_args
int 1
return

main_bare_routing@16:
// typed_abi_call/typed_c2c.py:17
// class Greeter(ARC4Contract):
txn OnCompletion
Expand Down Expand Up @@ -1589,3 +1609,93 @@ test_native_tuple:
==
assert
retsub


// test_cases.typed_abi_call.typed_c2c.Greeter.test_no_args(app: uint64) -> void:
test_no_args:
// typed_abi_call/typed_c2c.py:215-216
// @arc4.abimethod()
// def test_no_args(self, app: Application) -> None:
proto 1 0
// typed_abi_call/typed_c2c.py:217
// result, _txn = arc4.abi_call(Logger.no_args, app_id=app)
itxn_begin
frame_dig -1
itxn_field ApplicationID
method "no_args()uint64"
itxn_field ApplicationArgs
int appl
itxn_field TypeEnum
int 0
itxn_field Fee
itxn_submit
itxn LastLog
dup
extract 4 0
swap
extract 0 4
byte 0x151f7c75
==
assert // ARC4 prefix is valid
btoi
// typed_abi_call/typed_c2c.py:218
// assert result == 42
int 42
==
assert
// typed_abi_call/typed_c2c.py:219
// arc4_result, _txn = arc4.abi_call[arc4.UInt64]("no_args()uint64", app_id=app)
itxn_begin
frame_dig -1
itxn_field ApplicationID
method "no_args()uint64"
itxn_field ApplicationArgs
int appl
itxn_field TypeEnum
int 0
itxn_field Fee
itxn_submit
itxn LastLog
dup
extract 4 0
swap
extract 0 4
byte 0x151f7c75
==
assert // ARC4 prefix is valid
// typed_abi_call/typed_c2c.py:220
// assert arc4_result == 42
byte 0x000000000000002a
b==
assert
// typed_abi_call/typed_c2c.py:222
// arc4.abi_call(Logger.no_args, app_id=app)
itxn_begin
frame_dig -1
itxn_field ApplicationID
method "no_args()uint64"
itxn_field ApplicationArgs
int appl
itxn_field TypeEnum
int 0
itxn_field Fee
itxn_submit
itxn LastLog
extract 0 4
byte 0x151f7c75
==
assert // ARC4 prefix is valid
// typed_abi_call/typed_c2c.py:223
// assert arc4.UInt64.from_log(op.ITxn.last_log()) == 42
itxn LastLog
dup
extract 4 0
swap
extract 0 4
byte 0x151f7c75
==
assert // ARC4 prefix is valid
byte 0x000000000000002a
b==
assert
retsub
20 changes: 19 additions & 1 deletion test_cases/typed_abi_call/out/Greeter.arc32.json

Large diffs are not rendered by default.

75 changes: 67 additions & 8 deletions test_cases/typed_abi_call/out/Greeter.destructured.ir
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ contract test_cases.typed_abi_call.typed_c2c.Greeter:
subroutine test_cases.typed_abi_call.typed_c2c.Greeter.approval_program() -> bool:
block@0: // L17
let tmp%0#0: bool = (txn NumAppArgs)
goto tmp%0#0 ? block@1 : block@15
goto tmp%0#0 ? block@1 : block@16
block@1: // abi_routing_L17
let tmp%1#0: bytes = (txna ApplicationArgs 0)
switch tmp%1#0 {method "test_method_selector_kinds(application)void" => block@2, method "test_method_overload(application)void" => block@3, method "test_arg_conversion(application)void" => block@4, method "test_15plus_args(application)void" => block@5, method "test_void(application)void" => block@6, method "test_ref_types(application,asset)void" => block@7, method "test_native_string(application)void" => block@8, method "test_native_bytes(application)void" => block@9, method "test_native_uint64(application)void" => block@10, method "test_native_biguint(application)void" => block@11, method "test_native_tuple(application)void" => block@12, * => fail // reject transaction}
switch tmp%1#0 {method "test_method_selector_kinds(application)void" => block@2, method "test_method_overload(application)void" => block@3, method "test_arg_conversion(application)void" => block@4, method "test_15plus_args(application)void" => block@5, method "test_void(application)void" => block@6, method "test_ref_types(application,asset)void" => block@7, method "test_native_string(application)void" => block@8, method "test_native_bytes(application)void" => block@9, method "test_native_uint64(application)void" => block@10, method "test_native_biguint(application)void" => block@11, method "test_native_tuple(application)void" => block@12, method "test_no_args(application)void" => block@13, * => fail // reject transaction}
block@2: // test_method_selector_kinds_route_L18
let tmp%2#0: uint64 = (txn OnCompletion)
let tmp%3#0: bool = (! tmp%2#0)
Expand Down Expand Up @@ -131,13 +131,24 @@ contract test_cases.typed_abi_call.typed_c2c.Greeter:
let tmp%70#0: uint64 = ((txnas Applications) tmp%69#0)
test_cases.typed_abi_call.typed_c2c.Greeter.test_native_tuple(tmp%70#0)
return 1u
block@15: // bare_routing_L17
block@13: // test_no_args_route_L215
let tmp%71#0: uint64 = (txn OnCompletion)
let not%tmp%71#0: bool = (! tmp%71#0)
(assert not%tmp%71#0) // reject transaction
let tmp%72#0: bool = (txn ApplicationID)
let tmp%73#0: bool = (! tmp%72#0)
(assert tmp%73#0) // is creating
let tmp%72#0: bool = (! tmp%71#0)
(assert tmp%72#0) // OnCompletion is NoOp
let tmp%73#0: bool = (txn ApplicationID)
(assert tmp%73#0) // is not creating
let tmp%74#0: bytes = (txna ApplicationArgs 1)
let tmp%75#0: uint64 = (btoi tmp%74#0)
let tmp%76#0: uint64 = ((txnas Applications) tmp%75#0)
test_cases.typed_abi_call.typed_c2c.Greeter.test_no_args(tmp%76#0)
return 1u
block@16: // bare_routing_L17
let tmp%77#0: uint64 = (txn OnCompletion)
let not%tmp%77#0: bool = (! tmp%77#0)
(assert not%tmp%77#0) // reject transaction
let tmp%78#0: bool = (txn ApplicationID)
let tmp%79#0: bool = (! tmp%78#0)
(assert tmp%79#0) // is creating
return 1u

subroutine test_cases.typed_abi_call.typed_c2c.Greeter.test_method_selector_kinds(app: uint64) -> void:
Expand Down Expand Up @@ -709,6 +720,54 @@ contract test_cases.typed_abi_call.typed_c2c.Greeter:
let tmp%18#0: bool = (== result1#0 result3#0)
(assert tmp%18#0)
return

subroutine test_cases.typed_abi_call.typed_c2c.Greeter.test_no_args(app: uint64) -> void:
block@0: // L215
itxn_begin
((itxn_field ApplicationID) app#0)
((itxn_field ApplicationArgs) method "no_args()uint64")
((itxn_field TypeEnum) appl)
((itxn_field Fee) 0u)
itxn_submit
let awst_tmp%0#0: bytes = (itxn LastLog)
let tmp%0#0: bytes = ((extract 4 0) awst_tmp%0#0)
let tmp%1#0: bytes = ((extract 0 4) awst_tmp%0#0)
let tmp%2#0: bool = (== tmp%1#0 0x151f7c75)
(assert tmp%2#0) // ARC4 prefix is valid
let result#0: uint64 = (btoi tmp%0#0)
let tmp%3#0: bool = (== result#0 42u)
(assert tmp%3#0)
itxn_begin
((itxn_field ApplicationID) app#0)
((itxn_field ApplicationArgs) method "no_args()uint64")
((itxn_field TypeEnum) appl)
((itxn_field Fee) 0u)
itxn_submit
let awst_tmp%1#0: bytes = (itxn LastLog)
let arc4_result#0: bytes = ((extract 4 0) awst_tmp%1#0)
let tmp%5#0: bytes = ((extract 0 4) awst_tmp%1#0)
let tmp%6#0: bool = (== tmp%5#0 0x151f7c75)
(assert tmp%6#0) // ARC4 prefix is valid
let tmp%7#0: bool = (b== arc4_result#0 0x000000000000002a)
(assert tmp%7#0)
itxn_begin
((itxn_field ApplicationID) app#0)
((itxn_field ApplicationArgs) method "no_args()uint64")
((itxn_field TypeEnum) appl)
((itxn_field Fee) 0u)
itxn_submit
let awst_tmp%2#0: bytes = (itxn LastLog)
let tmp%9#0: bytes = ((extract 0 4) awst_tmp%2#0)
let tmp%10#0: bool = (== tmp%9#0 0x151f7c75)
(assert tmp%10#0) // ARC4 prefix is valid
let awst_tmp%3#0: bytes = (itxn LastLog)
let tmp%12#0: bytes = ((extract 4 0) awst_tmp%3#0)
let tmp%13#0: bytes = ((extract 0 4) awst_tmp%3#0)
let tmp%14#0: bool = (== tmp%13#0 0x151f7c75)
(assert tmp%14#0) // ARC4 prefix is valid
let tmp%15#0: bool = (b== tmp%12#0 0x000000000000002a)
(assert tmp%15#0)
return

program clear-state:
subroutine test_cases.typed_abi_call.typed_c2c.Greeter.clear_state_program() -> bool:
Expand Down
Loading

0 comments on commit 74577c4

Please sign in to comment.