-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-e2e.ts
More file actions
154 lines (126 loc) · 4.7 KB
/
test-e2e.ts
File metadata and controls
154 lines (126 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bun
/**
* Standalone E2E test for @elizaos/plugin-blockrun
*
* Run with: bun run test-e2e.ts
* Requires: BASE_CHAIN_WALLET_KEY environment variable
*/
import { LLMClient } from '@blockrun/llm';
import { privateKeyToAccount } from 'viem/accounts';
import { createPublicClient, http, formatUnits } from 'viem';
import { base } from 'viem/chains';
const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
async function testWalletProvider() {
console.log('\n=== Testing Wallet Provider ===\n');
const privateKey = process.env.BASE_CHAIN_WALLET_KEY;
if (!privateKey) {
console.log('❌ BASE_CHAIN_WALLET_KEY not set');
return false;
}
try {
const account = privateKeyToAccount(privateKey as `0x${string}`);
console.log('✅ Wallet address:', account.address);
const publicClient = createPublicClient({
chain: base,
transport: http(),
});
// Get USDC balance
const usdcBalance = await publicClient.readContract({
address: USDC_BASE as `0x${string}`,
abi: [{
constant: true,
inputs: [{ name: '_owner', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: 'balance', type: 'uint256' }],
type: 'function',
}],
functionName: 'balanceOf',
args: [account.address],
});
console.log('✅ USDC balance:', formatUnits(usdcBalance, 6), 'USDC');
// Get ETH balance
const ethBalance = await publicClient.getBalance({ address: account.address });
console.log('✅ ETH balance:', formatUnits(ethBalance, 18), 'ETH');
return true;
} catch (error) {
console.log('❌ Wallet error:', error);
return false;
}
}
async function testBlockrunChat() {
console.log('\n=== Testing BlockRun Chat (x402) ===\n');
const privateKey = process.env.BASE_CHAIN_WALLET_KEY;
if (!privateKey) {
console.log('❌ BASE_CHAIN_WALLET_KEY not set');
return false;
}
try {
const client = new LLMClient({ privateKey: privateKey as `0x${string}` });
console.log('✅ LLMClient initialized');
console.log(' Wallet:', client.getWalletAddress());
// Test 1: Simple chat
console.log('\n📤 Test 1: Simple question...');
const start1 = Date.now();
const response1 = await client.chat('openai/gpt-4o-mini', 'What is 2+2? Reply with just the number.');
console.log('📥 Response:', response1);
console.log('⏱️ Latency:', Date.now() - start1, 'ms');
// Test 2: Another model
console.log('\n📤 Test 2: Different question...');
const start2 = Date.now();
const response2 = await client.chat('openai/gpt-4o-mini', 'Say hello in Japanese. Just the greeting.');
console.log('📥 Response:', response2);
console.log('⏱️ Latency:', Date.now() - start2, 'ms');
// Test 3: With system prompt
console.log('\n📤 Test 3: With system prompt...');
const start3 = Date.now();
const response3 = await client.chat('openai/gpt-4o-mini', 'What do you do?', {
system: 'You are a pirate. Speak like one.',
maxTokens: 50,
});
console.log('📥 Response:', response3);
console.log('⏱️ Latency:', Date.now() - start3, 'ms');
console.log('\n✅ All BlockRun chat tests passed!');
return true;
} catch (error) {
console.log('❌ BlockRun error:', error);
return false;
}
}
async function testListModels() {
console.log('\n=== Testing List Models ===\n');
const privateKey = process.env.BASE_CHAIN_WALLET_KEY;
if (!privateKey) {
console.log('❌ BASE_CHAIN_WALLET_KEY not set');
return false;
}
try {
const client = new LLMClient({ privateKey: privateKey as `0x${string}` });
const models = await client.listModels();
console.log('✅ Available models:', models.length);
models.slice(0, 5).forEach(m => {
console.log(` - ${m.id}: $${m.inputPrice}/1M input, $${m.outputPrice}/1M output`);
});
return true;
} catch (error) {
console.log('❌ List models error:', error);
return false;
}
}
async function main() {
console.log('🚀 BlockRun Plugin E2E Test');
console.log('============================');
const results = {
wallet: await testWalletProvider(),
models: await testListModels(),
chat: await testBlockrunChat(),
};
console.log('\n============================');
console.log('📊 Test Results:');
console.log(' Wallet Provider:', results.wallet ? '✅ PASS' : '❌ FAIL');
console.log(' List Models:', results.models ? '✅ PASS' : '❌ FAIL');
console.log(' BlockRun Chat:', results.chat ? '✅ PASS' : '❌ FAIL');
const allPassed = Object.values(results).every(r => r);
console.log('\n' + (allPassed ? '🎉 All tests passed!' : '⚠️ Some tests failed'));
process.exit(allPassed ? 0 : 1);
}
main();