Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
See which `algorand-python` stubs are implemented by the `algorand-python-testing` library. See the [Concepts](testing-guide/concepts.md#types-of-algopy-stub-implementations) section for more details on the implementation categories. Refer to the [`algorand-python` stubs API](api.md) for the full list of stubs for which the `algorand-python-testing` library provides implementations referenced in the table below.

| Name | Implementation type |
|---------------------------------------------|---------------------|
| ------------------------------------------- | ------------------- |
| algopy.Account | Emulated |
| algopy.Application | Emulated |
| algopy.Asset | Emulated |
Expand All @@ -18,6 +18,7 @@ See which `algorand-python` stubs are implemented by the `algorand-python-testin
| algopy.CompiledLogicSig | Mockable |
| algopy.Contract | Emulated |
| algopy.FixedArray | Native |
| algopy.FixedBytes | Native |
| algopy.Global | Emulated |
| algopy.GlobalState | Emulated |
| algopy.ImmutableArray | Native |
Expand Down
14 changes: 14 additions & 0 deletions docs/testing-guide/avm-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ random_bytes = context.any.bytes()
random_bytes = context.any.bytes(length=32)
```

## FixedBytes

```{testcode}
# Direct instantiation
bytes_value = algopy.FixedBytes[typing.Literal[16]](b"Hello, Algorand!")


# Instantiate test context
...

# Generate random byte sequences of length 32
random_bytes = context.any.fixed_bytes(FixedBytes[typing.Literal[32]])
```

## String

```{testcode}
Expand Down
3 changes: 2 additions & 1 deletion src/_algopy_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
uenumerate,
urange,
)
from _algopy_testing.primitives import BigUInt, Bytes, String, UInt64
from _algopy_testing.primitives import BigUInt, Bytes, FixedBytes, String, UInt64
from _algopy_testing.state import Box, BoxMap, BoxRef, GlobalState, LocalState
from _algopy_testing.value_generators.arc4 import ARC4ValueGenerator
from _algopy_testing.value_generators.avm import AVMValueGenerator
Expand All @@ -39,6 +39,7 @@
"BoxRef",
"Bytes",
"Contract",
"FixedBytes",
"GlobalState",
"ITxnGroupLoader",
"ITxnLoader",
Expand Down
4 changes: 3 additions & 1 deletion src/_algopy_testing/decorators/arc4.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from _algopy_testing.constants import ALWAYS_APPROVE_TEAL_PROGRAM, ARC4_RETURN_PREFIX
from _algopy_testing.context_helpers import lazy_context
from _algopy_testing.enums import OnCompleteAction
from _algopy_testing.primitives import BigUInt, Bytes, String, UInt64
from _algopy_testing.primitives import BigUInt, Bytes, FixedBytes, String, UInt64

_P = typing.ParamSpec("_P")
_R = typing.TypeVar("_R")
Expand Down Expand Up @@ -418,6 +418,8 @@ def _type_to_arc4( # noqa: PLR0912 PLR0911
return "uint512"
if issubclass(annotation, Bytes):
return "byte[]"
if issubclass(annotation, FixedBytes):
return f"byte[{annotation._length}]"
if issubclass(annotation, bool):
return "bool"
raise TypeError(f"type not a valid ARC4 type: {annotation}")
Expand Down
2 changes: 2 additions & 0 deletions src/_algopy_testing/primitives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from _algopy_testing.primitives.biguint import BigUInt
from _algopy_testing.primitives.bytes import Bytes
from _algopy_testing.primitives.fixed_bytes import FixedBytes
from _algopy_testing.primitives.string import String
from _algopy_testing.primitives.uint64 import UInt64

Expand All @@ -17,6 +18,7 @@
"BigUInt",
"Bytes",
"FixedArray",
"FixedBytes",
"ImmutableArray",
"ImmutableFixedArray",
"ReferenceArray",
Expand Down
11 changes: 5 additions & 6 deletions src/_algopy_testing/primitives/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
if TYPE_CHECKING:
from collections.abc import Iterator

from _algopy_testing.primitives.fixed_bytes import FixedBytes


from itertools import zip_longest

Expand All @@ -27,7 +29,7 @@ def __init__(self, value: bytes = b"") -> None:
check_type(value, bytes)
self.value = as_bytes(value)

def __contains__(self, item: Bytes | bytes) -> bool:
def __contains__(self, item: Bytes | FixedBytes | bytes) -> bool: # type: ignore[type-arg]
item_bytes = as_bytes(item)
return item_bytes in self.value

Expand All @@ -43,11 +45,8 @@ def __bool__(self) -> bool:
def __add__(self, other: Bytes | bytes) -> Bytes:
"""Concatenate Bytes with another Bytes or bytes literal e.g. `Bytes(b"Hello ")
+ b"World"`."""
if isinstance(other, Bytes):
return _checked_result(self.value + other.value, "+")
else:
result = self.value + as_bytes(other)
return _checked_result(result, "+")
result = self.value + as_bytes(other)
return _checked_result(result, "+")

def __radd__(self, other: bytes) -> Bytes:
"""Concatenate Bytes with another Bytes or bytes literal e.g. `b"Hello " +
Expand Down
Loading
Loading