Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The testing strategy for Aztec Standards is designed to ensure the reliability, privacy, and security of standardized smart contracts (AIP-20, AIP-721, and AIP-4626) within the Aztec Network. It employs a multi-layered approach combining unit and integration tests using Vitest, automated benchmarking for performance tracking, and specialized utilities to handle Aztec's unique private-public state interactions and cryptographic requirements.
Sources: README.md:1-45, package.json:11-20
Testing Infrastructure
The project uses vitest as its primary test runner and aztec-benchmark for performance metrics. The environment is configured to interact with an Aztec Sandbox, which provides a local development node for simulating the Aztec blockchain.
Environment Configuration
The testing environment is initialized globally before any tests run. This includes starting an Aztec Sandbox and configuring the module resolution for cryptographic libraries like @noble/hashes.
| Configuration | Value / Description |
|---|---|
| Test Runner | Vitest |
| Hook/Test Timeout | 200,000ms - 300,000ms (due to Sandbox simulation time) |
| Sandbox URL | http://localhost:8080 (Default) |
| Global Setup | vitest.setup.ts |
| Parallelism | Disabled (fileParallelism: false) to prevent Sandbox conflicts |
Sources: vitest.config.ts:14-25, vitest.setup.ts:1-17, src/ts/test/utils.ts:46-50
Sandbox Lifecycle
The lifecycle of the testing environment is managed through a global setup and teardown process.
Testing Methodologies
Functional Integration Testing
Tests are organized by contract type (Token, NFT, Vault, Escrow). Each suite follows a pattern of:
- Setup: Deploying the necessary contracts and minting initial supplies.
- Action: Executing contract methods (private or public).
- Assertion: Verifying balances in both private and public states, and validating emitted events.
Sources: src/ts/test/token.test.ts:34-45, src/ts/test/nft.test.ts:35-45
AuthWitness and Authorization
A critical component of the strategy involves testing AuthWitness (Authorization Witnesses). This allows one account to authorize another to perform actions on its behalf, which is essential for private interactions and contract-to-contract calls.
Security Testing: Inflation Attacks
The strategy includes specific scenarios to test protection against common DeFi vulnerabilities, such as inflation attacks in Tokenized Vaults. Tests verify that vaults deployed with a "dust" initial deposit correctly dilute potential manipulation attempts.
Sources: src/ts/test/tokenized_vault.test.ts:600-750
Core Testing Utilities
The utils.ts file provides standardized helpers to abstract the complexity of Aztec-specific operations.
Balance Verification
Verifying balances in Aztec requires simulating calls from specific accounts, as private state is only accessible to the owner.
expectTokenBalances: Checks both public and private balances for a given address.assertOwnsPrivateNFT: Verifies NFT ownership within private notes.
Sources: src/ts/test/utils.ts:89-114, src/ts/test/utils.ts:153-163
Log Decryption
Since private interactions do not emit public events, the testing strategy utilizes raw private log decryption to verify internal state changes, such as the initialization of transfer commitments.
Benchmarking Strategy
Benchmarks are implemented to track the gas costs and performance of contract methods. They extend a base Benchmark class and define specific setup and getMethods routines.
| Component | Benchmark Focus |
|---|---|
| TokenContract | Minting, Private/Public transfers, Burning, and Commitment initialization. |
| TokenizedVault | Deposit/Withdraw (all privacy combinations), Issuance, and Redemption. |
| Escrow | Partial vs. Full withdrawals, NFT withdrawals. |
| Logic | Key derivation (secret_keys_to_public_keys) and Escrow sharing. |
Sources: benchmarks/token_contract.benchmark.ts:60-110, benchmarks/tokenized_vault_contract.benchmark.ts:110-185, benchmarks/escrow_contract.benchmark.ts:84-110
Summary
The Aztec Standards testing strategy ensures that reusable contract primitives behave correctly across Aztec's dual state model. By leveraging complex utilities for log decryption, AuthWitness management, and sandbox orchestration, the project maintains high standards for privacy-preserving application development. Performance is further guarded by a dedicated benchmarking suite that measures the computational impact of standard operations.