3737)
3838
3939if typing .TYPE_CHECKING :
40- from collections .abc import Iterable , Iterator , Sequence
40+ from collections .abc import Callable , Iterable , Iterator , Sequence
4141
4242 import algopy
4343
5656 "Struct" ,
5757 "Tuple" ,
5858 "UFixedNxM" ,
59- "UInt128 " ,
59+ "UInt8 " ,
6060 "UInt16" ,
61- "UInt256" ,
6261 "UInt32" ,
63- "UInt512" ,
6462 "UInt64" ,
65- "UInt8" ,
63+ "UInt128" ,
64+ "UInt256" ,
65+ "UInt512" ,
6666 "UIntN" ,
6767 "abi_call" ,
6868 "arc4_create" ,
69- "arc4_update" ,
7069 "arc4_signature" ,
70+ "arc4_update" ,
7171 "emit" ,
7272]
7373
7474_ABI_LENGTH_SIZE = 2
7575_TBitSize = typing .TypeVar ("_TBitSize" , bound = int )
7676
77+ _P = typing .ParamSpec ("_P" )
78+ _R = typing .TypeVar ("_R" )
79+
7780
7881class _TypeInfo :
7982 @property
@@ -179,12 +182,22 @@ def __hash__(self) -> int:
179182 return hash (self .bytes )
180183
181184
182- def arc4_signature (signature : str , / ) -> algopy .Bytes :
185+ def arc4_signature (signature : str | Callable [ _P , _R ] , / ) -> algopy .Bytes :
183186 """Convert a signature to ARC4 bytes."""
184187 import algopy
185188
189+ from _algopy_testing .decorators .arc4 import get_arc4_metadata
190+
191+ if isinstance (signature , str ):
192+ method_signature = signature
193+ else :
194+ arc4_signature = get_arc4_metadata (signature ).arc4_signature
195+ if arc4_signature is None :
196+ raise ValueError ("signature not found" )
197+ method_signature = arc4_signature
198+
186199 hashed_signature = SHA512 .new (truncate = "256" )
187- hashed_signature .update (signature .encode ("utf-8" ))
200+ hashed_signature .update (method_signature .encode ("utf-8" ))
188201 return_value = hashed_signature .digest ()[:4 ]
189202 return algopy .Bytes (return_value )
190203
@@ -1187,11 +1200,17 @@ def _find_bool(
11871200) -> int :
11881201 """Helper function to find consecutive booleans from current index in a tuple."""
11891202 until = 0
1203+ is_looking_forward = delta > 0
1204+ is_looking_backward = delta < 0
11901205 values_length = len (values ) if isinstance (values , tuple | list ) else values .length .value
11911206 while True :
11921207 curr = index + delta * until
1208+ is_curr_at_end = curr == values_length - 1
1209+ is_curr_at_start = curr == 0
11931210 if isinstance (values [curr ], Bool ):
1194- if curr != values_length - 1 and delta > 0 or curr > 0 and delta < 0 :
1211+ if (is_looking_forward and not is_curr_at_end ) or (
1212+ is_looking_backward and not is_curr_at_start
1213+ ):
11951214 until += 1
11961215 else :
11971216 break
@@ -1204,11 +1223,17 @@ def _find_bool(
12041223def _find_bool_types (values : typing .Sequence [_TypeInfo ], index : int , delta : int ) -> int :
12051224 """Helper function to find consecutive booleans from current index in a tuple."""
12061225 until = 0
1226+ is_looking_forward = delta > 0
1227+ is_looking_backward = delta < 0
12071228 values_length = len (values )
12081229 while True :
12091230 curr = index + delta * until
1231+ is_curr_at_end = curr == values_length - 1
1232+ is_curr_at_start = curr == 0
12101233 if isinstance (values [curr ], _BoolTypeInfo ):
1211- if curr != values_length - 1 and delta > 0 or curr > 0 and delta < 0 :
1234+ if (is_looking_forward and not is_curr_at_end ) or (
1235+ is_looking_backward and not is_curr_at_start
1236+ ):
12121237 until += 1
12131238 else :
12141239 break
0 commit comments