UNPKG

plugin-hedera-dex

Version:

Comprehensive Hedera DEX plugin for SaucerSwap integration with ElizaOS. Provides real-time pool data, token swapping, and complete DEX functionality on Hedera blockchain.

144 lines (143 loc) โ€ข 5.88 kB
#!/usr/bin/env bun /** * Manual test script to verify the list_pools action works with real Hedera testnet data * Run with: bun run src/manual-test.ts */ import { hederaDexPlugin } from './index'; // Mock runtime that provides mainnet configuration const mockRuntime = { getSetting: (key) => { switch (key) { case 'HEDERA_NETWORK': return 'mainnet'; case 'HEDERA_MIRROR_NODE_URL': return 'https://mainnet-public.mirrornode.hedera.com'; default: return undefined; } }, // Add other required runtime methods as no-ops getMemory: () => null, setMemory: () => { }, getState: () => ({}), setState: () => { }, composeState: () => ({}), updateRecentMessageState: () => ({}), messageManager: null, descriptionManager: null, loreManager: null, documentsManager: null, knowledgeManager: null, services: new Map(), providers: [], actions: [], evaluators: [], plugins: [], fetch: global.fetch, }; // Mock memory object const mockMessage = { id: 'test-message-id', userId: 'test-user', agentId: 'test-agent', roomId: 'test-room', content: { text: 'list all pools on saucerswap', source: 'manual-test', }, createdAt: Date.now(), }; async function testListPoolsAction() { console.log('๐Ÿงช Testing LIST_POOLS action with real Hedera mainnet data...\n'); try { // Get the list pools action const listPoolsAction = hederaDexPlugin.actions?.[0]; if (!listPoolsAction) { throw new Error('LIST_POOLS action not found'); } console.log(`โœ… Found action: ${listPoolsAction.name}`); console.log(`๐Ÿ“ Description: ${listPoolsAction.description}`); console.log(`๐ŸŽฏ Similes: ${listPoolsAction.similes?.join(', ')}\n`); // Test validation console.log('๐Ÿ” Testing validation...'); const isValid = await listPoolsAction.validate(mockRuntime, mockMessage, undefined); console.log(`โœ… Validation result: ${isValid}\n`); // Test the handler with callback console.log('๐Ÿš€ Executing action handler...'); console.log('๐Ÿ“ก Connecting to Hedera mainnet Mirror Node...'); console.log('๐Ÿญ Querying SaucerSwap V2 Factory contract: 0.0.3946833\n'); let callbackContent = null; const callback = async (content) => { callbackContent = content; console.log('๐Ÿ“ž Callback received with pool data'); return []; }; const startTime = Date.now(); const result = await listPoolsAction.handler(mockRuntime, mockMessage, undefined, undefined, callback); const endTime = Date.now(); console.log(`โฑ๏ธ Execution time: ${endTime - startTime}ms\n`); // Display results if (result && result.success) { console.log('๐ŸŽ‰ SUCCESS! Pool data retrieved successfully'); console.log(`๐Ÿ“Š Total pools found: ${result.data?.totalPools || 0}`); console.log(`๐ŸŒ Network: ${result.values?.network || 'unknown'}`); console.log(`๐Ÿ“ก Data source: ${result.data?.dataSource || 'unknown'}\n`); if (callbackContent) { console.log('๐Ÿ“‹ Formatted pool information:'); console.log('='.repeat(80)); console.log(callbackContent.text); console.log('='.repeat(80)); } if (result.data?.pools && result.data.pools.length > 0) { console.log('\n๐Ÿ” First pool details:'); const firstPool = result.data.pools[0]; console.log(` Pool ID: ${firstPool.id}`); console.log(` Contract: ${firstPool.contractId}`); console.log(` Token A: ${firstPool.tokenA.name} (${firstPool.tokenA.symbol})`); console.log(` Token B: ${firstPool.tokenB.name} (${firstPool.tokenB.symbol})`); console.log(` Fee: ${firstPool.fee / 10000}%`); console.log(` Liquidity: ${firstPool.liquidity}`); } } else { console.log('โŒ FAILED! Error occurred:'); const errorMsg = result?.error instanceof Error ? result.error.message : String(result?.error || 'Unknown error'); console.log(` Error: ${errorMsg}`); console.log(` Details: ${result?.text || 'No details available'}`); if (result?.data && 'error' in result.data) { console.log(` Additional info: ${result.data.error}`); } } } catch (error) { console.error('๐Ÿ’ฅ Test failed with exception:', error); process.exit(1); } } async function testProvider() { console.log('\n๐Ÿ”ง Testing Hedera DEX Provider...'); const provider = hederaDexPlugin.providers?.[0]; if (!provider) { console.log('โŒ Provider not found'); return; } console.log(`โœ… Found provider: ${provider.name}`); const providerResult = await provider.get(mockRuntime, mockMessage, {}); console.log('๐Ÿ“‹ Provider information:'); console.log(` Text: ${providerResult.text}`); console.log(` Network: ${providerResult.values?.network || 'unknown'}`); console.log(` Capabilities: ${providerResult.values?.capabilities?.join(', ') || 'none'}`); console.log(` Supported networks: ${providerResult.data?.supportedNetworks?.join(', ') || 'none'}`); } // Run the tests async function main() { console.log('๐ŸŒŠ Hedera DEX Plugin - Manual Test Suite'); console.log('='.repeat(50)); await testListPoolsAction(); await testProvider(); console.log('\nโœจ Manual test completed!'); } // Execute if run directly if (import.meta.main) { main().catch(console.error); }