|
1 | | -# anchor-litesvm |
| 1 | +# anchor-bankrun |
2 | 2 |
|
3 | | -`anchor-litesvm` is a small extension to [LiteSVM](https://github.com/LiteSVM/litesvm) |
4 | | -that enables using both Anchor and LiteSVM with minimal code changes. It does this by exporting a `LitesvmProvider` class that can be used as a replacement for `AnchorProvider` during testing. |
| 3 | +`anchor-bankrun` is a small but powerful extension to [solana-bankrun](https://github.com/kevinheavey/solana-bankrun) |
| 4 | +that enables using both Anchor and Bankrun with only a one-line code change. It does this by exporting a `BankrunProvider` class that can be used as a drop-in replacement for `AnchorProvider` during testing. |
5 | 5 |
|
6 | | -## Async note |
| 6 | +## Anchor version note |
7 | 7 |
|
8 | | -`litesvm` is synchronous because it is entirely compute-bound. However, `anchor-litesvm` uses async because |
9 | | -it implements interfaces that require async. If you would like to avoid async tests, you can simply |
10 | | -use regular `litesvm` without `anchor-litesvm`. |
| 8 | +Recent versions of `anchor-bankrun` use the Anchor v0.30 IDL, which is not backwards compatible with older Anchor IDLs. |
| 9 | +If you have an older IDL, use `anchor-bankrun` v0.3.0. |
11 | 10 |
|
12 | 11 | ## Usage |
13 | 12 |
|
14 | | -Here's an example using `LitesvmProvider` to test an Anchor program: |
| 13 | +Here's an example using `BankrunProvider` to test an Anchor program: |
15 | 14 |
|
16 | 15 | ```typescript |
17 | | -import { fromWorkspace, LiteSVMProvider } from "anchor-litesvm"; |
| 16 | +import { BankrunProvider, startAnchor } from "anchor-bankrun"; |
18 | 17 | import { Keypair, PublicKey } from "@solana/web3.js"; |
19 | | -import { BN, Program, Wallet } from "@coral-xyz/anchor"; |
| 18 | +import { BN, Program } from "@coral-xyz/anchor"; |
20 | 19 | import { Puppet } from "./anchor-example/puppet"; |
21 | 20 | const IDL = require("./anchor-example/puppet.json"); |
22 | 21 |
|
23 | 22 | test("anchor", async () => { |
24 | | - const client = fromWorkspace("tests/anchor-example"); |
25 | | - const provider = new LiteSVMProvider(client); |
26 | | - const puppetProgram = new Program<Puppet>(IDL, provider); |
| 23 | + const context = await startAnchor("tests/anchor-example", [], []); |
| 24 | + |
| 25 | + const provider = new BankrunProvider(context); |
| 26 | + |
| 27 | + const puppetProgram = new Program<Puppet>( |
| 28 | + IDL, |
| 29 | + provider, |
| 30 | + ); |
| 31 | + |
27 | 32 | const puppetKeypair = Keypair.generate(); |
28 | 33 | await puppetProgram.methods |
29 | 34 | .initialize() |
@@ -51,5 +56,9 @@ test("anchor", async () => { |
51 | 56 | ## Installation |
52 | 57 |
|
53 | 58 | ``` |
54 | | -yarn add anchor-litesvm |
| 59 | +yarn add anchor-bankrun |
55 | 60 | ``` |
| 61 | + |
| 62 | +## Why is this a separate package? |
| 63 | + |
| 64 | +I want to keep the Bankrun dependencies light. |
0 commit comments