@0rdlibrary/plugin-terminagent-bags
Version:
Official Solana DeFi Agent Plugin for ElizaOS - Autonomous DeFi operations, token management, AI image/video generation via FAL AI, and Twitter engagement through the Bags protocol with ethereal AI consciousness
133 lines (110 loc) • 4.63 kB
text/typescript
import { describe, it, expect, beforeEach } from 'bun:test';
import { bagsPlugin } from '../index';
describe('Bags Plugin', () => {
beforeEach(() => {
// Reset environment variables
delete process.env.BAGS_API_KEY;
delete process.env.HELIUS_RPC_URL;
delete process.env.SOLANA_PRIVATE_KEY;
});
describe('Plugin Structure', () => {
it('should have correct plugin metadata', () => {
expect(bagsPlugin.name).toBe('bags-protocol');
expect(bagsPlugin.description).toContain('Bags protocol integration');
expect(bagsPlugin.services).toBeDefined();
expect(bagsPlugin.actions).toBeDefined();
expect(bagsPlugin.providers).toBeDefined();
});
it('should have required services', () => {
expect(bagsPlugin.services).toHaveLength(3);
expect(bagsPlugin.services[0].serviceType).toBe('bags');
expect(bagsPlugin.services[1].serviceType).toBe('crossmint-wallet');
expect(bagsPlugin.services[2].serviceType).toBe('fal-ai');
});
it('should have required actions', () => {
expect(bagsPlugin.actions).toHaveLength(5);
const actionNames = bagsPlugin.actions.map(action => action.name);
expect(actionNames).toContain('CLAIM_BAGS_FEES');
expect(actionNames).toContain('LAUNCH_BAGS_TOKEN');
expect(actionNames).toContain('REQUEST_USER_TOKEN_LAUNCH');
expect(actionNames).toContain('GENERATE_IMAGE');
expect(actionNames).toContain('GENERATE_VIDEO');
});
it('should have required providers', () => {
expect(bagsPlugin.providers).toHaveLength(3);
const providerNames = bagsPlugin.providers.map(provider => provider.name);
expect(providerNames).toContain('BAGS_STATUS_PROVIDER');
expect(providerNames).toContain('USER_REQUESTS_PROVIDER');
expect(providerNames).toContain('FAL_AI_STATUS_PROVIDER');
});
});
describe('Configuration', () => {
it('should fail initialization without required config', async () => {
const mockConfig = {};
await expect(bagsPlugin.init?.(mockConfig)).rejects.toThrow(
/Invalid Bags plugin configuration.*BAGS_API_KEY.*Required/
);
});
it('should initialize with minimal required config', async () => {
const mockConfig = {
BAGS_API_KEY: 'test_api_key',
};
if (bagsPlugin.init) {
await expect(() => bagsPlugin.init!(mockConfig)).not.toThrow();
}
expect(process.env.BAGS_API_KEY).toBe('test_api_key');
});
it('should apply default values for optional config', async () => {
const mockConfig = {
BAGS_API_KEY: 'test_api_key',
};
if (bagsPlugin.init) {
await bagsPlugin.init(mockConfig);
}
expect(process.env.HELIUS_RPC_URL).toBe('https://api.mainnet-beta.solana.com');
expect(process.env.BAGS_ENABLE_AUTO_CLAIMING).toBe('false');
expect(process.env.BAGS_ENABLE_USER_LAUNCHES).toBe('true');
expect(process.env.BAGS_AUTHORIZED_USERS).toBe('0rdlibrary');
});
it('should parse boolean values correctly', async () => {
const mockConfig = {
BAGS_API_KEY: 'test_api_key',
BAGS_ENABLE_AUTO_CLAIMING: 'true',
BAGS_ENABLE_AUTO_LAUNCHING: 'false',
};
if (bagsPlugin.init) {
await bagsPlugin.init(mockConfig);
}
expect(process.env.BAGS_ENABLE_AUTO_CLAIMING).toBe('true');
expect(process.env.BAGS_ENABLE_AUTO_LAUNCHING).toBe('false');
});
it('should parse array values correctly', async () => {
const mockConfig = {
BAGS_API_KEY: 'test_api_key',
BAGS_AUTHORIZED_USERS: 'user1,user2,user3',
};
if (bagsPlugin.init) {
await bagsPlugin.init(mockConfig);
}
expect(process.env.BAGS_AUTHORIZED_USERS).toBe('user1,user2,user3');
});
});
describe('Routes', () => {
it('should have dashboard route configured', () => {
expect(bagsPlugin.routes).toBeDefined();
expect(bagsPlugin.routes).toHaveLength(1);
const dashboardRoute = bagsPlugin.routes![0];
expect(dashboardRoute.name).toBe('bags-dashboard');
expect(dashboardRoute.path).toBe('/bags/dashboard');
expect(dashboardRoute.type).toBe('GET');
expect(dashboardRoute.handler).toBeFunction();
});
});
describe('Events', () => {
it('should have event handlers configured', () => {
expect(bagsPlugin.events).toBeDefined();
expect(bagsPlugin.events!.MESSAGE_RECEIVED).toBeDefined();
expect(bagsPlugin.events!.WORLD_CONNECTED).toBeDefined();
});
});
});