|
1 | 1 | import { describe, it, expect, beforeAll, afterAll } from 'vitest'; |
2 | 2 | import { PolkadotAgentKit } from '../../src/api'; |
3 | 3 | import { RECIPIENT, AGENT_PRIVATE_KEY, sleep } from './utils'; |
4 | | -import { parseUnits} from '@polkadot-agent-kit/common'; |
5 | | -import { ChatOllama } from "@langchain/ollama"; |
| 4 | +import { OllamaAgent } from './ollamaAgent'; |
6 | 5 |
|
7 | | - |
8 | | - |
9 | | -let agent: PolkadotAgentKit; |
| 6 | +let agentKit: PolkadotAgentKit; |
| 7 | +let ollamaAgent: OllamaAgent; |
10 | 8 |
|
11 | 9 | beforeAll(async () => { |
12 | | - agent = new PolkadotAgentKit(AGENT_PRIVATE_KEY, { keyType: 'Sr25519' }); |
13 | | - await agent.initializeApi(); |
14 | | - // make sure the API is ready |
15 | | - await sleep(5000); |
| 10 | + agentKit = new PolkadotAgentKit(AGENT_PRIVATE_KEY, { keyType: 'Sr25519' }); |
| 11 | + await agentKit.initializeApi(); |
| 12 | + ollamaAgent = new OllamaAgent(agentKit); |
| 13 | + await ollamaAgent.init(); |
16 | 14 | }); |
17 | 15 |
|
18 | 16 | afterAll(async () => { |
19 | | - await agent.disconnect(); |
| 17 | + await agentKit.disconnect(); |
20 | 18 | }); |
21 | 19 |
|
22 | | - |
23 | 20 | /// Note: |
24 | 21 | /// We are using Ollama for testing purposes, but you can use any other model you want |
25 | 22 | /// We are using Westend and Westend Asset Hub for integrations tests |
26 | | -describe('PolkadotAgentKit Integration', () => { |
27 | | - it('should get native balance on Westend', async () => { |
28 | | - const tool = agent.getNativeBalanceTool(); |
29 | | - const result = await tool.call({ chain: 'west' }); |
30 | | - // make sure the transaction is confirmed |
31 | | - await sleep(10000); |
32 | | - const { success, data } = JSON.parse(result.content); |
33 | | - expect(success).toBe(true); |
34 | | - expect(data).toBeDefined(); |
| 23 | +describe('PolkadotAgentKit Integration with OllamaAgent', () => { |
| 24 | + it('should get native balance on Westend using Ollama agent', async () => { |
| 25 | + const result = await ollamaAgent.ask('check balance on Westend'); |
| 26 | + console.log('OllamaAgent Balance Query Result:', result); |
| 27 | + await sleep(20000); |
| 28 | + expect(result.output).toBeDefined(); |
35 | 29 | }); |
36 | | - |
37 | | - it('should transfer 0.001 WND to recipient on Westend', async () => { |
38 | | - const tool = agent.transferNativeTool(); |
39 | | - const result = await tool.call({ |
40 | | - to: RECIPIENT, |
41 | | - amount: '0.01', |
42 | | - chain: 'west', |
43 | | - }); |
44 | | - // make sure the transaction is confirmed |
45 | | - await sleep(15000); |
46 | | - const { success, data } = JSON.parse(result.content); |
47 | | - expect(success).toBe(true); |
48 | | - expect(data).toBeDefined(); |
49 | | - |
50 | | - |
| 30 | + it('should transfer 0.001 WND to recipient on Westend using natural language', async () => { |
| 31 | + const userQuery = `transfer 0.001 WND to ${RECIPIENT} on Westend`; |
| 32 | + |
| 33 | + const result = await ollamaAgent.ask(userQuery); |
| 34 | + console.log('Transfer Query Result:', result); |
| 35 | + await sleep(20000); |
| 36 | + expect(result.output).toBeDefined(); |
51 | 37 | }); |
52 | | - |
53 | | - it('should xcm transfer 0.001 WND from Westend to Westend Asset Hub', async () => { |
54 | | - const tool = agent.xcmTransferNativeTool(); |
55 | | - const result = await tool.call({ |
56 | | - to: RECIPIENT, |
57 | | - amount: '0.01', |
58 | | - sourceChain: 'west', |
59 | | - destChain: 'west_asset_hub', |
60 | | - }); |
61 | | - // make sure the transaction is confirmed |
62 | | - await sleep(15000); |
63 | | - const { success, data } = JSON.parse(result.content); |
64 | | - expect(success).toBe(true); |
65 | | - expect(data).toBeDefined(); |
| 38 | + it('should xcm transfer 0.001 WND from Westend to Westend Asset Hub using natural language', async () => { |
| 39 | + const userQuery = `transfer 0.001 WND to ${RECIPIENT} from Westend to Westend Asset Hub`; |
| 40 | + const result = await ollamaAgent.ask(userQuery); |
| 41 | + console.log('XCM Transfer Query Result (Westend → Asset Hub):', result); |
| 42 | + await sleep(20000); |
| 43 | + expect(result.output).toBeDefined(); |
66 | 44 | }); |
67 | | - |
68 | | - it('should xcm transfer 0.001 WND from Westend Asset Hub to Westend', async () => { |
69 | | - const tool = agent.xcmTransferNativeTool(); |
70 | | - const result = await tool.call({ |
71 | | - to: RECIPIENT, |
72 | | - amount: '0.01', |
73 | | - sourceChain: 'west_asset_hub', |
74 | | - destChain: 'west', |
75 | | - }); |
76 | | - // make sure the transaction is confirmed |
77 | | - await sleep(10000); |
78 | | - const { success, data } = JSON.parse(result.content); |
79 | | - expect(success).toBe(true); |
80 | | - expect(data).toBeDefined(); |
| 45 | + it('should xcm transfer 0.001 WND from Westend Asset Hub to Westend using natural language', async () => { |
| 46 | + const userQuery = `transfer 0.001 WND to ${RECIPIENT} from Westend Asset Hub to Westend`; |
| 47 | + const result = await ollamaAgent.ask(userQuery); |
| 48 | + console.log('XCM Transfer Query Result (Asset Hub → Westend):', result); |
| 49 | + await sleep(20000); |
| 50 | + expect(result.output).toBeDefined(); |
81 | 51 | }); |
| 52 | + |
82 | 53 | }); |
0 commit comments