-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-signal-api.js
More file actions
185 lines (162 loc) Β· 6.54 KB
/
test-signal-api.js
File metadata and controls
185 lines (162 loc) Β· 6.54 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
183
184
185
const { getSafeAddressForSpot, sendSignalToSafeAPI } = require('./src/services/signalGeneration');
/**
* Creates a dummy but valid personalizedSignalData object for testing
* @returns {Object} - Dummy personalized signal data
*/
function createDummyPersonalizedSignalData() {
return {
token: "Uniswap (UNI)",
signal: "buy",
currentPrice: 8.10,
targets: [9.10, 10.50],
stopLoss: 7.80,
timeline: "1-2 weeks",
maxExitTime: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000).toISOString(), // 2 weeks from now
tradeTip: "UNI showing strong DeFi momentum with potential for 15-20% gains. Key resistance at $9.20, support at $7.80. Consider DCA strategy.",
tweet_id: "dummy_tweet_123",
tweet_link: "https://twitter.com/dummy/status/123456789",
tweet_timestamp: new Date().toISOString(),
priceAtTweet: 8.25,
exitValue: null,
twitterHandle: "CryptoReviewing",
tokenMentioned: "UNI",
tokenId: "uniswap",
lunarCrushMetrics: {
r_last6h_pct: 3.8,
d_pct_mktvol_6h: 12.5,
d_pct_socvol_6h: 18.2,
d_pct_sent_6h: 6.4,
d_pct_users_6h: 9.8,
d_pct_infl_6h: 15.3,
d_galaxy_6h: 2.8,
neg_d_altrank_6h: -3.2
},
lunarCrushPrediction: 5.2,
lunarCrushTokenType: "defi",
userWeightages: {
r_last6h_pct: 85,
d_pct_mktvol_6h: 70,
d_pct_socvol_6h: 60,
d_pct_sent_6h: 75,
d_pct_users_6h: 65,
d_pct_infl_6h: 80,
d_galaxy_6h: 55,
neg_d_altrank_6h: 70
},
personalizedFor: "p_9899"
};
}
/**
* Test function to test getSafeAddressForSpot and sendSignalToSafeAPI
*/
async function testSignalAPI() {
console.log('π§ͺ Starting Signal API Test...\n');
// Create dummy data
const personalizedSignalData = createDummyPersonalizedSignalData();
console.log('π Created dummy personalized signal data:');
console.log(JSON.stringify(personalizedSignalData, null, 2));
console.log('\n' + '='.repeat(80) + '\n');
// Test username - replace with a real username from your database
const testUsername = "p_9899"; // Change this to a real username in your database
try {
console.log(`π Testing getSafeAddressForSpot for username: ${testUsername}`);
const spotResult = await getSafeAddressForSpot(testUsername);
if (spotResult && spotResult.safeAddress) {
console.log('β
Successfully retrieved spot safe address:');
console.log(` Safe Address: ${spotResult.safeAddress}`);
console.log(` Twitter ID: ${spotResult.twitterId}`);
console.log(` Network: ${spotResult.networkKey || 'Unknown'}`);
console.log('\n' + '='.repeat(80) + '\n');
console.log(`π€ Testing sendSignalToSafeAPI for username: ${testUsername}`);
const apiResult = await sendSignalToSafeAPI(
personalizedSignalData,
testUsername,
spotResult.safeAddress,
spotResult.twitterId
);
if (apiResult.success) {
console.log('β
Successfully sent signal to Safe API:');
console.log(JSON.stringify(apiResult.response, null, 2));
} else {
console.log('β Failed to send signal to Safe API:');
console.log(JSON.stringify(apiResult.error, null, 2));
}
} else {
console.log('β No spot safe address found for user:', testUsername);
console.log(' This could mean:');
console.log(' - User does not exist in the database');
console.log(' - User has no safeConfigs configured');
console.log(' - User has no spot type safe configs');
console.log(' - User has no safeAddress in their spot configs');
}
} catch (error) {
console.error('β Error during testing:', error);
}
console.log('\n' + '='.repeat(80) + '\n');
console.log('π Test completed!');
}
/**
* Test function with multiple usernames to find a valid one
*/
async function testWithMultipleUsernames() {
console.log('π Testing with multiple potential usernames...\n');
// Common test usernames - replace with actual usernames from your database
const testUsernames = [
"p_9899",
];
const personalizedSignalData = createDummyPersonalizedSignalData();
for (const username of testUsernames) {
console.log(`\nπ§ͺ Testing username: ${username}`);
console.log('-'.repeat(50));
try {
const spotResult = await getSafeAddressForSpot(username);
if (spotResult && spotResult.safeAddress) {
console.log(`β
Found safe address for ${username}: ${spotResult.safeAddress}`);
// Test sending signal
const apiResult = await sendSignalToSafeAPI(
personalizedSignalData,
username,
spotResult.safeAddress,
spotResult.twitterId
);
console.log(`π€ API Result for ${username}:`, apiResult.success ? 'SUCCESS' : 'FAILED');
if (!apiResult.success) {
console.log(` Error: ${JSON.stringify(apiResult.error)}`);
}
// If we found a working user, we can stop here
if (apiResult.success) {
console.log(`\nπ Successfully tested with user: ${username}`);
break;
}
} else {
console.log(`β No safe address found for ${username}`);
}
} catch (error) {
console.error(`β Error testing ${username}:`, error.message);
}
}
}
// Run the test
if (require.main === module) {
console.log('π Starting Signal API Test Suite...\n');
// Test with single username
testSignalAPI()
.then(() => {
console.log('\n' + '='.repeat(80) + '\n');
console.log('π Running multi-username test...\n');
return testWithMultipleUsernames();
})
.then(() => {
console.log('\nπ All tests completed!');
process.exit(0);
})
.catch((error) => {
console.error('π₯ Test suite failed:', error);
process.exit(1);
});
}
module.exports = {
createDummyPersonalizedSignalData,
testSignalAPI,
testWithMultipleUsernames
};