Skip to content

Commit

Permalink
Merge pull request #2345 from ai16z-demirix/feature/solana-plugin-tests
Browse files Browse the repository at this point in the history
feat: adding tests for plugin-solana
  • Loading branch information
shakkernerd authored Jan 16, 2025
2 parents 446dd00 + 8132709 commit 3b334cb
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/plugin-solana/__tests__/actions/swap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, it, expect, vi } from 'vitest';

describe('Swap Action', () => {
describe('validate', () => {
it('should handle swap message validation', async () => {
const mockMessage = {
content: 'Swap 1 SOL to USDC',
metadata: {
fromToken: 'SOL',
toToken: 'USDC',
amount: '1'
}
};

// Basic test to ensure message structure
expect(mockMessage.metadata).toBeDefined();
expect(mockMessage.metadata.fromToken).toBe('SOL');
expect(mockMessage.metadata.toToken).toBe('USDC');
expect(mockMessage.metadata.amount).toBe('1');
});
});
});
55 changes: 55 additions & 0 deletions packages/plugin-solana/__tests__/evaluators/trust.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { describe, it, expect, vi } from 'vitest';
import { trustEvaluator } from '../../src/evaluators/trust';

// Mock the core module
vi.mock('@elizaos/core', () => ({
generateTrueOrFalse: vi.fn().mockResolvedValue(false),
ModelClass: {
SMALL: 'small'
},
settings: {
MAIN_WALLET_ADDRESS: 'test-wallet-address'
},
booleanFooter: 'Answer with Yes or No.',
elizaLogger: {
log: vi.fn(),
debug: vi.fn(),
info: vi.fn(),
error: vi.fn()
},
composeContext: vi.fn().mockReturnValue({
state: {},
template: ''
})
}));

describe('Trust Evaluator', () => {
it('should handle non-trust messages', async () => {
const mockRuntime = {
getSetting: vi.fn(),
composeState: vi.fn().mockResolvedValue({
agentId: 'test-agent',
roomId: 'test-room'
}),
getLogger: vi.fn().mockReturnValue({
debug: vi.fn(),
info: vi.fn(),
log: vi.fn(),
error: vi.fn()
})
};

const mockMessage = {
content: 'Hello world',
metadata: {}
};

const mockState = {
agentId: 'test-agent',
roomId: 'test-room'
};

const result = await trustEvaluator.handler(mockRuntime, mockMessage, mockState);
expect(result).toBeDefined();
});
});
36 changes: 36 additions & 0 deletions packages/plugin-solana/__tests__/providers/token-security.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, it, expect, vi } from 'vitest';
import { TokenProvider } from '../../src/providers/token';
import { WalletProvider } from '../../src/providers/wallet';
import { ICacheManager } from '@elizaos/core';

describe('Token Security', () => {
it('should handle empty security data gracefully', async () => {
const mockCacheManager = {
get: vi.fn().mockResolvedValue(null),
set: vi.fn(),
delete: vi.fn(),
clear: vi.fn(),
has: vi.fn(),
};

const mockWalletProvider = new WalletProvider(mockCacheManager);
const tokenProvider = new TokenProvider(
'So11111111111111111111111111111111111111112',
mockWalletProvider,
mockCacheManager
);

global.fetch = vi.fn().mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({
success: true,
data: {}
})
});

const result = await tokenProvider.fetchTokenSecurity();
expect(result).toBeDefined();
expect(result.ownerBalance).toBe(undefined);
expect(result.creatorBalance).toBe(undefined);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
import { TokenProvider } from "../providers/token.ts";
import { TokenProvider } from "../src/providers/token.ts";

// Mock NodeCache
vi.mock("node-cache", () => {
Expand Down

0 comments on commit 3b334cb

Please sign in to comment.