@n1xyz/nord-ts 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test.ts DELETED
@@ -1,107 +0,0 @@
1
- import { Nord } from './src/nord/client/Nord';
2
- import { MetricPeriod } from './src/nord/api/metrics';
3
- import { PeakTpsPeriodUnit } from './src/types';
4
-
5
- // Configuration for Nord client
6
- const NORD_CONFIG = {
7
- webServerUrl: 'https://zo-devnet.n1.xyz',
8
- solanaProgramId: 'nord1111111111111111111111111111111111111',
9
- solanaUrl: 'https://api.devnet.solana.com',
10
- initWebSockets: false // We don't need WebSockets for these tests
11
- };
12
-
13
- // Function to run all tests
14
- async function runTests() {
15
- console.log('Testing Nord API with URL:', NORD_CONFIG.webServerUrl);
16
- console.log('----------------------------------------');
17
-
18
- try {
19
- // Initialize Nord client
20
- console.log('\nInitializing Nord client...');
21
- const nord = await Nord.initNord(NORD_CONFIG);
22
- console.log('Nord client initialized successfully');
23
-
24
- // Test aggregateMetrics
25
- console.log('\n1. Testing aggregateMetrics:');
26
- const metrics = await nord.aggregateMetrics();
27
- console.log('Aggregate Metrics:', JSON.stringify(metrics, null, 2));
28
-
29
- // Test with custom parameters
30
- console.log('\nTesting aggregateMetrics with custom parameters:');
31
- const customMetrics = await nord.aggregateMetrics(
32
- 3,
33
- PeakTpsPeriodUnit.Hour
34
- );
35
- console.log('Custom Aggregate Metrics:', JSON.stringify(customMetrics, null, 2));
36
-
37
- // Test getCurrentTps
38
- console.log('\n2. Testing getCurrentTps:');
39
- const tps1m = await nord.getCurrentTps(MetricPeriod.ONE_MINUTE);
40
- console.log(`Current TPS (1m): ${tps1m}`);
41
-
42
- const tps5m = await nord.getCurrentTps(MetricPeriod.FIVE_MINUTES);
43
- console.log(`Current TPS (5m): ${tps5m}`);
44
-
45
- // Test getPeakTps
46
- console.log('\n3. Testing getPeakTps:');
47
- const peakTps24h = await nord.getPeakTps(MetricPeriod.ONE_DAY);
48
- console.log(`Peak TPS (24h): ${peakTps24h}`);
49
-
50
- const peakTps1w = await nord.getPeakTps(MetricPeriod.ONE_WEEK);
51
- console.log(`Peak TPS (1w): ${peakTps1w}`);
52
-
53
- // Test getMedianLatency
54
- console.log('\n4. Testing getMedianLatency:');
55
- const medianLatency1m = await nord.getMedianLatency(MetricPeriod.ONE_MINUTE);
56
- console.log(`Median Latency (1m): ${medianLatency1m} ms`);
57
-
58
- const medianLatency1h = await nord.getMedianLatency(MetricPeriod.ONE_HOUR);
59
- console.log(`Median Latency (1h): ${medianLatency1h} ms`);
60
-
61
- // Test getTotalTransactions
62
- console.log('\n5. Testing getTotalTransactions:');
63
- const totalTx = await nord.getTotalTransactions();
64
- console.log(`Total Transactions: ${totalTx}`);
65
-
66
- // Test queryPrometheus with a custom query
67
- console.log('\n6. Testing queryPrometheus with custom query:');
68
- const customQuery = 'sum(rate(nord_requests_ok_count[15m]))';
69
- const customQueryResult = await nord.queryPrometheus(customQuery);
70
- console.log(`Custom Query Result (${customQuery}): ${customQueryResult}`);
71
-
72
- // Test getLastActionId
73
- console.log('\n7. Testing getLastActionId:');
74
- const lastActionId = await nord.getLastActionId();
75
- console.log(`Last Action ID: ${lastActionId}`);
76
-
77
- // Test queryRecentActions
78
- console.log('\n8. Testing queryRecentActions:');
79
- // Get 10 recent actions starting from 0
80
- const recentActions = await nord.queryRecentActions(0, 10);
81
- console.log(`Recent Actions (from 0 to 10):`);
82
- console.log(JSON.stringify(recentActions, null, 2));
83
-
84
- // Test queryActionsRange
85
- console.log('\n9. Testing queryActionsRange:');
86
- // If lastActionId is available, use it to get a range of actions
87
- if (lastActionId > 10) {
88
- const fromId = Math.max(0, lastActionId - 10);
89
- const toId = lastActionId;
90
- const actionsRange = await nord.queryRecentActions(fromId, toId);
91
- console.log(`Actions Range (from ${fromId} to ${toId}):`);
92
- console.log(JSON.stringify(actionsRange, null, 2));
93
- } else {
94
- console.log('Not enough actions to demonstrate range query');
95
- }
96
-
97
- } catch (error) {
98
- console.error('Error running tests:', error);
99
- }
100
- }
101
-
102
- // Run all tests
103
- runTests().then(() => {
104
- console.log('\nAll tests completed!');
105
- }).catch(error => {
106
- console.error('Fatal error:', error);
107
- });