Skip to content

Commit 116a88f

Browse files
committed
new test case and corner case for array casees
1 parent 9bc879d commit 116a88f

File tree

2 files changed

+101
-3
lines changed

2 files changed

+101
-3
lines changed

pyteal/ast/abi/util.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ def type_spec_is_assignable(a: TypeSpec, b: TypeSpec) -> bool:
507507
ArrayTypeSpec,
508508
StaticArrayTypeSpec,
509509
DynamicArrayTypeSpec,
510+
StringTypeSpec,
511+
AddressTypeSpec,
510512
)
511513

512514
match a, b:
@@ -532,9 +534,20 @@ def type_spec_is_assignable(a: TypeSpec, b: TypeSpec) -> bool:
532534
return a.length_static() == b.length_static()
533535
case DynamicArrayTypeSpec(), DynamicArrayTypeSpec():
534536
return True
535-
case _:
536-
return False
537-
case ArrayTypeSpec(), _:
537+
return False
538+
case (ArrayTypeSpec(), _) | (_, ArrayTypeSpec()):
539+
if isinstance(b, ArrayTypeSpec):
540+
a, b = b, a
541+
match a, b:
542+
case DynamicArrayTypeSpec(), StringTypeSpec():
543+
a, b = cast(DynamicArrayTypeSpec, a), cast(StringTypeSpec, b)
544+
return a.value_type_spec() == b.value_type_spec()
545+
case StaticArrayTypeSpec(), AddressTypeSpec():
546+
a, b = cast(StaticArrayTypeSpec, a), cast(AddressTypeSpec, b)
547+
return (
548+
a.value_type_spec() == b.value_type_spec()
549+
and a.length_static() == b.length_static()
550+
)
538551
return False
539552

540553
if isinstance(a, type(b)):

pyteal/ast/abi/util_test.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,21 @@ class NamedTDecl(abi.NamedTuple):
781781
c: abi.Field[abi.Transaction]
782782

783783

784+
class NamedTComp0(abi.NamedTuple):
785+
a0: abi.Field[abi.String]
786+
a1: abi.Field[abi.StaticArray[abi.Byte, Literal[32]]]
787+
788+
789+
class NamedTComp1(abi.NamedTuple):
790+
b0: abi.Field[abi.DynamicBytes]
791+
b1: abi.Field[abi.Address]
792+
793+
794+
class NamedTComp2(abi.NamedTuple):
795+
b1: abi.Field[abi.Address]
796+
b0: abi.Field[abi.DynamicBytes]
797+
798+
784799
TYPE_SPEC_ASSIGNABLE_CASES = [
785800
(abi.PaymentTransactionTypeSpec(), abi.TransactionTypeSpec(), True),
786801
(
@@ -841,6 +856,76 @@ class NamedTDecl(abi.NamedTuple):
841856
abi.type_spec_from_annotation(NamedTDecl),
842857
True,
843858
),
859+
(
860+
abi.type_spec_from_annotation(abi.StaticBytes[Literal[7]]),
861+
abi.type_spec_from_annotation(abi.StaticArray[abi.Byte, Literal[11]]),
862+
False,
863+
),
864+
(
865+
abi.type_spec_from_annotation(NamedTDecl),
866+
abi.type_spec_from_annotation(NamedTDecl),
867+
True,
868+
),
869+
(
870+
abi.type_spec_from_annotation(abi.String),
871+
abi.type_spec_from_annotation(abi.DynamicBytes),
872+
True,
873+
),
874+
(
875+
abi.type_spec_from_annotation(abi.DynamicArray[abi.Byte]),
876+
abi.type_spec_from_annotation(abi.String),
877+
True,
878+
),
879+
(
880+
abi.type_spec_from_annotation(abi.DynamicArray[abi.Uint32]),
881+
abi.type_spec_from_annotation(abi.String),
882+
False,
883+
),
884+
(
885+
abi.type_spec_from_annotation(abi.Address),
886+
abi.type_spec_from_annotation(abi.StaticArray[abi.Byte, Literal[32]]),
887+
True,
888+
),
889+
(
890+
abi.type_spec_from_annotation(abi.StaticBytes[Literal[32]]),
891+
abi.type_spec_from_annotation(abi.Address),
892+
True,
893+
),
894+
(
895+
abi.type_spec_from_annotation(abi.StaticBytes[Literal[33]]),
896+
abi.type_spec_from_annotation(abi.Address),
897+
False,
898+
),
899+
(
900+
abi.type_spec_from_annotation(NamedTComp0),
901+
abi.type_spec_from_annotation(NamedTComp1),
902+
True,
903+
),
904+
(
905+
abi.type_spec_from_annotation(NamedTComp1),
906+
abi.type_spec_from_annotation(NamedTComp0),
907+
True,
908+
),
909+
(
910+
abi.type_spec_from_annotation(NamedTDecl),
911+
abi.type_spec_from_annotation(NamedTComp0),
912+
False,
913+
),
914+
(
915+
abi.type_spec_from_annotation(NamedTComp2),
916+
abi.type_spec_from_annotation(NamedTComp0),
917+
False,
918+
),
919+
(
920+
abi.type_spec_from_annotation(abi.String),
921+
abi.type_spec_from_annotation(abi.DynamicArray[abi.Uint64]),
922+
False,
923+
),
924+
(
925+
abi.type_spec_from_annotation(abi.DynamicArray[abi.Uint64]),
926+
abi.type_spec_from_annotation(abi.String),
927+
False,
928+
),
844929
]
845930

846931

0 commit comments

Comments
 (0)