/** * Tests for NetworkConfig * * Verifies network configuration loading and retrieval */ describe('NetworkConfig', () => { it('should have NetworkConfig module available', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') expect(fs.existsSync(networkConfigPath)).toBe(true) }) it('should be exported from helpers index', () => { const fs = require('fs') const path = require('path') const indexPath = path.join(__dirname, '../../src/helpers/index.ts') const indexContent = fs.readFileSync(indexPath, 'utf-8') expect(indexContent).toContain('NetworkConfig') expect(indexContent).toContain('getNetworkConfig') }) describe('networks.ts file', () => { it('should have networks.ts in src/config/', () => { const fs = require('fs') const path = require('path') const networksTsPath = path.join(__dirname, '../../src/config/networks.ts') expect(fs.existsSync(networksTsPath)).toBe(true) }) it('should contain valid TypeScript structure', () => { const fs = require('fs') const path = require('path') const networksTsPath = path.join(__dirname, '../../src/config/networks.ts') const content = fs.readFileSync(networksTsPath, 'utf-8') expect(content).toContain('export const networks') expect(content).toContain('ChainId') expect(content).toContain('Chain') }) it('should contain network configurations with required fields', () => { const { networks } = require('../../src/config/networks') // Check at least one network exists const networkKeys = Object.keys(networks) expect(networkKeys.length).toBeGreaterThan(0) // Verify network structure has expected fields (check arbitrum as example) if (networks.arbitrum) { expect(networks.arbitrum).toHaveProperty('chainId') expect(networks.arbitrum).toHaveProperty('QuoterV2') expect(networks.arbitrum.QuoterV2).toHaveProperty('address') } }) it('should contain major networks', () => { const { networks } = require('../../src/config/networks') const majorNetworks = ['Arbitrum', 'Polygon', 'Optimism', 'Base'] const networkKeys = Object.keys(networks) // At least some major networks should be present const hasMajorNetworks = majorNetworks.some(network => networkKeys.includes(network)) expect(hasMajorNetworks).toBe(true) }) }) describe('getNetworkConfig function', () => { it('should define getNetworkConfig function', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') expect(content).toContain('function getNetworkConfig') expect(content).toContain('networkName: Chain') }) it('should return network config for valid network', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') // Should have logic to retrieve network from networks object const hasNetworkRetrieval = content.includes('networks[') || content.includes('return config') expect(hasNetworkRetrieval).toBe(true) }) it('should handle missing network gracefully', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') // Should check if network exists before returning or throw error const hasErrorHandling = content.includes('!networks[networkName]') || content.includes('if (!config)') || content.includes('throw new Error') expect(hasErrorHandling).toBe(true) }) it('should handle case-insensitive network names', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') // Should look up network by name in the networks object expect(content).toContain('networks[') }) }) describe('NetworkConfig type', () => { it('should define NetworkConfig interface or type', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') // Should have type definition or export for network config const hasTypeDefinition = content.includes('interface NetworkConfig') || content.includes('type NetworkConfig') || content.includes('type { NetworkConfig }') expect(hasTypeDefinition).toBe(true) }) it('should include chainId in NetworkConfig', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') expect(content).toContain('chainId') }) }) describe('Networks type', () => { it('should define Networks type for all networks', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') // Should have type for the networks object const hasNetworksType = content.includes('Record { it('should import networks from networks.ts', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') const importsNetworks = content.includes('../config/networks') || content.includes('./config/networks') expect(importsNetworks).toBe(true) }) it('should export getNetworkConfig function', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') const exportsGetNetworkConfig = content.includes('export') && content.includes('getNetworkConfig') expect(exportsGetNetworkConfig).toBe(true) }) it('should export NetworkConfig type', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') const exportsNetworkConfig = content.includes('export') && content.includes('NetworkConfig') expect(exportsNetworkConfig).toBe(true) }) }) describe('Error handling', () => { it('should provide helpful error message for missing network', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') // Should have error message mentioning the network name const hasErrorMessage = content.includes('Network') && content.includes('not found') expect(hasErrorMessage).toBe(true) }) }) describe('Network validation', () => { it('should validate network config has required properties', () => { const fs = require('fs') const path = require('path') const networkConfigPath = path.join(__dirname, '../../src/helpers/NetworkConfig.ts') const content = fs.readFileSync(networkConfigPath, 'utf-8') // Should return the network config object expect(content).toContain('return') }) }) })