-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-script.js
More file actions
182 lines (152 loc) Β· 5.66 KB
/
test-script.js
File metadata and controls
182 lines (152 loc) Β· 5.66 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Test script for both The Graph and Substreams
const { getIntent } = require('./intent.js');
const GraphService = require('./services/graphService.js');
const SubstreamsService = require('./services/substreamsService.js');
// Test questions organized by service
const testQuestions = {
// The Graph (Subgraphs) tests
subgraphs: [
"Show ethereum network stats",
"Show analytics for USDC",
"Show my transaction history",
"Token stats for ETH",
"Show pool analytics for 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640"
],
// Substreams tests
substreams: [
"Show my recent transactions",
"Real-time USDC analytics",
"Live network statistics",
"Show me live token activity",
"Real-time blockchain metrics"
],
// Error handling tests
errors: [
"Show transactions for 0xinvalid",
"Analytics for fake token",
"Network stats for fake network"
]
};
async function testService(serviceName, questions) {
console.log(`\nπ§ͺ Testing ${serviceName.toUpperCase()}...`);
console.log('=' * 50);
for (let i = 0; i < questions.length; i++) {
const question = questions[i];
console.log(`\n${i + 1}. Testing: "${question}"`);
try {
// Test intent recognition
const intentResponse = await getIntent(question);
const intent = JSON.parse(intentResponse);
console.log(` β
Intent: ${intent.intent}`);
// Test service based on intent
if (serviceName === 'subgraphs') {
await testGraphService(intent);
} else if (serviceName === 'substreams') {
await testSubstreamsService(intent);
} else if (serviceName === 'errors') {
console.log(` β οΈ Expected error handling for: ${intent.intent}`);
}
} catch (error) {
console.log(` β Error: ${error.message}`);
}
}
}
async function testGraphService(intent) {
const graphService = new GraphService();
try {
switch (intent.intent) {
case 'network-stats':
console.log(` π Testing network statistics...`);
// Mock test - would call graphService.getNetworkStatistics()
console.log(` β
Network stats test passed`);
break;
case 'token-analytics':
console.log(` πͺ Testing token analytics...`);
// Mock test - would call graphService.getTokenAnalytics()
console.log(` β
Token analytics test passed`);
break;
case 'transaction-history':
console.log(` π Testing transaction history...`);
// Mock test - would call graphService.getUserTransactionHistory()
console.log(` β
Transaction history test passed`);
break;
default:
console.log(` β οΈ Unhandled intent: ${intent.intent}`);
}
} catch (error) {
console.log(` β Graph service error: ${error.message}`);
}
}
async function testSubstreamsService(intent) {
const substreamsService = new SubstreamsService();
try {
switch (intent.intent) {
case 'realtime-transactions':
console.log(` β‘ Testing real-time transactions...`);
// Mock test - would call substreamsService.getRealtimeTransactions()
console.log(` β
Real-time transactions test passed`);
break;
case 'token-analytics':
console.log(` π₯ Testing real-time token analytics...`);
// Mock test - would call substreamsService.getRealtimeTokenAnalytics()
console.log(` β
Real-time token analytics test passed`);
break;
case 'network-stats':
console.log(` π‘ Testing real-time network stats...`);
// Mock test - would call substreamsService.getRealtimeNetworkStats()
console.log(` β
Real-time network stats test passed`);
break;
default:
console.log(` β οΈ Unhandled intent: ${intent.intent}`);
}
} catch (error) {
console.log(` β Substreams service error: ${error.message}`);
}
}
async function runAllTests() {
console.log('π Starting Comprehensive Test Suite');
console.log('Testing both The Graph (Subgraphs) and Substreams services');
console.log('=' * 60);
try {
// Test The Graph (Subgraphs)
await testService('subgraphs', testQuestions.subgraphs);
// Test Substreams
await testService('substreams', testQuestions.substreams);
// Test Error Handling
await testService('errors', testQuestions.errors);
console.log('\nβ
All tests completed!');
console.log('\nπ Test Summary:');
console.log(`- The Graph (Subgraphs): ${testQuestions.subgraphs.length} tests`);
console.log(`- Substreams: ${testQuestions.substreams.length} tests`);
console.log(`- Error Handling: ${testQuestions.errors.length} tests`);
console.log(`- Total: ${testQuestions.subgraphs.length + testQuestions.substreams.length + testQuestions.errors.length} tests`);
} catch (error) {
console.error('β Test suite failed:', error);
}
}
// Quick test function for specific service
async function quickTest(service) {
console.log(`\nβ‘ Quick Test for ${service.toUpperCase()}`);
if (service === 'subgraphs') {
await testService('subgraphs', testQuestions.subgraphs.slice(0, 2));
} else if (service === 'substreams') {
await testService('substreams', testQuestions.substreams.slice(0, 2));
} else {
console.log('Available services: subgraphs, substreams');
}
}
// Run tests if this file is executed directly
if (require.main === module) {
const args = process.argv.slice(2);
if (args.length > 0) {
quickTest(args[0]);
} else {
runAllTests();
}
}
module.exports = {
testQuestions,
testService,
runAllTests,
quickTest
};