-
Notifications
You must be signed in to change notification settings - Fork 9
Description
(Made by Claude Code, reviewed by @decider)
Title: TypeError: Expected Buffer when sending transactions with complex account structures
Repository: LiteSVM/anchor-litesvm
Issue Description:
When using anchor-litesvm v0.1.2 to test Solana programs, certain transactions fail with TypeError: Expected Buffer during the base58 encoding phase. This occurs specifically with transactions that involve complex account structures or multiple signers.
Environment:
- anchor-litesvm: 0.1.2
- @coral-xyz/anchor: 0.31.1
- @solana/web3.js: 1.98.2
Error Stack Trace:
TypeError: Expected Buffer
at Object.encode (node_modules/anchor-litesvm/node_modules/base-x/src/index.js:27:44)
at sendWithErr (node_modules/anchor-litesvm/src/index.ts:74:26)
at LiteSVMProvider.sendAndConfirm (node_modules/anchor-litesvm/src/index.ts:150:3)
at MethodsBuilder.rpc [as _rpcFn] (client/node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:29:31)
at MethodsBuilder.rpc (client/node_modules/@coral-xyz/anchor/src/program/namespace/methods.ts:434:17)
Reproduction Steps:
- Create a test that initializes extra account meta list and adds a region:
import { LiteSVMProvider, fromWorkspace } from "anchor-litesvm";
import * as anchor from "@coral-xyz/anchor";
const client = fromWorkspace(".");
const provider = new LiteSVMProvider(client, new anchor.Wallet(adminWallet));
// This transaction fails with "Expected Buffer" error
await program.methods
.addRegion({ name: "Test Region", symbol: "TEST", uri: "https://test.com" })
.accounts({
admin: adminWallet.publicKey,
tokenVault: accounts.tokenVault,
platformState: accounts.platformState,
regionState: accounts.regionState,
usdcYieldPool: accounts.usdcYieldPool,
feeTokenPool: accounts.feeTokenPool,
mint: accounts.regionalMint.publicKey,
usdcMint: accounts.usdcMint,
tokenProgram: TOKEN_PROGRAM_ID,
token2022Program: TOKEN_2022_PROGRAM_ID,
associatedTokenProgram: anchor.utils.token.ASSOCIATED_PROGRAM_ID,
systemProgram: SystemProgram.programId,
rent: SYSVAR_RENT_PUBKEY,
})
.signers([accounts.regionalMint, adminWallet])
.rpc();- Similar error occurs with pool registry transactions:
await program.methods
.registerPool(poolAddress, dexProgram, poolType)
.accounts({
admin: adminWallet.publicKey,
poolRegistry,
regionMint,
platformState: context.pdas.platformState,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();Expected Behavior:
Transactions should be properly encoded and sent to the LiteSVM instance without encoding errors.
Actual Behavior:
The transaction fails during base58 encoding with "TypeError: Expected Buffer" before reaching the LiteSVM instance.
Analysis:
The error occurs in the sendWithErr function at line 74 of anchor-litesvm's index.ts, specifically during the base58 encoding of the transaction signature. This suggests that the signature might not be in the expected format (Buffer) when it reaches the encoding step.
Workaround:
Currently, we have to skip tests that trigger this error. Simple transactions (like basic initialization) work fine, but more complex transactions with multiple accounts or signers fail.
Impact:
This issue prevents testing of complex Solana program interactions with anchor-litesvm, limiting its usefulness for comprehensive test suites. We can only test simple transactions while more complex scenarios fail.
Additional Context:
- The same transactions work correctly with standard Anchor testing using solana-test-validator
- The issue appears to be specific to how anchor-litesvm handles transaction encoding
- Tests for simpler operations (platform initialization, balance checks) work perfectly
Possible Solutions:
- Ensure transaction signatures are properly converted to Buffer format before base58 encoding
- Update the signature handling in the
sendWithErrfunction - Add better type checking/conversion for transaction data before encoding
Would love to help test any fixes or provide more details if needed!