Skip to content

Commit

Permalink
Merge pull request #15 from kevinheavey/anchor-0.30
Browse files Browse the repository at this point in the history
Upgrade to Anchor 0.30
  • Loading branch information
kevinheavey authored Jun 29, 2024
2 parents e15ea4c + 7901a3f commit 50e8df4
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 146 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.4.0] - 2024-06-29

- BREAKING: Update to Anchor v0.30 [(#15)](https://github.com/kevinheavey/anchor-bankrun/pull/15)

## [0.3.0] - 2023-12-02

- Make `@solana/web3.js` a peer dependency [(#5)](https://github.com/kevinheavey/anchor-bankrun/pull/5)
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
`anchor-bankrun` is a small but powerful extension to [solana-bankrun](https://github.com/kevinheavey/solana-bankrun)
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.

## Anchor version note

Recent versions of `anchor-bankrun` use the Anchor v0.30 IDL, which is not backwards compatible with older Anchor IDLs.
If you have an older IDL, use `anchor-bankrun` v0.3.0.

## Usage

Here's an example using `BankrunProvider` to test an Anchor program:
Expand All @@ -12,20 +17,16 @@ import { startAnchor } from "solana-bankrun";
import { BankrunProvider } from "anchor-bankrun";
import { Keypair, PublicKey } from "@solana/web3.js";
import { BN, Program } from "@coral-xyz/anchor";
import { IDL as PuppetIDL, Puppet } from "./anchor-example/puppet";

const PUPPET_PROGRAM_ID = new PublicKey(
"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
);
import { Puppet } from "./anchor-example/puppet";
const IDL = require("./anchor-example/puppet.json");

test("anchor", async () => {
const context = await startAnchor("tests/anchor-example", [], []);

const provider = new BankrunProvider(context);

const puppetProgram = new Program<Puppet>(
PuppetIDL,
PUPPET_PROGRAM_ID,
IDL,
provider,
);

Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"name": "anchor-bankrun",
"version": "0.3.0",
"version": "0.4.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/"
],
"files": ["dist/"],
"license": "MIT",
"devDependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@coral-xyz/anchor": "^0.30.0",
"@solana/web3.js": "^1.78.4",
"@types/bn.js": "^5.1.1",
"@types/bs58": "^4.0.1",
Expand Down Expand Up @@ -36,7 +34,7 @@
},
"packageManager": "[email protected]",
"peerDependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@coral-xyz/anchor": "^0.30.0",
"@solana/web3.js": "^1.78.4",
"solana-bankrun": "^0.2.0"
}
Expand Down
68 changes: 68 additions & 0 deletions tests/anchor-example/puppet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"address": "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
"metadata": {
"name": "puppet",
"version": "0.1.0",
"spec": "0.1.0",
"description": "Created with Anchor"
},
"instructions": [
{
"name": "initialize",
"discriminator": [175, 175, 109, 31, 13, 152, 155, 237],
"accounts": [
{
"name": "puppet",
"writable": true,
"signer": true
},
{
"name": "user",
"writable": true,
"signer": true
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": []
},
{
"name": "set_data",
"discriminator": [223, 114, 91, 136, 197, 78, 153, 153],
"accounts": [
{
"name": "puppet",
"writable": true
}
],
"args": [
{
"name": "data",
"type": "u64"
}
]
}
],
"accounts": [
{
"name": "Data",
"discriminator": [206, 156, 59, 188, 18, 79, 240, 232]
}
],
"types": [
{
"name": "Data",
"type": {
"kind": "struct",
"fields": [
{
"name": "data",
"type": "u64"
}
]
}
}
]
}
95 changes: 27 additions & 68 deletions tests/anchor-example/puppet.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
/**
* Program IDL in camelCase format in order to be used in JS/TS.
*
* Note that this is only a type helper and is not the actual IDL. The original
* IDL can be found at `target/idl/puppet.json`.
*/
export type Puppet = {
version: "0.1.0";
name: "puppet";
address: "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS";
metadata: {
name: "puppet";
version: "0.1.0";
spec: "0.1.0";
description: "Created with Anchor";
};
instructions: [
{
name: "initialize";
discriminator: [175, 175, 109, 31, 13, 152, 155, 237];
accounts: [
{
name: "puppet";
isMut: true;
isSigner: true;
writable: true;
signer: true;
},
{
name: "user";
isMut: true;
isSigner: true;
writable: true;
signer: true;
},
{
name: "systemProgram";
isMut: false;
isSigner: false;
address: "11111111111111111111111111111111";
},
];
args: [];
},
{
name: "setData";
discriminator: [223, 114, 91, 136, 197, 78, 153, 153];
accounts: [
{
name: "puppet";
isMut: true;
isSigner: false;
writable: true;
},
];
args: [
Expand All @@ -41,6 +52,12 @@ export type Puppet = {
},
];
accounts: [
{
name: "data";
discriminator: [206, 156, 59, 188, 18, 79, 240, 232];
},
];
types: [
{
name: "data";
type: {
Expand All @@ -55,61 +72,3 @@ export type Puppet = {
},
];
};

export const IDL: Puppet = {
version: "0.1.0",
name: "puppet",
instructions: [
{
name: "initialize",
accounts: [
{
name: "puppet",
isMut: true,
isSigner: true,
},
{
name: "user",
isMut: true,
isSigner: true,
},
{
name: "systemProgram",
isMut: false,
isSigner: false,
},
],
args: [],
},
{
name: "setData",
accounts: [
{
name: "puppet",
isMut: true,
isSigner: false,
},
],
args: [
{
name: "data",
type: "u64",
},
],
},
],
accounts: [
{
name: "data",
type: {
kind: "struct",
fields: [
{
name: "data",
type: "u64",
},
],
},
},
],
};
51 changes: 51 additions & 0 deletions tests/anchor-example/puppet_master.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"address": "HmbTLCmaGvZhKnn1Zfa1JVnp7vkMV4DYVxPLWBVoN65L",
"metadata": {
"name": "puppet_master",
"version": "0.1.0",
"spec": "0.1.0",
"description": "Created with Anchor"
},
"instructions": [
{
"name": "pull_strings",
"discriminator": [13, 252, 243, 149, 120, 132, 189, 145],
"accounts": [
{
"name": "puppet",
"writable": true
},
{
"name": "puppet_program",
"address": "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
}
],
"args": [
{
"name": "data",
"type": "u64"
}
]
}
],
"accounts": [
{
"name": "Data",
"discriminator": [206, 156, 59, 188, 18, 79, 240, 232]
}
],
"types": [
{
"name": "Data",
"type": {
"kind": "struct",
"fields": [
{
"name": "data",
"type": "u64"
}
]
}
}
]
}
Loading

0 comments on commit 50e8df4

Please sign in to comment.