Skip to content

Commit

Permalink
fix: fixed incorrect typing of algopy.arc4.abi_call parameters `glo…
Browse files Browse the repository at this point in the history
…bal_num_uint`, `global_num_bytes`, `local_num_uint`, `local_num_bytes` and `extra_program_pages`
  • Loading branch information
daniel-makerx committed Oct 7, 2024
1 parent e7f13d1 commit e464ca2
Show file tree
Hide file tree
Showing 21 changed files with 1,702 additions and 175 deletions.
2 changes: 1 addition & 1 deletion examples/sizes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
chained_assignment/ChainedAssignment 88 87 - | 30 30 -
compile/Hello 219 181 - | 105 85 -
compile/HelloBase 200 156 - | 96 74 -
compile/HelloFactory 7113 6555 - | 921 697 -
compile/HelloFactory 7275 6674 - | 1011 760 -
compile/HelloOtherConstants 306 277 - | 135 121 -
compile/HelloPrfx 213 168 - | 100 77 -
compile/HelloTmpl 213 168 - | 100 77 -
Expand Down
30 changes: 15 additions & 15 deletions stubs/algopy-stubs/arc4.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,11 @@ class _ABICallWithReturnProtocol(typing.Protocol[_TABIResult_co]):
on_completion: algopy.OnCompleteAction = ...,
approval_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
clear_state_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
global_num_uint: UInt64 | int = ...,
global_num_bytes: UInt64 | int = ...,
local_num_uint: UInt64 | int = ...,
local_num_bytes: UInt64 | int = ...,
extra_program_pages: UInt64 | int = ...,
global_num_uint: algopy.UInt64 | int = ...,
global_num_bytes: algopy.UInt64 | int = ...,
local_num_uint: algopy.UInt64 | int = ...,
local_num_bytes: algopy.UInt64 | int = ...,
extra_program_pages: algopy.UInt64 | int = ...,
fee: algopy.UInt64 | int = 0,
sender: algopy.Account | str = ...,
note: algopy.Bytes | bytes | str = ...,
Expand All @@ -537,11 +537,11 @@ class _ABICallProtocolType(typing.Protocol):
on_completion: algopy.OnCompleteAction = ...,
approval_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
clear_state_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
global_num_uint: UInt64 | int = ...,
global_num_bytes: UInt64 | int = ...,
local_num_uint: UInt64 | int = ...,
local_num_bytes: UInt64 | int = ...,
extra_program_pages: UInt64 | int = ...,
global_num_uint: algopy.UInt64 | int = ...,
global_num_bytes: algopy.UInt64 | int = ...,
local_num_uint: algopy.UInt64 | int = ...,
local_num_bytes: algopy.UInt64 | int = ...,
extra_program_pages: algopy.UInt64 | int = ...,
fee: algopy.UInt64 | int = 0,
sender: algopy.Account | str = ...,
note: algopy.Bytes | bytes | str = ...,
Expand All @@ -557,11 +557,11 @@ class _ABICallProtocolType(typing.Protocol):
on_completion: algopy.OnCompleteAction = ...,
approval_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
clear_state_program: algopy.Bytes | bytes | tuple[algopy.Bytes, ...] = ...,
global_num_uint: UInt64 | int = ...,
global_num_bytes: UInt64 | int = ...,
local_num_uint: UInt64 | int = ...,
local_num_bytes: UInt64 | int = ...,
extra_program_pages: UInt64 | int = ...,
global_num_uint: algopy.UInt64 | int = ...,
global_num_bytes: algopy.UInt64 | int = ...,
local_num_uint: algopy.UInt64 | int = ...,
local_num_bytes: algopy.UInt64 | int = ...,
extra_program_pages: algopy.UInt64 | int = ...,
fee: algopy.UInt64 | int = 0,
sender: algopy.Account | str = ...,
note: algopy.Bytes | algopy.String | bytes | str = ...,
Expand Down
2 changes: 1 addition & 1 deletion stubs/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "algorand-python"
# this version represents the version of the stub API's and should follow semver semantics
# when updating this value also update src/compile.py:MAX_SUPPORTED_ALGOPY_VERSION_EX if it is a major/minor change
# also see stubs/README.md#versioning
version = "2.1.0"
version = "2.1.1"
description = "API for writing Algorand Python Smart contracts"
authors = ["Algorand Foundation <[email protected]>"]
readme = "README.md"
Expand Down
22 changes: 22 additions & 0 deletions test_cases/compile/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,25 @@ def test_other_constants(self) -> None:

# delete the app
arc4.abi_call(HelloOtherConstants.delete, app_id=app)

@arc4.abimethod()
def test_abi_call_create_params(self) -> None:
compiled = compile_contract(Hello)
app = arc4.abi_call(
Hello.create,
String("hey"),
approval_program=compiled.approval_program,
clear_state_program=compiled.clear_state_program,
global_num_uint=compiled.global_uints,
global_num_bytes=compiled.global_bytes,
local_num_uint=compiled.local_uints,
local_num_bytes=compiled.local_bytes,
extra_program_pages=compiled.extra_program_pages,
).created_app

result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)

assert result == "hey there"

# delete the app
arc4.abi_call(Hello.delete, app_id=app)
118 changes: 104 additions & 14 deletions test_cases/compile/out/HelloFactory.approval.mir

Large diffs are not rendered by default.

131 changes: 126 additions & 5 deletions test_cases/compile/out/HelloFactory.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ __puya_arc4_router__:
// class HelloFactory(ARC4Contract):
proto 0 1
txn NumAppArgs
bz __puya_arc4_router___bare_routing@15
bz __puya_arc4_router___bare_routing@16
method "test_logicsig()address"
method "test_compile_contract()void"
method "test_compile_contract_tmpl()void"
Expand All @@ -23,8 +23,9 @@ __puya_arc4_router__:
method "test_arc4_create_large()void"
method "test_arc4_update()void"
method "test_other_constants()void"
method "test_abi_call_create_params()void"
txna ApplicationArgs 0
match __puya_arc4_router___test_logicsig_route@2 __puya_arc4_router___test_compile_contract_route@3 __puya_arc4_router___test_compile_contract_tmpl_route@4 __puya_arc4_router___test_compile_contract_prfx_route@5 __puya_arc4_router___test_compile_contract_large_route@6 __puya_arc4_router___test_arc4_create_route@7 __puya_arc4_router___test_arc4_create_tmpl_route@8 __puya_arc4_router___test_arc4_create_prfx_route@9 __puya_arc4_router___test_arc4_create_large_route@10 __puya_arc4_router___test_arc4_update_route@11 __puya_arc4_router___test_other_constants_route@12
match __puya_arc4_router___test_logicsig_route@2 __puya_arc4_router___test_compile_contract_route@3 __puya_arc4_router___test_compile_contract_tmpl_route@4 __puya_arc4_router___test_compile_contract_prfx_route@5 __puya_arc4_router___test_compile_contract_large_route@6 __puya_arc4_router___test_arc4_create_route@7 __puya_arc4_router___test_arc4_create_tmpl_route@8 __puya_arc4_router___test_arc4_create_prfx_route@9 __puya_arc4_router___test_arc4_create_large_route@10 __puya_arc4_router___test_arc4_update_route@11 __puya_arc4_router___test_other_constants_route@12 __puya_arc4_router___test_abi_call_create_params_route@13
int 0
retsub

Expand Down Expand Up @@ -164,18 +165,30 @@ __puya_arc4_router___test_other_constants_route@12:
int 1
retsub

__puya_arc4_router___bare_routing@15:
__puya_arc4_router___test_abi_call_create_params_route@13:
// compile/factory.py:296
// @arc4.abimethod()
txn OnCompletion
!
assert // OnCompletion is NoOp
txn ApplicationID
assert // is not creating
callsub test_abi_call_create_params
int 1
retsub

__puya_arc4_router___bare_routing@16:
// compile/factory.py:24
// class HelloFactory(ARC4Contract):
txn OnCompletion
bnz __puya_arc4_router___after_if_else@19
bnz __puya_arc4_router___after_if_else@20
txn ApplicationID
!
assert // is creating
int 1
retsub

__puya_arc4_router___after_if_else@19:
__puya_arc4_router___after_if_else@20:
// compile/factory.py:24
// class HelloFactory(ARC4Contract):
int 0
Expand Down Expand Up @@ -1348,3 +1361,111 @@ test_other_constants:
itxn_field Fee
itxn_submit
retsub


// test_cases.compile.factory.HelloFactory.test_abi_call_create_params() -> void:
test_abi_call_create_params:
// compile/factory.py:296-297
// @arc4.abimethod()
// def test_abi_call_create_params(self) -> None:
proto 0 0
// compile/factory.py:299-309
// app = arc4.abi_call(
// Hello.create,
// String("hey"),
// approval_program=compiled.approval_program,
// clear_state_program=compiled.clear_state_program,
// global_num_uint=compiled.global_uints,
// global_num_bytes=compiled.global_bytes,
// local_num_uint=compiled.local_uints,
// local_num_bytes=compiled.local_bytes,
// extra_program_pages=compiled.extra_program_pages,
// ).created_app
itxn_begin
// compile/factory.py:298
// compiled = compile_contract(Hello)
int 1
itxn_field GlobalNumByteSlice
byte base64 CoEBQw==
itxn_field ClearStateProgramPages
byte base64 CiACAQAmAQhncmVldGluZzEYQAADiACRiAABQ4oAATEbQQBfggMEIN86VAQkN408BNCiggA2GgCOAwACABUAICOJMRkURDEYFEQ2GgFXAgCIAD8iiTEZgQUSRDEYRCKJMRkURDEYRDYaAVcCAIgAKkkVFlcGAkxQgAQVH3x1TFCwIomBBDEZjgEAAiOJMRhEIomKAQAoi/9niYoBASMoZUSAASBQi/9QiYoAACiAAGeJ
itxn_field ApprovalProgramPages
// compile/factory.py:299-309
// app = arc4.abi_call(
// Hello.create,
// String("hey"),
// approval_program=compiled.approval_program,
// clear_state_program=compiled.clear_state_program,
// global_num_uint=compiled.global_uints,
// global_num_bytes=compiled.global_bytes,
// local_num_uint=compiled.local_uints,
// local_num_bytes=compiled.local_bytes,
// extra_program_pages=compiled.extra_program_pages,
// ).created_app
method "create(string)void"
itxn_field ApplicationArgs
// compile/factory.py:301
// String("hey"),
byte 0x0003686579
itxn_field ApplicationArgs
// compile/factory.py:299-309
// app = arc4.abi_call(
// Hello.create,
// String("hey"),
// approval_program=compiled.approval_program,
// clear_state_program=compiled.clear_state_program,
// global_num_uint=compiled.global_uints,
// global_num_bytes=compiled.global_bytes,
// local_num_uint=compiled.local_uints,
// local_num_bytes=compiled.local_bytes,
// extra_program_pages=compiled.extra_program_pages,
// ).created_app
int appl
itxn_field TypeEnum
int 0
itxn_field Fee
itxn_submit
itxn CreatedApplicationID
// compile/factory.py:311
// result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)
itxn_begin
dup
itxn_field ApplicationID
method "greet(string)string"
itxn_field ApplicationArgs
byte 0x00057468657265
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
extract 2 0
// compile/factory.py:313
// assert result == "hey there"
byte "hey there"
==
assert
// compile/factory.py:315-316
// # delete the app
// arc4.abi_call(Hello.delete, app_id=app)
itxn_begin
int DeleteApplication
itxn_field OnCompletion
itxn_field ApplicationID
method "delete()void"
itxn_field ApplicationArgs
int appl
itxn_field TypeEnum
int 0
itxn_field Fee
itxn_submit
retsub
15 changes: 14 additions & 1 deletion test_cases/compile/out/HelloFactory.arc32.json

Large diffs are not rendered by default.

62 changes: 53 additions & 9 deletions test_cases/compile/out/HelloFactory.destructured.ir
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ contract test_cases.compile.factory.HelloFactory:
subroutine test_cases.compile.factory.HelloFactory.__puya_arc4_router__() -> bool:
block@0: // L24
let tmp%0#0: uint64 = (txn NumAppArgs)
goto tmp%0#0 ? block@1 : block@15
goto tmp%0#0 ? block@1 : block@16
block@1: // abi_routing_L24
let tmp%2#0: bytes = (txna ApplicationArgs 0)
switch tmp%2#0 {method "test_logicsig()address" => block@2, method "test_compile_contract()void" => block@3, method "test_compile_contract_tmpl()void" => block@4, method "test_compile_contract_prfx()void" => block@5, method "test_compile_contract_large()void" => block@6, method "test_arc4_create()void" => block@7, method "test_arc4_create_tmpl()void" => block@8, method "test_arc4_create_prfx()void" => block@9, method "test_arc4_create_large()void" => block@10, method "test_arc4_update()void" => block@11, method "test_other_constants()void" => block@12, * => return 0u}
switch tmp%2#0 {method "test_logicsig()address" => block@2, method "test_compile_contract()void" => block@3, method "test_compile_contract_tmpl()void" => block@4, method "test_compile_contract_prfx()void" => block@5, method "test_compile_contract_large()void" => block@6, method "test_arc4_create()void" => block@7, method "test_arc4_create_tmpl()void" => block@8, method "test_arc4_create_prfx()void" => block@9, method "test_arc4_create_large()void" => block@10, method "test_arc4_update()void" => block@11, method "test_other_constants()void" => block@12, method "test_abi_call_create_params()void" => block@13, * => return 0u}
block@2: // test_logicsig_route_L26
let tmp%3#0: uint64 = (txn OnCompletion)
let tmp%4#0: bool = (! tmp%3#0)
Expand Down Expand Up @@ -102,15 +102,23 @@ contract test_cases.compile.factory.HelloFactory:
(assert tmp%47#0) // is not creating
test_cases.compile.factory.HelloFactory.test_other_constants()
return 1u
block@15: // bare_routing_L24
block@13: // test_abi_call_create_params_route_L296
let tmp%49#0: uint64 = (txn OnCompletion)
goto tmp%49#0 ? block@19 : block@16
block@16: // __algopy_default_create_L24
let tmp%50#0: uint64 = (txn ApplicationID)
let tmp%51#0: bool = (! tmp%50#0)
(assert tmp%51#0) // is creating
let tmp%50#0: bool = (! tmp%49#0)
(assert tmp%50#0) // OnCompletion is NoOp
let tmp%51#0: uint64 = (txn ApplicationID)
(assert tmp%51#0) // is not creating
test_cases.compile.factory.HelloFactory.test_abi_call_create_params()
return 1u
block@19: // after_if_else_L24
block@16: // bare_routing_L24
let tmp%53#0: uint64 = (txn OnCompletion)
goto tmp%53#0 ? block@20 : block@17
block@17: // __algopy_default_create_L24
let tmp%54#0: uint64 = (txn ApplicationID)
let tmp%55#0: bool = (! tmp%54#0)
(assert tmp%55#0) // is creating
return 1u
block@20: // after_if_else_L24
return 0u

subroutine test_cases.compile.factory.HelloFactory.test_logicsig() -> bytes:
Expand Down Expand Up @@ -490,6 +498,42 @@ contract test_cases.compile.factory.HelloFactory:
((itxn_field Fee) 0u)
itxn_submit
return

subroutine test_cases.compile.factory.HelloFactory.test_abi_call_create_params() -> void:
block@0: // L296
itxn_begin
((itxn_field GlobalNumByteSlice) 1u)
((itxn_field ClearStateProgramPages) CoEBQw==)
((itxn_field ApprovalProgramPages) CiACAQAmAQhncmVldGluZzEYQAADiACRiAABQ4oAATEbQQBfggMEIN86VAQkN408BNCiggA2GgCOAwACABUAICOJMRkURDEYFEQ2GgFXAgCIAD8iiTEZgQUSRDEYRCKJMRkURDEYRDYaAVcCAIgAKkkVFlcGAkxQgAQVH3x1TFCwIomBBDEZjgEAAiOJMRhEIomKAQAoi/9niYoBASMoZUSAASBQi/9QiYoAACiAAGeJ)
((itxn_field ApplicationArgs) method "create(string)void")
((itxn_field ApplicationArgs) 0x0003686579)
((itxn_field TypeEnum) appl)
((itxn_field Fee) 0u)
itxn_submit
let app#0: uint64 = (itxn CreatedApplicationID)
itxn_begin
((itxn_field ApplicationID) app#0)
((itxn_field ApplicationArgs) method "greet(string)string")
((itxn_field ApplicationArgs) 0x00057468657265)
((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: bytes = ((extract 2 0) tmp%0#0)
let tmp%3#0: bool = (== result#0 "hey there")
(assert tmp%3#0)
itxn_begin
((itxn_field OnCompletion) DeleteApplication)
((itxn_field ApplicationID) app#0)
((itxn_field ApplicationArgs) method "delete()void")
((itxn_field TypeEnum) appl)
((itxn_field Fee) 0u)
itxn_submit
return

program clear-state:
subroutine algopy.arc4.ARC4Contract.clear_state_program() -> bool:
Expand Down
Loading

0 comments on commit e464ca2

Please sign in to comment.