-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
139 lines (126 loc) · 4.36 KB
/
test.js
File metadata and controls
139 lines (126 loc) · 4.36 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
// Test script for Observer Protocol SDK
const { ObserverProtocol } = require('./index.js');
async function runTests() {
console.log('🧪 Observer Protocol SDK Test Suite\n');
const observer = new ObserverProtocol();
let testsPassed = 0;
let testsFailed = 0;
// Test 1: API Connectivity
console.log('Test 1: API Connectivity (getTrends)');
try {
const trends = await observer.getTrends();
console.log(' ✅ API is reachable');
console.log(` 📊 ${trends.total_events} events, ${trends.total_verified_agents} verified agents`);
testsPassed++;
} catch (e) {
console.log(' ❌ API unreachable:', e.message);
testsFailed++;
}
// Test 2: Register agent
console.log('\nTest 2: Agent Registration');
let agentId;
try {
const agent = await observer.registerAgent({
publicKey: '03' + Math.random().toString(36).substring(2, 34),
alias: 'TestAgent-' + Date.now(),
lightningNodePubkey: '03testnode'
});
agentId = agent.id;
console.log(' ✅ Agent registered:', agent.id.substring(0, 16) + '...');
console.log(' 🏷️ Badge URL:', agent.badge_url);
testsPassed++;
} catch (e) {
console.log(' ❌ Registration failed:', e.message);
testsFailed++;
}
// Test 3: Get reputation for new agent
console.log('\nTest 3: Get Reputation (new agent)');
if (agentId) {
try {
const rep = await observer.getReputation(agentId);
console.log(' ✅ Reputation fetched');
console.log(` 📈 Score: ${rep.score}, Transactions: ${rep.transaction_count}`);
testsPassed++;
} catch (e) {
console.log(' ❌ Reputation fetch failed:', e.message);
testsFailed++;
}
} else {
console.log(' ⚠️ Skipped (no agent ID)');
}
// Test 4: Get agent profile for maxi-0001
console.log('\nTest 4: Get Existing Agent Profile (maxi-0001)');
try {
const profile = await observer.getAgentProfile('maxi-0001');
console.log(' ✅ Profile fetched for maxi-0001');
console.log(` 👤 Name: ${profile.agent_name}, Verified: ${profile.verified}`);
console.log(` 📊 Tx count: ${profile.verified_tx_count}`);
testsPassed++;
} catch (e) {
console.log(' ❌ Profile fetch failed:', e.message);
testsFailed++;
}
// Test 5: Query transactions
console.log('\nTest 5: Query Transactions (feed)');
try {
const txs = await observer.queryTransactions({ limit: 3 });
console.log(' ✅ Transactions queried:', txs.length, 'results');
if (txs.length > 0) {
console.log(` 📋 First tx: ${txs[0].event_type} (${txs[0].protocol})`);
}
testsPassed++;
} catch (e) {
console.log(' ❌ Query failed:', e.message);
testsFailed++;
}
// Test 6: Verify agent (test signature)
console.log('\nTest 6: Verify Agent');
if (agentId) {
try {
const verified = await observer.verifyAgent(agentId, 'test-challenge', 'test-signature');
console.log(' ✅ Verification result:', verified.verified);
testsPassed++;
} catch (e) {
console.log(' ❌ Verification failed:', e.message);
testsFailed++;
}
}
// Test 7: Get badge URL
console.log('\nTest 7: Badge URL Generation');
try {
const badgeUrl = observer.getBadgeUrl('maxi-0001');
console.log(' ✅ Badge URL generated:', badgeUrl.substring(0, 60) + '...');
testsPassed++;
} catch (e) {
console.log(' ❌ Badge URL failed:', e.message);
testsFailed++;
}
// Test 8: Get reputation for maxi-0001
console.log('\nTest 8: Get Reputation (maxi-0001)');
try {
const rep = await observer.getReputation('maxi-0001');
console.log(' ✅ Reputation fetched for maxi-0001');
console.log(` 📈 Badge level: ${rep.badge_level}, Tx count: ${rep.transaction_count}`);
testsPassed++;
} catch (e) {
console.log(' ❌ Reputation fetch failed:', e.message);
testsFailed++;
}
// Summary
console.log('\n' + '='.repeat(50));
console.log(`📊 Test Results: ${testsPassed} passed, ${testsFailed} failed`);
console.log('='.repeat(50));
if (testsFailed === 0) {
console.log('✅ All SDK functions are working correctly!');
return true;
} else {
console.log('⚠️ Some tests failed - review errors above');
return false;
}
}
runTests().then(success => {
process.exit(success ? 0 : 1);
}).catch(err => {
console.error('Unexpected error:', err);
process.exit(1);
});