Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
Tests: Unit tests for action functions
Context
/workspaces/3D-Agent/solana-agent-sdk is a TypeScript Solana agent SDK (@three-ws/solana-agent).
Package location: /workspaces/3D-Agent/solana-agent-sdk/
The existing agent-payments-sdk package uses Jest (jest.config.ts, ts-jest). This package has no tests yet. Use the same stack.
Install test dependencies:
cd /workspaces/3D-Agent/solana-agent-sdk
npm install --save-dev jest ts-jest @types/jest
Add to package.json scripts:
"test": "node --experimental-vm-modules node_modules/.bin/jest"
Create jest.config.ts:
import type { Config } from "jest";
const config: Config = {
preset: "ts-jest/presets/default-esm",
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.ts$": ["ts-jest", { useESM: true }],
},
};
export default config;
What to Test
Create tests/actions/ directory with these test files. All tests must be fully self-contained — mock RPC calls, do not hit mainnet/devnet.
tests/actions/transfer-sol.test.ts
Test transferSol from src/actions/transfer-sol.ts.
Mock buildAndSend to capture what it receives. The tests should verify:
- Correct lamport conversion:
amount: 0.5→lamports = 500_000_000 - Correct instruction:
SystemProgram.transferinstruction is built with correctfromPubkey,toPubkey,lamports - Metadata is generated:
opts.meta.labelcontains the amount and "SOL" - Metadata kind:
opts.meta.kind === "transfer" - String address accepted: passing
toas a base58 string works the same asPublicKey - Custom meta override: if
opts.metais provided, it's used instead of auto-generated
Use a mock WalletProvider with a fixed public key.
tests/actions/transfer-spl.test.ts
Test transferSpl from src/actions/transfer-spl.ts.
Mock connection.getAccountInfo, connection.getMint (via getMint from spl-token), and buildAndSend.
Tests:
- Receiver ATA creation: when
getAccountInfo(receiverAta)returns null, acreateAssociatedTokenAccountInstructionis added - No receiver ATA creation: when receiver ATA exists, no creation instruction
- Sender ATA check: when
getAccountInfo(senderAta)returns null, throws an error containing "no token account" - TransferChecked instruction: correct
senderAta,mint,receiverAta,authority,amount,decimals - BigInt metadata:
uiAmountis correct string — noNumber(bigint)precision loss
tests/actions/swap.test.ts
Test jupiterSwap and getSwapQuote from src/actions/swap.ts.
Mock global.fetch to return controlled Jupiter API responses.
Tests:
- Quote fetch: correct URL is constructed with
inputMint,outputMint,amount,slippageBps - Default slippage: when not provided, defaults to 50 bps
- Swap request: correct POST body
{ quoteResponse, userPublicKey, dynamicComputeUnitLimit: true, prioritizationFeeLamports: "auto" } - Quote error: when quote API returns non-200, throws
Error(orSwapErrorif custom errors task is done) - Swap error: when swap API returns non-200, throws
Error - Metadata on MetaAwareWallet: when wallet implements
setNextMeta, it's called with a swap metadata object includingkind: "swap",amountIn,amountOut - Non-MetaAware wallet: when wallet doesn't implement
setNextMeta, no error is thrown
tests/actions/ata.test.ts
Test getOrCreateAta from src/actions/ata.ts.
Tests:
- ATA already exists: returns
{ ata, signature: undefined }whengetAccountInforeturns data - ATA doesn't exist: builds
createAssociatedTokenAccountInstruction, callsbuildAndSend, returns{ ata, signature: "fakeSig" } - Default owner: when
ownernot provided, useswallet.publicKey - Custom owner: when
owneris provided, uses that address
Verification
npm run buildpasses with zero errorsnpm testpasses with all tests green- No test hits an external network (all RPC calls are mocked)
- Test files are in
tests/directory, notsrc/