AlgoPytest API Reference

Account Entities

Module containing class abstractions for the various possible entities in Algorand.

class AlgoUser(address, private_key=None, name=None)[source]

Bases: object

A simple Algorand user storing an address and private key.

Parameters
  • address (str) – The base32 Algorand address of the user.

  • private_key (Optional[str]) – The private key of the user.

  • name (Optional[str]) – A name assigned to the user for better pretty-printing.

address: str

Stored user address from the constructor.

name: Optional[str] = None

Stored user name from the constructor.

private_key: Optional[str] = None

Stored user private key from the constructor.

class MultisigAccount(version, threshold, owner_accounts, name=None)[source]

Bases: AlgoUser

An Algorand user subclass representing a multi-signature account.

Parameters
  • version (int) – The version of the multi-signature account.

  • threshold (int) – The minimum number of owner signers required to operate the multi-signature account.

  • owner_accounts (List[AlgoUser]) – The owners of the multi-signature account.

  • name (Optional[str]) – A name assigned to the multi-signature account for better pretty-printing.

property attributes: Multisig

The multi-signature attributes enforced on this multi-signature account.

class SmartContractAccount(app_id, name=None)[source]

Bases: AlgoUser

An Algorand user subclass representing a smart contract’s account address.

Parameters
  • app_id (int) – The ID of the application for this account address.

  • name (Optional[str]) – A name assigned to the application account for better pretty-printing.

Transaction Operations

Module containing the transaction operations used to interact with Smart Contracts and Signatures.

Operation Context Managers

class TxnElemsContext[source]

Bases: object

Context manager to return unsent transaction objects from AlgoPytest transaction operations.

Within this context manager, all AlgoPytest transaction operations return an unsent signer-transaction pairing rather than sending the transaction into the Algorand network. This pairing can be directly re-input to other AlgoPytest transaction operations that take signer-transaction pairings as inputs, such as group_transaction.

Example

# Create a group transaction utilizing the `TxnElemsContext` context manager
with TxnElemsContext():
    txn0 = payment_transaction(sender=owner, receiver=user1, amount=10_000_000)
    txn1 = payment_transaction(sender=owner, receiver=user2, amount=10_000_000)

# Send the group transaction by supplying the unsent transactions to group
group_transaction(txn0, txn1)
class TxnIDContext[source]

Bases: object

Context manager to return sent transaction ID from AlgoPytest transaction operations.

Within this context manager, all AlgoPytest transaction operations return the sent transaction’s ID along with any usual return result as a tuple.

Smart Contract Operations

call_app(sender, app_id, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None)[source]

Perform an application call to a deployed smart contract.

Parameters
  • sender (AlgoUser) – The account to perform the application call to the smart contract.

  • app_id (int) – The application ID of the deployed smart contract.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationNoOpTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any arguments to pass along with the application call.

  • accounts (Optional[List[AlgoUser]]) – Any Algorand account addresses to pass along with the application call.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

clear_app(sender, app_id, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None)[source]

Clear from a deployed smart contract.

Parameters
  • sender (AlgoUser) – The account to clear from the smart contract.

  • app_id (int) – The application ID of the deployed smart contract.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationClearStateTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any additional arguments to the application.

  • accounts (Optional[List[AlgoUser]]) – Any additional accounts to supply to the application.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

close_out_app(sender, app_id, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None)[source]

Close-out from a deployed smart contract.

Parameters
  • sender (AlgoUser) – The account to close-out from the smart contract.

  • app_id (int) – The application ID of the deployed smart contract.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationCloseOutTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any additional arguments to the application.

  • accounts (Optional[List[AlgoUser]]) – Any additional accounts to supply to the application.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

create_app(owner, approval_program, clear_program, version=5, local_ints=0, local_bytes=0, global_ints=0, global_bytes=0, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None, extra_pages=0)[source]

Deploy a smart contract from the supplied details.

Parameters
  • owner (AlgoUser) – The user who will be the creator and owner of the smart contract.

  • approval_program (Expr) – The PyTeal expression representing the approval program.

  • clear_program (Expr) – The PyTeal expression representing the clear program.

  • version (int) – The version with which to compile the supplied PyTeal programs.

  • local_ints (int) – The local integer requirements of the smart contract application.

  • local_bytes (int) – The local bytes requirements of the smart contract application.

  • global_ints (int) – The global integer requirements of the smart contract application.

  • global_bytes (int) – The global bytes requirements of the smart contract application.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationCreateTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any additional arguments to the application.

  • accounts (Optional[List[AlgoUser]]) – Any additional accounts to supply to the application.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

  • extra_pages (int) – Provides extra program size.

Returns

A derived integer type holding the deployed application’s ID. Can be used as a regular integer, but also within a context manager to facilitate easy clean up.

Return type

DeployedAppID

create_compiled_app(owner, approval_compiled, clear_compiled, global_schema, local_schema, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None, extra_pages=0)[source]

Deploy a smart contract from the supplied details.

Parameters
  • owner (AlgoUser) – The user who will be the creator and owner of the smart contract.

  • approval_compiled (bytes) – The TEAL compiled binary code of the approval program.

  • clear_compiled (bytes) – The TEAL compiled binary code of the clear program.

  • global_schema (StateSchema) – The global state schema details.

  • local_schema (StateSchema) – The local state schema details.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationCreateTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any additional arguments to the application.

  • accounts (Optional[List[AlgoUser]]) – Any additional accounts to supply to the application.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

  • extra_pages (int) – Provides extra program size.

Returns

A derived integer type holding the deployed application’s ID. Can be used as a regular integer, but also within a context manager to facilitate easy clean up.

Return type

DeployedAppID

delete_app(owner, app_id, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None)[source]

Delete a deployed smart contract.

Parameters
  • owner (AlgoUser) – The creator of the smart contract

  • app_id (int) – The application ID of the deployed smart contract.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationDeleteTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any additional arguments to the application.

  • accounts (Optional[List[AlgoUser]]) – Any additional accounts to supply to the application.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

opt_in_app(sender, app_id, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None)[source]

Opt-in to a deployed smart contract.

Parameters
  • sender (AlgoUser) – The account to opt-in to the smart contract.

  • app_id (int) – The application ID of the deployed smart contract.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationOptInTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any additional arguments to the application.

  • accounts (Optional[List[AlgoUser]]) – Any additional accounts to supply to the application.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

update_app(owner, app_id, approval_compiled, clear_compiled, *, params=None, app_args=None, accounts=None, foreign_apps=None, foreign_assets=None, note='', lease='', rekey_to=None)[source]

Update a deployed smart contract.

Parameters
  • owner (AlgoUser) – The creator of the smart contract

  • app_id (int) – The application ID of the deployed smart contract.

  • approval_compiled (bytes) – The TEAL compiled binary code of the approval program.

  • clear_compiled (bytes) – The TEAL compiled binary code of the clear program.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the ApplicationUpdateTxn into the Algorand network.

  • app_args (Optional[List[Union[int, str]]]) – Any additional arguments to the application.

  • accounts (Optional[List[AlgoUser]]) – Any additional accounts to supply to the application.

  • foreign_apps (Optional[List[int]]) – Any other apps used by the application, identified by app index.

  • foreign_assets (Optional[List[int]]) – List of assets involved in call.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

Algorand ASA Operations

close_out_asset(sender, asset_id, receiver, *, params=None, note='', lease='', rekey_to=None)[source]

Close out an Algorand standard asset.

Parameters
  • sender (AlgoUser) – The user to close-out of the asset.

  • asset_id (int) – The ID of the asset to close-out of.

  • receiver (AlgoUser) – The user to receive the entire asset balance of the sender before closing out.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the AssetCreateTxn into the Algorand network.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

create_asset(sender, manager, reserve, freeze, clawback, asset_name, total, decimals, unit_name, default_frozen, *, params=None, url='', metadata_hash='', note='', lease='', rekey_to=None)[source]

Create an Algorand standard asset from the supplied details.

Parameters
  • sender (AlgoUser) – The user who will be the creator of the asset.

  • manager (AlgoUser) – The user with manager privileges over the asset.

  • reserve (AlgoUser) – The user representing the reserve address of the asset.

  • freeze (AlgoUser) – The user with freeze privileges over the asset.

  • clawback (AlgoUser) – The user with clawback privileges over the asset.

  • asset_name (str) – The name of the asset.

  • total (int) – The total amount of asset tokens to mint.

  • decimals (int) – The degree of divisibility of the asset.

  • unit_name (str) – The name of a unit of this asset.

  • default_frozen (bool) – Whether to freeze the holdings of this asset by default.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the AssetCreateTxn into the Algorand network.

  • url (str) – Specifies a URL where more information on the asset can be retrieved

  • metadata_hash (str) – A 32-byte hash of metadata that is relevant to your asset and/or asset holders.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Returns

A derived integer type holding the created asset’s ID. Can be used as a regular integer, but also within a context manager to facilitate easy clean up.

Return type

DeployedAssetID

destroy_asset(sender, asset_id, *, params=None, note='', lease='', rekey_to=None)[source]

Destroy an Algorand standard asset.

Parameters
  • sender (AlgoUser) – The user who created the asset.

  • asset_id (int) – The ID of the asset to destroy.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the AssetCreateTxn into the Algorand network.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

freeze_asset(sender, target, new_freeze_state, asset_id, *, params=None, note='', lease='', rekey_to=None)[source]

Freeze/unfreeze an Algorand standard asset of a target user.

Parameters
  • sender (AlgoUser) – The user who created the asset.

  • target (AlgoUser) – The user whose asset will be frozen/unfrozen.

  • new_freeze_state (bool) – Whether the asset of the target user should be frozen or not.

  • asset_id (int) – The ID of the asset to freeze/unfreeze.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the AssetCreateTxn into the Algorand network.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

opt_in_asset(sender, asset_id, *, params=None, note='', lease='', rekey_to=None)[source]

Opt-in to an Algorand standard asset.

Parameters
  • sender (AlgoUser) – The user to opt-in to the asset.

  • asset_id (int) – The ID of the asset to opt-in to.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the AssetCreateTxn into the Algorand network.

  • close_assets_to – An Algorand user to close any remainder asset balance of the sender to.

  • revocation_target – Send assets from this address rather than the sender. Can be used only by the clawback user of the asset.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

transfer_asset(sender, receiver, amount, asset_id, *, params=None, close_assets_to=None, revocation_target=None, note='', lease='', rekey_to=None)[source]

Transfer Algorand standard asset tokens to a target recipient.

Parameters
  • sender (AlgoUser) – The user to send the asset transfer.

  • receiver (AlgoUser) – The user to receive the asset transfer.

  • amount (int) – The amount of asset base units to transfer.

  • asset_id (int) – The ID of the asset to transfer.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the AssetCreateTxn into the Algorand network.

  • close_assets_to (Optional[AlgoUser]) – An Algorand user to close any remainder asset balance of the sender to.

  • revocation_target (Optional[AlgoUser]) – Send assets from this address rather than the sender. Can be used only by the clawback user of the asset.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

update_asset(sender, asset_id, *, manager, reserve, freeze, clawback, params=None, note='', lease='', rekey_to=None)[source]

Update an Algorand standard asset.

Parameters
  • sender (AlgoUser) – The user who created the asset.

  • asset_id (int) – The ID of the asset to destroy.

  • manager (Optional[AlgoUser]) – The user to take over the manager privileges over the asset.

  • reserve (Optional[AlgoUser]) – The user to take over the reserve address of the asset.

  • freeze (Optional[AlgoUser]) – The user to take over the freeze privileges over the asset.

  • clawback (Optional[AlgoUser]) – The user to take over the clawback privileges over the asset.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the AssetCreateTxn into the Algorand network.

  • note (str) – A note to attach to the application creation transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

Other Transaction Operations

group_transaction(*transactions)[source]

Send all of the supplied unsent transactions as a group transaction.

Parameters

*transactions (SignerTxnPairT) – Unsent signer-transaction pairings to send as a group. It is recommended to use the TxnElemsContext context manager to create these unsent signer-transaction pairings.

Return type

Tuple[AlgoUser, _GroupTxn]

multisig_transaction(multisig_account, transaction, signing_accounts)[source]

Send a multi-signature transaction operating on a multi-signature account.

Parameters
  • multisig_account (MultisigAccount) – The multi-signature account which the multi-signature transaction will affect.

  • transaction (SignerTxnPairT) – The transaction which will affect the multi-signature account.

  • signing_accounts (List[AlgoUser]) – The multiple accounts to sign the transaction as a multi-signature transaction.

Return type

Tuple[AlgoUser, _MultisigTxn]

payment_transaction(sender, receiver, amount, *, params=None, close_remainder_to=None, note='', lease='', rekey_to=None)[source]

Perform an Algorand payment transaction.

Parameters
  • sender (AlgoUser) – The account to send the Algorand transaction payment.

  • receiver (AlgoUser) – The account to receive the Algorand transaction payment

  • amount (int) – The amount of microAlgos (10e-6 Algos) to transact.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the PaymentTxn into the Algorand network.

  • close_remainder_to (Optional[AlgoUser]) – An Algorand address to close any remainder balance of the sender to.

  • note (str) – A note to attach to the payment transaction.

  • lease (str) – A unique lease where no other transaction from the same sender and same lease can be confirmed during the transactions valid rounds.

  • rekey_to (Optional[AlgoUser]) – An Algorand address to rekey the sender to.

Return type

None

smart_signature_transaction(smart_signature, transaction, *, params=None)[source]

Send a transaction signed by a smart signature.

Parameters
  • smart_signature (LogicSigAccount) – The smart signature to sign the transaction.

  • transaction (SignerTxnPairT) – The transaction to send singed by the smart signature.

  • params (Optional[SuggestedParams]) – Transaction parameters to use when sending the LogicSigTransaction into the Algorand network.

Return type

None

Algorand Client Functions

Module containing helper functions for accessing the Algorand blockchain.

account_balance(account)[source]

Return the balance amount for the provided account.

Parameters

account (AlgoUser) – The Algorand user whose account balance to query.

Returns

The account balance in microAlgos.

Return type

int

application_global_state(app_id, address_fields=None)[source]

Read the global state of an application.

Parameters
  • app_id (int) – The ID of the application to query for its global state.

  • address_fields (Optional[list[str]]) – The keys where the value is expected to be an Algorand address. Address values need to be encoded to get them in human-readable format.

Returns

The global state query results.

Return type

dict[str, str]

application_local_state(app_id, account, address_fields=None)[source]

Read the local sate of an account relating to an application.

Parameters
  • app_id (int) – The ID of the application to query for the local state.

  • account (AlgoUser) – The user whose local state to read.

  • address_fields (Optional[list[str]]) – The keys where the value is expected to be an Algorand address. Address values need to be encoded to get them in human-readable format.

Returns

The local state query results.

Return type

dict[str, str]

asset_balance(account, asset_id)[source]

Return the asset balance amount for the provided account and asset_id.

Parameters
  • account (AlgoUser) – The Algorand user whose asset balance to query.

  • asset_id (int) – The specific asset ID for which to query.

Returns

The account’s balance of the asset request. Returns None if the account is not opted-in to the asset.

Return type

Optional[int]

asset_info(asset_id)[source]

Return the asset information for the provided asset_id.

Parameters

asset_id (int) – The specific asset ID for which to query.

Returns

The details of the requested asset.

Return type

dict[str, Any]

compile_program(program, mode, version=5)[source]

Compiles a PyTeal smart contract program to the TEAL binary code.

Parameters
  • program (Expr) – A PyTeal expression representing an Algorand program.

  • mode (Mode) – The mode with which to compile the supplied PyTeal program.

  • version (int) – The version with which to compile the supplied PyTeal program.

Returns

The TEAL compiled binary code.

Return type

bytes

pending_transaction_info(transaction_id)[source]

Return info on the pending transaction status.

Parameters

transaction_id (int) –

Return type

dict[str, Any]

process_transactions(transactions)[source]

Send provided grouped transactions to network and wait for confirmation.

Parameters

transactions (list[TransactionT]) –

Return type

int

suggested_params(**kwargs)[source]

Return the suggested params from the algod client.

Parameters

kwargs (Any) – Parameter/value pairings to override in the transaction suggested parameters.

Returns

The suggested transaction parameters for an Algorand transaction.

Return type

SuggestedParams

transaction_info(transaction_id)[source]

Retrieve information regarding the transaction identified by transaction_id.

Parameters

transaction_id (str) – The transaction ID of the transaction to query.

Returns

The details of the requested transaction.

Return type

dict[str, Any]