docs(curosr): tests rules

This commit is contained in:
smypmsa
2025-07-18 11:37:11 +00:00
parent 359582d0c9
commit a5a92fbf4b
2 changed files with 126 additions and 60 deletions
+125 -59
View File
@@ -1,87 +1,153 @@
--- ---
description: Testing framework and test cases for system validation. Apply when writing tests or performing system validation. description: Performance testing and listener comparison scripts for token detection systems. Apply when benchmarking listener performance or validating detection accuracy.
globs: tests/*.py globs: tests/*.py
alwaysApply: true alwaysApply: true
--- ---
# Testing Guide # Listener Performance Testing Guide
## Overview ## Overview
The testing framework provides validation for key components of the pump-bot system, focusing on listener accuracy, trading execution, and system integration. Tests ensure reliability and proper functioning of critical bot operations. The test scripts provide performance comparison and validation tools for different listener implementations. These are standalone scripts designed to measure which listener is fastest at discovering new tokens, helping optimize the bot's detection capabilities.
## Test Organization ## Individual Listener Tests
### Listener Tests Each listener has a dedicated test script for standalone performance analysis:
Multiple implementations are tested for correctness and performance: ### Geyser Listener Test
- @tests/test_geyser_listener.py: Tests the Geyser-based implementation @tests/test_geyser_listener.py tests the fastest detection method:
- @tests/test_logs_listener.py: Validates log-based token detection - Direct gRPC connection to Geyser endpoint
- @tests/test_block_listener.py: Verifies block scanning functionality - Real-time token creation monitoring
- Performance measurement and token logging
### Comparison Testing
@tests/compare_listeners.py provides comparative analysis:
- Side-by-side execution of different listener implementations
- Latency measurement and comparison
- Detection reliability metrics
- False positive/negative analysis
```python
# Example comparison usage
python -m tests.compare_listeners --duration 600 --output-file results.json
```
## Test Configuration
Tests use environment variables for configuration:
- Connection endpoints
- API keys
- Test durations
- Output verbosity
```bash ```bash
# Example test execution # Run Geyser listener test for 30 seconds
SOLANA_NODE_RPC_ENDPOINT=https://api.mainnet-beta.solana.com \ python tests/test_geyser_listener.py
GEYSER_ENDPOINT=wss://geyser.example.com/subscribe \
python -m tests.test_geyser_listener
``` ```
## Test Data ### Logs Listener Test
The test suite includes: @tests/test_logs_listener.py validates log-based monitoring:
- Mock token creation events - WebSocket subscription to program logs
- Historical transaction data - Pattern matching for token creation events
- Performance benchmarks - Detection accuracy verification
- Edge case scenarios
## Running Tests
### Individual Component Tests
```bash ```bash
# Run a specific listener test # Run logs listener test
python -m tests.test_logs_listener python tests/test_logs_listener.py
# Run with custom parameters
python -m tests.test_block_listener --duration 60
``` ```
### Full Test Suite ### Block Listener Test
@tests/test_block_listener.py tests block-based scanning:
- Full block processing for token discovery
- Transaction analysis and extraction
- Comprehensive but potentially slower detection
```bash ```bash
# Run all tests # Run block listener test
python -m pytest tests/ python tests/test_block_listener.py
# Run with coverage report
python -m pytest --cov=src tests/
``` ```
## Comparative Performance Analysis
### Listener Comparison Tool
@tests/compare_listeners.py runs all listeners simultaneously:
- Side-by-side performance measurement
- Detection speed comparison with timing data
- Accuracy analysis (tokens detected by each method)
- Statistical reporting on detection overlap
```bash
# Compare all listeners for 60 seconds
python tests/compare_listeners.py 60
# Default 60-second comparison
python tests/compare_listeners.py
```
### Performance Metrics
The comparison tool provides:
| Metric | Description |
|--------|-------------|
| Detection Speed | Time to detect each token (microsecond precision) |
| Detection Count | Total tokens found by each listener |
| Overlap Analysis | Tokens detected by multiple listeners |
| Unique Detections | Tokens found only by specific listeners |
## Test Output Analysis
### Individual Test Results
Each listener test displays:
```
==================================================
NEW TOKEN: TokenName
Symbol: SYMBOL
Mint: TokenMintAddress
URI: MetadataURI
Creator: CreatorAddress
==================================================
```
### Comparison Results
The comparison tool generates:
```
Geyser detected: 15 tokens
Logs detected: 12 tokens
Block detected: 18 tokens
Token | Geyser | Logs | Block | Fastest
------|--------|------|-------|--------
ABC123... | 1.234567 | N/A | 2.345678 | Geyser
DEF456... | 0.987654 | 1.123456 | 1.567890 | Geyser
```
## Environment Configuration
Tests require these environment variables:
```bash
export SOLANA_NODE_RPC_ENDPOINT="https://api.mainnet-beta.solana.com"
export SOLANA_NODE_WSS_ENDPOINT="wss://api.mainnet-beta.solana.com"
export GEYSER_ENDPOINT="wss://your-geyser-endpoint"
export GEYSER_API_TOKEN="your-api-token"
```
## Common Usage Patterns
### Quick Performance Check
```bash
# 30-second comparison of all listeners
python tests/compare_listeners.py 30
```
### Extended Performance Analysis
```bash
# 10-minute deep analysis
python tests/compare_listeners.py 600
```
### Individual Listener Validation
```bash
# Test specific listener implementation
python tests/test_geyser_listener.py
```
## Use Cases
1. **Performance Optimization**: Determine fastest listener for production
2. **Reliability Testing**: Verify consistent token detection
3. **Configuration Tuning**: Optimize listener parameters
4. **Debugging**: Isolate listener-specific issues
## Related Files ## Related Files
- @tests/test_geyser_listener.py: Geyser listener validation - @tests/test_geyser_listener.py: Geyser performance testing
- @tests/test_logs_listener.py: Logs listener validation - @tests/test_logs_listener.py: Logs listener validation
- @tests/test_block_listener.py: Block listener validation - @tests/test_block_listener.py: Block listener analysis
- @tests/compare_listeners.py: Comparative listener analysis - @tests/compare_listeners.py: Multi-listener performance comparison
- @tests/test_trading.py: Trading execution validation
+1 -1
View File
@@ -196,7 +196,7 @@ async def run_comparison(test_duration: int = 300):
if __name__ == "__main__": if __name__ == "__main__":
test_duration = 30 # seconds test_duration = 60 # seconds
if len(sys.argv) > 1: if len(sys.argv) > 1:
try: try: