test_utils_anchor
Utilities and extensions for testing anchor programs in wasm compatible environments.
Installation
To install you can used the following command:
Or directly add the following to your Cargo.toml:
[]
= "0.2" # replace with the latest version
Features
| Feature | Description |
|---|---|
test_validator |
Enables the test_validator feature for the solana_test_validator crate. |
Compatibility
This crate is compatible with Anchor v0.32.1 and higher.
Usage
The primary utility in this crate is the anchor_processor! macro. It adapts an Anchor program's entrypoint to be compatible with the solana-program-test framework, which is essential for integration testing.
Setting up an Anchor ProgramTest
Here is a complete example of how to set up a test environment for an Anchor program, based on the tests in the example_client crate.
use Result;
use ExampleProgramClient; // Your generated client
use MemoryWallet;
use Account;
use sol_to_lamports;
use Pubkey;
use Keypair;
use anchor_processor;
use get_wallet_keypair;
use ProgramTest;
use TestRpcProvider;
use tokio;
// 1. Create a function to set up the test environment.
async
// 4. Use the setup function in your tests.
async