Skip to content

Commit ccde074

Browse files
committed
feat: add mock implementations for validation functionality
1 parent f84c7c2 commit ccde074

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

src/_algopy_testing/arc4.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def bytes(self) -> algopy.Bytes:
158158

159159
return algopy.Bytes(self._value)
160160

161+
def validate(self) -> None:
162+
pass
163+
161164
def __eq__(self, other: object) -> bool:
162165
if isinstance(other, _ABIEncoded):
163166
return self._type_info == other._type_info and self.bytes == other.bytes

src/_algopy_testing/decorators/arc4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def abimethod( # noqa: PLR0913
151151
resource_encoding: _ResourceEncoding = "value",
152152
readonly: bool = False,
153153
default_args: Mapping[str, str | object] | None = None,
154+
validate_encoding: typing.Literal["unsafe_disabled", "args"] = "args", # noqa: ARG001
154155
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]] | Callable[_P, _R]:
155156
from _algopy_testing.utilities.log import log
156157

src/_algopy_testing/models/account.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def bytes(self) -> Bytes:
128128
def public_key(self) -> str:
129129
return algosdk.encoding.encode_address(self._public_key) # type: ignore[no-any-return]
130130

131+
def validate(self) -> None:
132+
pass
133+
131134
def __getattr__(self, name: str) -> typing.Any:
132135
try:
133136
return self.data.fields[name] # type: ignore[literal-required]

src/_algopy_testing/primitives/array.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ def serialize(self) -> bytes:
144144
def from_bytes(cls, value: bytes, /) -> typing.Self:
145145
return deserialize_from_bytes(cls, value)
146146

147+
def validate(self) -> None:
148+
pass
149+
147150

148151
class _FixedArrayMeta(type, typing.Generic[_TArrayItem, _TArrayLength]):
149152
__concrete__: typing.ClassVar[dict[tuple[type, type], type]] = {}
@@ -255,6 +258,9 @@ def serialize(self) -> bytes:
255258
def from_bytes(cls, value: bytes, /) -> typing.Self:
256259
return deserialize_from_bytes(cls, value)
257260

261+
def validate(self) -> None:
262+
pass
263+
258264

259265
class _ImmutableArrayMeta(type):
260266
__concrete__: typing.ClassVar[dict[type, type]] = {}
@@ -362,6 +368,9 @@ def serialize(self) -> bytes:
362368
def from_bytes(cls, value: bytes, /) -> typing.Self:
363369
return deserialize_from_bytes(cls, value)
364370

371+
def validate(self) -> None:
372+
pass
373+
365374

366375
class ReferenceArray(Reversible[_TArrayItem]):
367376
def __init__(self, values: Iterable[_TArrayItem] = ()):
@@ -510,6 +519,9 @@ def serialize(self) -> bytes:
510519
def from_bytes(cls, value: bytes, /) -> typing.Self:
511520
return deserialize_from_bytes(cls, value)
512521

522+
def validate(self) -> None:
523+
pass
524+
513525

514526
@typing.dataclass_transform()
515527
class Struct(Serializable, MutableBytes):
@@ -558,6 +570,9 @@ def from_bytes(cls, value: bytes, /) -> typing.Self:
558570
def _update_backing_value(self) -> None:
559571
self._value = serialize_to_bytes(self)
560572

573+
def validate(self) -> None:
574+
pass
575+
561576

562577
def zero_bytes(typ: type[_T]) -> _T:
563578
# Get the static size of the type

tests/artifacts/Arc4ABIMethod/contract.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def create(self) -> None:
3333
assert app_txn.app_id == 0, "expected txn to have 0"
3434
assert Txn.application_id == 0, "expected txn to have 0"
3535

36-
@arc4.abimethod
36+
@arc4.abimethod(validate_encoding="unsafe_disabled")
3737
def sink(self, value: arc4.String, arr: UInt8Array) -> None:
3838
assert value
3939
assert arr
@@ -84,6 +84,7 @@ def with_acc(self, value: arc4.String, acc: Account, arr: UInt8Array) -> None:
8484
def complex_sig(
8585
self, struct1: MyStruct, txn: algopy.gtxn.Transaction, acc: Account, five: UInt8Array
8686
) -> tuple[MyStructAlias, MyStruct]:
87+
five.validate()
8788
assert Txn.num_app_args == 4
8889
# struct
8990
assert struct1.another_struct.one == 1
@@ -123,6 +124,7 @@ def echo_resource_by_index(
123124
def echo_resource_by_value(
124125
self, asset: Asset, app: Application, acc: Account
125126
) -> tuple[Asset, Application, Account]:
127+
acc.validate()
126128
asset_id = op.btoi(Txn.application_args(1))
127129
assert asset.id == asset_id, "expected asset to be passed by value"
128130
app_id = op.btoi(Txn.application_args(2))

tests/artifacts/Arrays/immutable.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def test_biguint_array(self) -> None:
155155
@arc4.abimethod()
156156
def test_bool_array(self, length: UInt64) -> None:
157157
arr = ImmutableArray[bool]()
158+
arr.validate() # does nothing but should still be callable
158159
assert arr.length == 0
159160

160161
for i in urange(length):

0 commit comments

Comments
 (0)