_algopy_testing.context_helpers.ledger_context

Module Contents

Classes

LedgerContext

Context for managing the ledger state.

API

class LedgerContext

Context for managing the ledger state.

Initialization

get_account(address: str) algopy.Account

Get an account by address.

Args: address (str): The account address.

Returns: algopy.Account: The account object.

account_exists(address: str) bool

Check if an account exists.

Args: address (str): The account address.

Returns: bool: True if the account exists, False otherwise.

update_account(
address: str,
opted_asset_balances: dict[int, algopy.UInt64] | None = None,
**account_fields: Unpack[_algopy_testing.models.account.AccountFields],
) None

Update account fields.

Args: address (str): The account address. opted_asset_balances (dict[int, algopy.UInt64] | None): The opted asset balances . **account_fields: The fields to update.

get_asset(asset_id: algopy.UInt64 | int) algopy.Asset

Get an asset by ID.

Args: asset_id (algopy.UInt64 | int): The asset ID.

Returns: algopy.Asset: The asset object.

Raises: ValueError: If the asset is not found.

asset_exists(asset_id: algopy.UInt64 | int) bool

Check if an asset exists.

Args: asset_id (algopy.UInt64 | int): The asset ID.

Returns: bool: True if the asset exists, False otherwise.

update_asset(
asset_id: int,
**asset_fields: Unpack[_algopy_testing.models.asset.AssetFields],
) None

Update asset fields.

Args: asset_id (int): The asset ID. **asset_fields: The fields to update.

Raises: ValueError: If the asset is not found.

get_app(
app_id: algopy.Contract | algopy.Application | algopy.UInt64 | int,
) algopy.Application

Get an application by ID, contract or app reference.

Args: int, auto extracts id from contract or app reference.

Returns: algopy.Application: The application object.

app_exists(app_id: algopy.UInt64 | int) bool

Check if an application exists.

Args: app (algopy.UInt64 | int): The application ID.

Returns: bool: True if the application exists, False otherwise.

update_app(
app_id: int,
**application_fields: Unpack[_algopy_testing.models.application.ApplicationFields],
) None

Update application fields.

Args: app_id (int): The application ID. **application_fields: The fields to update.

get_global_state(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
key: bytes | algopy.Bytes,
) int | bytes

Get global state for an application.

Args: app: The application identifier. key: The state key.

Returns: int | bytes: The state value.

set_global_state(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
key: bytes | algopy.Bytes,
value: int | bytes | None,
) None

Set global state for an application.

Args: app: The application identifier. key: The state key. value: The state value.

get_local_state(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
account: algopy.Account | str,
key: algopy.Bytes | bytes,
) int | bytes

Get local state for an application and account.

Args: app: The application identifier. account: The account identifier. key: The state key.

Returns: int | bytes: The state value.

set_local_state(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
account: algopy.Account | str,
key: algopy.Bytes | bytes,
value: int | bytes | None,
) None

Set local state for an application and account.

Args: app: The application identifier. account: The account identifier. key: The state key. value: The state value.

get_box(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
key: algopy.Bytes | bytes,
) bytes

Get box content for an application.

Args: app: The application identifier. key: The box key.

Returns: bytes: The box content.

set_box(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
key: algopy.Bytes | bytes,
value: algopy.Bytes | bytes,
) None

Set box content for an application.

Args: app: The application identifier. key: The box key. value: The box content.

delete_box(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
key: algopy.Bytes | bytes,
) bool

Delete a box for an application.

Args: app: The application identifier. key: The box key.

Returns: bool: True if the box was deleted, False if it didn’t exist.

box_exists(
app: algopy.Contract | algopy.Application | algopy.UInt64 | int,
key: algopy.Bytes | bytes,
) bool

Check if a box exists for an application.

Args: app: The application identifier. key: The box key.

Returns: bool: True if the box exists, False otherwise.

set_block(
index: int,
seed: algopy.UInt64 | int,
timestamp: algopy.UInt64 | int,
) None

Set block content.

Args: index (int): The block index. seed (algopy.UInt64 | int): The block seed. timestamp (algopy.UInt64 | int): The block timestamp.

get_block_content(index: int, key: str) int

Get block content.

Args: index (int): The block index. key (str): The content key.

Returns: int: The block content value.

Raises: ValueError: If the block content is not found.

patch_global_fields(
**global_fields: Unpack[_algopy_testing.op.global_values.GlobalFields],
) None

Patch global fields.

Args: **global_fields: The fields to patch.

Raises: AttributeError: If invalid fields are provided.