diff --git a/CHANGELOG.md b/CHANGELOG.md index c3ea018..0aeb1e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index f4c0001..2cf7024 100644 --- a/README.md +++ b/README.md @@ -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: @@ -12,11 +17,8 @@ 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", [], []); @@ -24,8 +26,7 @@ test("anchor", async () => { const provider = new BankrunProvider(context); const puppetProgram = new Program( - PuppetIDL, - PUPPET_PROGRAM_ID, + IDL, provider, ); diff --git a/package.json b/package.json index 7705a2a..32a8f2f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -36,7 +34,7 @@ }, "packageManager": "yarn@1.22.19", "peerDependencies": { - "@coral-xyz/anchor": "^0.28.0", + "@coral-xyz/anchor": "^0.30.0", "@solana/web3.js": "^1.78.4", "solana-bankrun": "^0.2.0" } diff --git a/tests/anchor-example/puppet.json b/tests/anchor-example/puppet.json new file mode 100644 index 0000000..3f2d116 --- /dev/null +++ b/tests/anchor-example/puppet.json @@ -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" + } + ] + } + } + ] +} diff --git a/tests/anchor-example/puppet.ts b/tests/anchor-example/puppet.ts index e140dc1..c9b4cac 100644 --- a/tests/anchor-example/puppet.ts +++ b/tests/anchor-example/puppet.ts @@ -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: [ @@ -41,6 +52,12 @@ export type Puppet = { }, ]; accounts: [ + { + name: "data"; + discriminator: [206, 156, 59, 188, 18, 79, 240, 232]; + }, + ]; + types: [ { name: "data"; type: { @@ -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", - }, - ], - }, - }, - ], -}; diff --git a/tests/anchor-example/puppet_master.json b/tests/anchor-example/puppet_master.json new file mode 100644 index 0000000..148b7a6 --- /dev/null +++ b/tests/anchor-example/puppet_master.json @@ -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" + } + ] + } + } + ] +} diff --git a/tests/anchor-example/puppet_master.ts b/tests/anchor-example/puppet_master.ts index 5f702a2..0de19ce 100644 --- a/tests/anchor-example/puppet_master.ts +++ b/tests/anchor-example/puppet_master.ts @@ -1,19 +1,29 @@ +/** + * 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_master.json`. + */ export type PuppetMaster = { - version: "0.1.0"; - name: "puppet_master"; + address: "HmbTLCmaGvZhKnn1Zfa1JVnp7vkMV4DYVxPLWBVoN65L"; + metadata: { + name: "puppetMaster"; + version: "0.1.0"; + spec: "0.1.0"; + description: "Created with Anchor"; + }; instructions: [ { name: "pullStrings"; + discriminator: [13, 252, 243, 149, 120, 132, 189, 145]; accounts: [ { name: "puppet"; - isMut: true; - isSigner: false; + writable: true; }, { name: "puppetProgram"; - isMut: false; - isSigner: false; + address: "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"; }, ]; args: [ @@ -24,32 +34,24 @@ export type PuppetMaster = { ]; }, ]; -}; - -export const IDL: PuppetMaster = { - version: "0.1.0", - name: "puppet_master", - instructions: [ + accounts: [ { - name: "pullStrings", - accounts: [ - { - name: "puppet", - isMut: true, - isSigner: false, - }, - { - name: "puppetProgram", - isMut: false, - isSigner: false, - }, - ], - args: [ - { - name: "data", - type: "u64", - }, - ], + name: "data"; + discriminator: [206, 156, 59, 188, 18, 79, 240, 232]; }, - ], + ]; + types: [ + { + name: "data"; + type: { + kind: "struct"; + fields: [ + { + name: "data"; + type: "u64"; + }, + ]; + }; + }, + ]; }; diff --git a/tests/main.test.ts b/tests/main.test.ts index 7b18231..29d2153 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -2,23 +2,16 @@ import { startAnchor } from "solana-bankrun"; import { BankrunProvider } from "anchor-bankrun"; import { Keypair, PublicKey, SendTransactionError } from "@solana/web3.js"; import { BN, Program } from "@coral-xyz/anchor"; -import { IDL as PuppetIDL, Puppet } from "./anchor-example/puppet"; +import { Puppet } from "./anchor-example/puppet"; import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet"; - -const PUPPET_PROGRAM_ID = new PublicKey( - "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS", -); +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( - PuppetIDL, - PUPPET_PROGRAM_ID, - provider, - ); + const puppetProgram = new Program(IDL, provider); const puppetKeypair = Keypair.generate(); await puppetProgram.methods @@ -48,11 +41,7 @@ test("error test", async () => { const provider = new BankrunProvider(context); - const puppetProgram = new Program( - PuppetIDL, - PUPPET_PROGRAM_ID, - provider, - ); + const puppetProgram = new Program(IDL, provider); const puppetKeypair = Keypair.generate(); await puppetProgram.methods diff --git a/yarn.lock b/yarn.lock index c9f27f1..7eb4f9b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -304,14 +304,20 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@coral-xyz/anchor@^0.28.0": - version "0.28.0" - resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.28.0.tgz#8345c3c9186a91f095f704d7b90cd256f7e8b2dc" - integrity sha512-kQ02Hv2ZqxtWP30WN1d4xxT4QqlOXYDxmEd3k/bbneqhV3X5QMO4LAtoUFs7otxyivOgoqam5Il5qx81FuI4vw== - dependencies: - "@coral-xyz/borsh" "^0.28.0" +"@coral-xyz/anchor-errors@^0.30.1": + version "0.30.1" + resolved "https://registry.yarnpkg.com/@coral-xyz/anchor-errors/-/anchor-errors-0.30.1.tgz#bdfd3a353131345244546876eb4afc0e125bec30" + integrity sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ== + +"@coral-xyz/anchor@^0.30.0": + version "0.30.1" + resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.30.1.tgz#17f3e9134c28cd0ea83574c6bab4e410bcecec5d" + integrity sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ== + dependencies: + "@coral-xyz/anchor-errors" "^0.30.1" + "@coral-xyz/borsh" "^0.30.1" + "@noble/hashes" "^1.3.1" "@solana/web3.js" "^1.68.0" - base64-js "^1.5.1" bn.js "^5.1.2" bs58 "^4.0.1" buffer-layout "^1.2.2" @@ -319,16 +325,15 @@ cross-fetch "^3.1.5" crypto-hash "^1.3.0" eventemitter3 "^4.0.7" - js-sha256 "^0.9.0" pako "^2.0.3" snake-case "^3.0.4" superstruct "^0.15.4" toml "^3.0.0" -"@coral-xyz/borsh@^0.28.0": - version "0.28.0" - resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.28.0.tgz#fa368a2f2475bbf6f828f4657f40a52102e02b6d" - integrity sha512-/u1VTzw7XooK7rqeD7JLUSwOyRSesPUk0U37BV9zK0axJc1q0nRbKFGFLYCQ16OtdOJTTwGfGp11Lx9B45bRCQ== +"@coral-xyz/borsh@^0.30.1": + version "0.30.1" + resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.30.1.tgz#869d8833abe65685c72e9199b8688477a4f6b0e3" + integrity sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ== dependencies: bn.js "^5.1.2" buffer-layout "^1.2.0" @@ -980,7 +985,7 @@ base-x@^3.0.2, base-x@^3.0.6: dependencies: safe-buffer "^5.0.1" -base64-js@^1.3.1, base64-js@^1.5.1: +base64-js@^1.3.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== @@ -2006,11 +2011,6 @@ jest@^29.6.1: import-local "^3.0.2" jest-cli "^29.6.2" -js-sha256@^0.9.0: - version "0.9.0" - resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966" - integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA== - js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"