|
1 | | -# anchor-bankrun |
| 1 | +# anchor-litesvm |
2 | 2 |
|
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. |
| 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. |
5 | 5 |
|
6 | | -## Anchor version note |
| 6 | +## Async note |
7 | 7 |
|
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. |
| 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`. |
10 | 11 |
|
11 | 12 | ## Usage |
12 | 13 |
|
13 | | -Here's an example using `BankrunProvider` to test an Anchor program: |
| 14 | +Here's an example using `LitesvmProvider` to test an Anchor program: |
14 | 15 |
|
15 | 16 | ```typescript |
16 | | -import { BankrunProvider, startAnchor } from "anchor-bankrun"; |
| 17 | +import { fromWorkspace, LiteSVMProvider } from "anchor-litesvm"; |
17 | 18 | import { Keypair, PublicKey } from "@solana/web3.js"; |
18 | | -import { BN, Program } from "@coral-xyz/anchor"; |
| 19 | +import { BN, Program, Wallet } from "@coral-xyz/anchor"; |
19 | 20 | import { Puppet } from "./anchor-example/puppet"; |
20 | 21 | const IDL = require("./anchor-example/puppet.json"); |
21 | 22 |
|
22 | 23 | test("anchor", async () => { |
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 | | - |
| 24 | + const client = fromWorkspace("tests/anchor-example"); |
| 25 | + const provider = new LiteSVMProvider(client); |
| 26 | + const puppetProgram = new Program<Puppet>(IDL, provider); |
32 | 27 | const puppetKeypair = Keypair.generate(); |
33 | 28 | await puppetProgram.methods |
34 | 29 | .initialize() |
@@ -56,9 +51,5 @@ test("anchor", async () => { |
56 | 51 | ## Installation |
57 | 52 |
|
58 | 53 | ``` |
59 | | -yarn add anchor-bankrun |
| 54 | +yarn add anchor-litesvm |
60 | 55 | ``` |
61 | | - |
62 | | -## Why is this a separate package? |
63 | | - |
64 | | -I want to keep the Bankrun dependencies light. |
0 commit comments