-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor polish; fixing links in algopy testing docs; simplifying auctio…
…n tests (#259)
- Loading branch information
1 parent
f19425d
commit 0b6a087
Showing
6 changed files
with
103 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
# Coverage | ||
|
||
See which stubs are implemented completely (pure functions), which are mockable (via context manager), and which are not. | ||
See which `algorand-python` stubs are implemented by the `algorand-python-testing` library. There are 3 general categories: | ||
|
||
| Name | Implementation Status | Mockable Representation | | ||
| ------------------------------------------- | --------------------- | ----------------------- | | ||
| Primitives (UInt64, BigUInt, Bytes, String) | Fully Implemented | Yes | | ||
| Asset | Partially Implemented | Yes | | ||
| Account | Partially Implemented | Yes | | ||
| Application | Partially Implemented | Yes | | ||
| urange | Fully Implemented | Yes | | ||
| subroutine | Fully Implemented | Yes | | ||
| op. (most operations) | Fully Implemented | Yes | | ||
| Txn, GTxn, ITxn | Fully Implemented | Yes | | ||
| Global | Fully Implemented | Yes | | ||
| Box | Fully Implemented | Yes | | ||
| Block | Fully Implemented | Yes | | ||
| logicsig | Fully Implemented | Yes | | ||
| log | Fully Implemented | Yes | | ||
| itxn. (inner transactions) | Fully Implemented | Yes | | ||
| gtxn. (group transactions) | Fully Implemented | Yes | | ||
| ensure_budget | Fully Implemented | Yes | | ||
| arc4. (most ARC4 features) | Fully Implemented | Yes | | ||
| uenumerate | Not Implemented | Yes | | ||
| op.ITxnCreate | Not Implemented | Yes | | ||
| op.EllipticCurve | Not Implemented | Yes | | ||
| op.AssetParamsGet | Not Implemented | Yes | | ||
| op.AppParamsGet | Not Implemented | Yes | | ||
| op.AppLocal | Not Implemented | Yes | | ||
| op.AppGlobal | Not Implemented | Yes | | ||
| op.AcctParamsGet | Not Implemented | Yes | | ||
| itxn.ApplicationCallInnerTransaction | Not Implemented | Yes | | ||
| arc4.UFixedNxM | Not Implemented | Yes | | ||
| arc4.BigUFixedNxM | Not Implemented | Yes | | ||
| arc4.ARC4Contract | Not Implemented | Yes | | ||
| StateTotals | Not Implemented | Yes | | ||
1. **Implemented**: Full native Python equivalent matching AVM computation. For example, `algopy.op.sha256` and other cryptographic operations behave identically in AVM and unit tests written with this library. | ||
|
||
2. **Emulated**: Implemented with the aid of the `AlgopyTestContext` manager, which mimics major AVM behavior to allow this abstraction to function as expected in a test context. For example, when you call `Box.put` on an `algopy.Box` object within a test context, it won't interact with the real Algorand network. Instead, it will store the data in the test context manager behind the scenes, while still providing the same interface as the real `Box` class. | ||
|
||
3. **Mockable**: No implementation provided, but can be easily mocked or patched to inject intended behavior. For example, `algopy.abi_call` can be mocked to return or act as needed; otherwise, it will raise a "not implemented" exception. Mockable types are exceptional cases where behavior or functionality does not make sense within a unit testing context or would require an unnecessary amount of complexity without significant benefit to the end user (a developer writing offline unit tests). | ||
|
||
> Note, below table not exhaustive yet, but will be expanded along with initial stable release. | ||
| Name | Implementation Status | | ||
| ------------------------------------------------------------ | --------------------- | | ||
| Primitives (UInt64, BigUInt, Bytes, String) | Implemented | | ||
| urange | Implemented | | ||
| All crypto ops in op.\* namespace (to be expanded in detail) | Implemented | | ||
| Txn, GTxn, ITxn | Implemented | | ||
| arc4.\* namespace (to be expanded in detail) | Implemented | | ||
| uenumerate | Implemented | | ||
| op.ITxnCreate | Implemented | | ||
| StateTotals | Implemented | | ||
| Asset | Emulated | | ||
| Account | Emulated | | ||
| Application | Emulated | | ||
| subroutine | Emulated | | ||
| Global | Emulated | | ||
| Box | Emulated | | ||
| Block | Emulated | | ||
| logicsig | Emulated | | ||
| log | Emulated | | ||
| itxn.\* namespace (inner transactions) | Emulated | | ||
| gtxn.\* namespace (group transactions) | Emulated | | ||
| ensure_budget | Mockable | | ||
| op.EllipticCurve | Mockable | | ||
| op.AssetParamsGet | Mockable | | ||
| op.AppParamsGet | Mockable | | ||
| op.AppLocal | Mockable | | ||
| op.AppGlobal | Mockable | | ||
| op.AcctParamsGet | Mockable | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# Examples | ||
# Example | ||
|
||
| Contract Name | Description | Link to contract.py | | ||
| ------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------ | | ||
| Auction | Implements a basic auction system | [auction/contract.py](algopy_testing/examples/auction/contract.py) | | ||
| Proof of Attendance | Manages proof of attendance for events | [proof_of_attendance/contract.py](algopy_testing/examples/proof_of_attendance/contract.py) | | ||
| Simple Voting | Implements a basic voting system | [simple_voting/contract.py](algopy_testing/examples/simple_voting/contract.py) | | ||
| ZK Whitelist | Implements a whitelist using zero-knowledge proofs | [zk_whitelist/contract.py](algopy_testing/examples/zk_whitelist/contract.py) | | ||
| HTLC LogicSig | Implements a Hashed Time-Locked Contract using LogicSig | [htlc_logicsig/signature.py](algopy_testing/examples/htlc_logicsig/signature.py) | | ||
Below is a showcase of various examples of unit testing real and sample Algorand Python smart contracts using `algorand-python-testing`. | ||
|
||
| Contract Name | Test File | Key Features Demonstrated | Test versions of Algopy Abstractions used | | ||
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | | ||
| Auction | [test_contract.py](https://github.com/algorandfoundation/puya/blob/main/algopy_testing/examples/auction/test_contract.py) | - Use of algopy_testing_context<br>- Mocking of global state and transaction fields<br>- Testing of ARC4 contract methods<br>- Emulation of asset creation and transfers<br>- Verification of inner transactions | - **ARC4Contract**<br>- **Global**<br>- **Txn**<br>- **Asset**<br>- **Account** | | ||
| Proof of Attendance | [test_contract.py](https://github.com/algorandfoundation/puya/blob/main/algopy_testing/examples/proof_of_attendance/test_contract.py) | - Creation and management of dummy assets<br>- Testing of box storage operations<br>- Verification of inner transactions for asset transfers<br>- Use of any\_\* methods for generating test data | - **Contract**<br>- **Box**<br>- **Asset**<br>- **Account**<br>- **op** (for various operations) | | ||
| Simple Voting | [test_contract.py](https://github.com/algorandfoundation/puya/blob/main/algopy_testing/examples/simple_voting/test_contract.py) | - Testing of global and local state operations<br>- Verification of transaction group operations<br>- Mocking of payment transactions | - **Contract**<br>- **GlobalState**<br>- **LocalState**<br>- **Txn**<br>- **GTxn** (group transactions) | | ||
| ZK Whitelist | [test_contract.py](https://github.com/algorandfoundation/puya/blob/main/algopy_testing/examples/zk_whitelist/test_contract.py) | - Testing of zero-knowledge proof verification<br>- Mocking of external application calls<br>- Use of ARC4 types and methods | - **ARC4Contract**<br>- **arc4 types** (Address, DynamicArray, StaticArray, etc.)<br>- Application logs | | ||
| HTLC LogicSig | [test_signature.py](https://github.com/algorandfoundation/puya/blob/main/algopy_testing/examples/htlc_logicsig/test_signature.py) | - Testing of LogicSig contracts<br>- Verification of time-based conditions<br>- Mocking of transaction parameters | - **LogicSig**<br>- **Txn**<br>- **Global** | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters