coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.68k stars 1.35k forks source link

Use PNPM and Bun instead of Yarn to install packages and run Anchor tests #3080

Closed AuroraLantean closed 2 months ago

AuroraLantean commented 4 months ago

Why does Anchor lock JS package manager and runtime to Yarn? PNPM saves more disk spaces in installing JS packages. Bun runs much faster and supports TypeScript natively.

I can use pnpm to reinstall everything after importing yarn.lock, and deleting node_modules

But in the Anchor.toml

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

When I changed yarn into bun, anchor test command failed.

     Error: Simulation failed. 
Message: Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction. 
Logs: 
[
  "Program qu3BpUtF7Qv6fHztxeAEbVXeJe... invoke [1]",
  "Program is not deployed",
  "Program qu3BpUtF7Qv6fHztxeAEbVXeJe... failed: invalid account data for instruction"
]. 
Catch the `SendTransactionError` and call `getLogs()` on it for full details.
      at Connection.sendEncodedTransaction (node_modules/.pnpm/@solana+web3.js@1.95.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/@solana/web3.js/src/connection.ts:6006:13)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Connection.sendRawTransaction (node_modules/.pnpm/@solana+web3.js@1.95.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/@solana/web3.js/src/connection.ts:5962:20)
      at sendAndConfirmRawTransaction (node_modules/.pnpm/@coral-xyz+anchor@0.30.1_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/@coral-xyz/anchor/src/provider.ts:377:21)
      at AnchorProvider.sendAndConfirm (node_modules/.pnpm/@coral-xyz+anchor@0.30.1_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/@coral-xyz/anchor/src/provider.ts:163:14)
      at MethodsBuilder.rpc [as _rpcFn] (node_modules/.pnpm/@coral-xyz+anchor@0.30.1_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:29:16)

Please advise. Thanks

acheroncrypto commented 4 months ago

When I changed yarn into bun, anchor test command failed.

Why did it fail? Anchor just runs the command you specify, so if it doesn't work, it's related more to the testing tool you use rather than Anchor.

AuroraLantean commented 2 months ago

After updating my tools, I got it working!

rustc 1.80.1 (3f5fd8dd4 2024-08-06), solana-cli 1.18.18 (src:83047136; feat:4215500110, client:SolanaLabs), pnpm 9.9.0, yarn 1.22.22 ... installed via pnpm install -g yarn bun 1.1.26 anchor 0.29.0

To run a test: test = "bun run ts-mocha -p ./tsconfig.json -t 1000000 tests/my-test1.ts"