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 wallet providers
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/
If Jest is not yet set up, install it:
cd /workspaces/3D-Agent/solana-agent-sdk
npm install --save-dev jest ts-jest @types/jest
jest.config.ts (create if missing):
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;
package.json scripts: "test": "node --experimental-vm-modules node_modules/.bin/jest"
The wallet provider source files are in src/wallet/:
keypair.ts—KeypairWalletProviderbrowser-server.ts—BrowserWalletProviderbrowser-client.ts—BrowserWalletClient
What to Test
Create tests/wallet/ directory.
tests/wallet/keypair.test.ts
Test KeypairWalletProvider.
Generate a test keypair using Keypair.generate() from @solana/web3.js.
Tests:
- Base58 string constructor:
new KeypairWalletProvider(bs58EncodedKey)sets correctpublicKey - Uint8Array constructor:
new KeypairWalletProvider(keypair.secretKey)sets correctpublicKey - Array constructor:
new KeypairWalletProvider(Array.from(keypair.secretKey))sets correctpublicKey - signTransaction (legacy): signs a
Transaction, result has a signature for the keypair's public key - signTransaction (versioned): signs a
VersionedTransaction, resultsignaturesarray is non-empty - signAndSendTransaction: mocks
sendAndConfirmTransactionto return"fakeSig", verifies it's called with the keypair
For test 6, mock the module:
jest.mock("@solana/web3.js", () => ({
...jest.requireActual("@solana/web3.js"),
sendAndConfirmTransaction: jest.fn().mockResolvedValue("fakeSig"),
}));
tests/wallet/browser-server.test.ts
Test BrowserWalletProvider.
Tests:
- Constructor defaults:
sessionIdis a UUID string,publicKeyis set from options - String publicKey: constructor accepts base58 string, converts to
PublicKey - setNextMeta: calling
setNextMeta(meta)thensignTransactionattachesmetato the pending tx - signTransaction creates pending entry: after calling
signTransaction,getPending()has one entry - signTransaction pending has correct fields:
id,transaction(base64),versioned,createdAt,meta - submitSigned resolves the promise: calling
submitSigned(id, signedBase64)resolves the pendingsignTransactionpromise - submitRejected rejects the promise: calling
submitRejected(id)rejects with an error containing "rejected" - timeout: if neither
submitSignednorsubmitRejectedis called withintimeoutMs, the promise rejects with "timed out" - meta consumed once: after one
signTransactioncall,nextMetais cleared; a second call hasmeta: undefined
For test 8, use a short timeoutMs (e.g. 50ms) and jest.useFakeTimers().
For test 6, build a valid signed transaction:
const tx = new Transaction();
tx.recentBlockhash = "11111111111111111111111111111111";
tx.feePayer = Keypair.generate().publicKey;
const signed = Buffer.from(tx.serialize({ requireAllSignatures: false })).toString("base64");
tests/wallet/browser-client.test.ts
Test BrowserWalletClient. This file runs in Node.js but BrowserWalletClient uses EventSource and browser globals (fetch, atob, btoa). Mock them.
Setup:
global.fetch = jest.fn();
global.EventSource = jest.fn().mockImplementation((url: string) => ({
onmessage: null,
onerror: null,
close: jest.fn(),
})) as any;
Tests:
- connect() opens EventSource: after
client.connect(),EventSourceconstructor was called withbaseUrl + "/stream" - disconnect() closes EventSource: after connect then disconnect,
close()is called - onmessage triggers signing: simulate a message event with a pending tx; verify
signeris called - auto-sign without onApproval: signer is called immediately when a message arrives (no approval step)
- onApproval blocks signing: when
onApprovalis provided, signer is NOT called untilapprove()is invoked - onApproval reject path: calling
reject()in handler callsfetchto the/reject/:idendpoint, signer is NOT called - onConfirmed fires: when the sign POST returns
{ ok: true, signature: "abc" },onConfirmedis called with the pending tx and"abc" - reconnect on error: simulate
onerror, verify a newEventSourceis created afterreconnectMs
Use jest.useFakeTimers() for test 8.
Verification
npm run buildpassesnpm testpasses — all tests green- No test uses real network connections
tests/wallet/contains three test files