Testing Guide¶
The Algorand Python Testing framework provides powerful tools for testing Algorand Python smart contracts within a Python interpreter. This guide covers the main features and concepts of the framework, helping you write effective tests for your Algorand applications.
Note
For all code examples in the Testing Guide section, assume context
is an instance of AlgopyTestContext
obtained using the algopy_testing_context()
context manager. All subsequent code is executed within this context.
(You are here 📍)"] C["puya (compiler)"] end subgraph GB["Your Algorand Project"] D[Your Algorand Python contract] end D -->|type hints inferred from| A D -->|compiled using| C D -->|tested via| B
High-level overview of the relationship between your smart contracts project, Algorand Python Testing framework, Algorand Python type stubs, and the compiler
The Algorand Python Testing framework streamlines unit testing of your Algorand Python smart contracts by offering functionality to:
Simulate the Algorand Virtual Machine (AVM) environment
Create and manipulate test accounts, assets, applications, transactions, and ARC4 types
Test smart contract classes, including their states, variables, and methods
Verify logic signatures and subroutines
Manage global state, local state, scratch slots, and boxes in test contexts
Simulate transactions and transaction groups, including inner transactions
Verify opcode behavior
By using this framework, you can ensure your Algorand Python smart contracts function correctly before deploying them to a live network.
Key features of the framework include:
AlgopyTestContext
: The main entry point for testing, providing access to various testing utilities and simulated blockchain stateAVM Type Simulation: Accurate representations of AVM types like
UInt64
andBytes
ARC4 Support: Tools for testing ARC4 contracts and methods, including struct definitions and ABI encoding/decoding
Transaction Simulation: Ability to create and execute various transaction types
State Management: Tools for managing and verifying global and local state changes
Opcode Simulation: Implementations of AVM opcodes for accurate smart contract behavior testing
The framework is designed to work seamlessly with Algorand Python smart contracts, allowing developers to write comprehensive unit tests that closely mimic the behavior of contracts on the Algorand blockchain.