UNPKG

@bcoders.gr/eth-provider

Version:

High-Performance IPC Ethereum Provider with Advanced Optimizations - Refactored for Better Performance

190 lines (153 loc) โ€ข 6.56 kB
import CacheManagerTests from './unit/cache-manager.test.js'; import JSONParserTests from './unit/json-parser.test.js'; import RequestPoolTests from './unit/request-pool.test.js'; import StressTests from './integration/stress-test.js'; /** * Comprehensive test runner for all provider tests */ class TestRunner { constructor() { this.totalTests = 0; this.passedTests = 0; this.failedTests = 0; this.startTime = null; } async runAllTests() { console.log('๐Ÿš€ Starting Comprehensive Test Suite\n'); console.log('====================================='); this.startTime = Date.now(); try { // Unit Tests console.log('๐Ÿ“‹ UNIT TESTS'); console.log('=============\n'); await this.runUnitTests(); console.log('\n๐Ÿ“‹ INTEGRATION & STRESS TESTS'); console.log('==============================\n'); await this.runIntegrationTests(); this.printFinalSummary(); } catch (error) { console.error('โŒ Test runner failed:', error); process.exit(1); } } async runUnitTests() { // Cache Manager Tests console.log('๐Ÿงช Cache Manager Unit Tests'); const cacheTests = new CacheManagerTests(); await cacheTests.runAllTests(); this.aggregateResults(cacheTests.testResults); // JSON Parser Tests console.log('๐Ÿงช JSON Parser Unit Tests'); const parserTests = new JSONParserTests(); await parserTests.runAllTests(); this.aggregateResults(parserTests.testResults); // Request Pool Tests console.log('๐Ÿงช Request Pool Unit Tests'); const poolTests = new RequestPoolTests(); await poolTests.runAllTests(); this.aggregateResults(poolTests.testResults); } async runIntegrationTests() { // Stress and Integration Tests console.log('๐Ÿงช Stress & Integration Tests'); const stressTests = new StressTests(); await stressTests.runAllTests(); this.aggregateResults(stressTests.testResults); } aggregateResults(testResults) { testResults.forEach(result => { this.totalTests++; if (result.status === 'PASS') { this.passedTests++; } else { this.failedTests++; } }); } printFinalSummary() { const endTime = Date.now(); const duration = endTime - this.startTime; const successRate = ((this.passedTests / this.totalTests) * 100).toFixed(1); console.log('\n๐ŸŽฏ FINAL TEST SUMMARY'); console.log('====================='); console.log(`๐Ÿ“Š Total Tests: ${this.totalTests}`); console.log(`โœ… Passed: ${this.passedTests}`); console.log(`โŒ Failed: ${this.failedTests}`); console.log(`๐Ÿ“ˆ Success Rate: ${successRate}%`); console.log(`โฑ๏ธ Duration: ${duration}ms`); console.log(`๐Ÿš€ Average: ${(duration / this.totalTests).toFixed(2)}ms per test`); if (this.failedTests === 0) { console.log('\n๐ŸŽ‰ ALL TESTS PASSED! ๐ŸŽ‰'); console.log('The refactored IPC Provider is working perfectly!'); } else { console.log(`\nโš ๏ธ ${this.failedTests} test(s) failed. Please review the results above.`); } console.log('=====================\n'); // Exit with appropriate code process.exit(this.failedTests === 0 ? 0 : 1); } } // Performance validation test async function validatePerformanceImprovements() { console.log('๐Ÿ”ฌ Performance Validation'); console.log('=========================\n'); try { // Import and run performance benchmarks const { default: PerformanceBenchmark } = await import('../benchmarks/performance-test.js'); const benchmark = new PerformanceBenchmark(); console.log('Running performance benchmarks to validate improvements...\n'); await benchmark.runAllTests(); console.log('โœ… Performance validation completed\n'); } catch (error) { console.log('โš ๏ธ Performance validation skipped:', error.message); console.log(' (This is normal if running without benchmark dependencies)\n'); } } // Component integration test async function validateComponentIntegration() { console.log('๐Ÿ”— Component Integration Validation'); console.log('===================================\n'); try { const { IPCProvider } = await import('../index.js'); // Test that all components work together const provider = new IPCProvider('/tmp/integration-test.ipc', { cacheEnabled: true, batchRequests: true, metricsEnabled: true, poolSize: 10 }); // Test component interaction const stats = provider.getStats(); console.log('โœ… All components loaded successfully'); console.log('โœ… Provider initialization successful'); console.log('โœ… Statistics gathering functional'); console.log(`โœ… Cache system: ${stats.cache.enabled ? 'enabled' : 'disabled'}`); console.log(`โœ… Batch processing: ${stats.batch ? 'available' : 'unavailable'}`); console.log(`โœ… Metrics tracking: ${stats.metrics.enabled ? 'enabled' : 'disabled'}`); console.log(`โœ… Object pooling: ${stats.pool.totalPoolSize} objects ready`); console.log('\n๐ŸŽฏ Component integration validation passed!\n'); } catch (error) { console.error('โŒ Component integration validation failed:', error); throw error; } } // Main execution async function main() { console.log('๐Ÿงช IPC Provider v2.0 - Comprehensive Test Suite'); console.log('================================================\n'); // Validate component integration first await validateComponentIntegration(); // Run performance validation await validatePerformanceImprovements(); // Run comprehensive test suite const testRunner = new TestRunner(); await testRunner.runAllTests(); } // Run if executed directly if (import.meta.url === `file://${process.argv[1]}`) { main().catch(error => { console.error('๐Ÿ’ฅ Test suite failed:', error); process.exit(1); }); } export default TestRunner;