Skip to content

algopy_testing.state.box

BoxBox abstracts the reading and writing of a single value to a single box.
BoxRefBoxRef abstracts the reading and writing of boxes containing raw binary data.
BoxMapBoxMap abstracts the reading and writing of a set of boxes using a common key and

Bases: Generic[_TValue]

Box abstracts the reading and writing of a single value to a single box.

The box size will be reconfigured dynamically to fit the size of the value being assigned to it.

create(size: algopy.UInt64 | int | None = None) → bool

Section titled “create(size: algopy.UInt64 | int | None = None) → bool”

extract(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int) → algopy.Bytes

Section titled “extract(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int) → algopy.Bytes”

Extract a slice of bytes from the box.

Fails if the box does not exist, or if start_index + length > len(box)

  • Parameters:
    • start_index – The offset to start extracting bytes from
    • length – The number of bytes to extract
  • Returns: The extracted bytes

resize(new_size: algopy.UInt64 | int) → None

Section titled “resize(new_size: algopy.UInt64 | int) → None”

Resizes the box the specified new_size.

Truncating existing data if the new value is shorter or padding with zero bytes if it is longer.

  • Parameters: new_size – The new size of the box

replace(start_index: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None

Section titled “replace(start_index: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None”

Write value to the box starting at start_index.

Fails if the box does not exist, or if start_index + len(value) > len(box)

  • Parameters:
    • start_index – The offset to start writing bytes from
    • value – The bytes to be written

splice(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None

Section titled “splice(start_index: algopy.UInt64 | int, length: algopy.UInt64 | int, value: algopy.Bytes | bytes) → None”

Set box to contain its previous bytes up to index start_index, followed by bytes, followed by the original bytes of the box that began at index start_index + length

Important: This op does not resize the box If the new value is longer than the box size, it will be truncated. If the new value is shorter than the box size, it will be padded with zero bytes

  • Parameters:
    • start_index – The index to start inserting value
    • length – The number of bytes after start_index to omit from the new value
    • value – The value to be inserted.

Bases: _BoxRef

BoxRef abstracts the reading and writing of boxes containing raw binary data.

The size is configured manually, and can be set to values larger than what the AVM can handle in a single value.

Bases: Generic[_TKey, _TValue]

BoxMap abstracts the reading and writing of a set of boxes using a common key and content type.

Each composite key (prefix + key) still needs to be made available to the application via the boxes property of the Transaction.

get(key: _TKey, default: _TValue) → _TValue

Section titled “get(key: _TKey, default: _TValue) → _TValue”

maybe(key: _TKey) → tuple[_TValue, bool]

Section titled “maybe(key: _TKey) → tuple[_TValue, bool]”

Returns a Box holding the box value at key.