Skip to content

Instantly share code, notes, and snippets.

@ochaloup
Created September 9, 2024 10:37
Show Gist options
  • Save ochaloup/e22cb14037faaabb3f9590103584c496 to your computer and use it in GitHub Desktop.
Save ochaloup/e22cb14037faaabb3f9590103584c496 to your computer and use it in GitHub Desktop.
solana-bankrun code update

To update solana-bankrun

Points on how to work with solana-bankrun, to update the code and then test it in a project on local computer.

Update solana-bankrun

As of the PR kevinheavey/solana-bankrun#31 the change consists of update of src/lib.rs to update linking to solana program test: https://github.com/anza-xyz/agave/blob/v2.0.9/program-test/src/lib.rs#L1016

From changes in src/lib.rs the linking to TypeScript is needed to be coded into index.ts.

Then building goes with

cargo build
yarn install
yarn run lint && yarn run fmt
yarn run build
yarn run artifacts
yarn run tsc
# not sure why is needed manual `cp` call but `yanr run <smt>` did not work 
cp solana-bankrun/solana-bankrun.linux-x64-gnu.node dist/

OUTPUT: dist/ directory with TS and *-gnu.node

Update anchor-bankrun

As the linked project works with anchor-bankrun I needed to update the dependencies for it as well. Otherwise I was getting error

[] Building project '$HOME/marinade-ts-cli/tsconfig.json'...

packages/lib/bankrun-utils/src/extendedProvider.ts:83:3 - error TS2322: Type 'import("$HOME/marinade-ts-cli/node_modules/.pnpm/solana-bankrun@0.2.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/solana-bankrun/dist/index").BanksTransactionMeta' is not assignable to type 'import("$HOME/marinade-ts-cli/node_modules/.pnpm/dist@file+..+solana-bankrun+dist/node_modules/dist/index").BanksTransactionMeta'.
  Types have separate declarations of a private property 'inner'.

83   return await provider.context.banksClient.processTransaction(tx)
     ~~~~~~

packages/lib/bankrun-utils/src/testInit.ts:254:38 - error TS2345: Argument of type 'import("$HOME/marinade-ts-cli/node_modules/.pnpm/dist@file+..+solana-bankrun+dist/node_modules/dist/index").ProgramTestContext' is not assignable to parameter of type 'import("$HOME/marinade-ts-cli/node_modules/.pnpm/solana-bankrun@0.2.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/solana-bankrun/dist/index").ProgramTestContext'.
  Types have separate declarations of a private property 'inner'.

254   return new BankrunExtendedProvider(context)
                                         ~~~~~~~


Found 2 errors.

 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

So, changing the anchor-bankrun dependency path in package.json to file:/<HOME>/solana-bankrun/dist at https://github.com/kevinheavey/anchor-bankrun/blob/v0.4.0/package.json#L18

rm -rf node_modules
yarn install
yarn run tsc

OUTPUT: dist/ dir with TS data

Updating related project

I work with https://github.com/marinade-finance/marinade-ts-cli/tree/main/packages/lib/bankrun-utils where both paths to solana-bankrun and anchor-bankrun have to be changed (at all places)

https://github.com/marinade-finance/marinade-ts-cli/blob/libs_2.4.8/packages/lib/bankrun-utils/package.json#L30-L38

"solana-bankrun": "file:/<HOME>/solana-bankrun/dist",
"anchor-bankrun": "file:/<HOME>/anchor-bankrun/dist",

and then update and build

# just to be double-sure to remove old dependencies
rm -rf node_modules/
pnpm install
pnpm build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment