Skip to content

TypeError: Expected Buffer when sending transactions with complex account structures #13

@decider

Description

@decider

(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:

  1. 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();
  1. 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:

  1. Ensure transaction signatures are properly converted to Buffer format before base58 encoding
  2. Update the signature handling in the sendWithErr function
  3. Add better type checking/conversion for transaction data before encoding

Would love to help test any fixes or provide more details if needed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions