/** * Tests for ProtocolConfig * * Verifies protocol configuration mapping and key resolution */ describe('ProtocolConfig', () => { it('should have ProtocolConfig module available', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') expect(fs.existsSync(protocolConfigPath)).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('ProtocolConfig') expect(indexContent).toContain('getProtocolConfigKeys') }) describe('PROTOCOL_CONFIG_MAP', () => { it('should define protocol configuration map', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('PROTOCOL_CONFIG_MAP') expect(content).toContain('Partial>') }) it('should have factory and quoter keys for all protocols', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Verify key protocols are mapped expect(content).toContain('Protocol.QuickSwap') expect(content).toContain('Protocol.Lynex') expect(content).toContain('Protocol.ThickV2') expect(content).toContain('Protocol.Shadow') expect(content).toContain('Protocol.MachineX') expect(content).toContain('Protocol.Aerodrome') expect(content).toContain('Protocol.PoolShark') }) it('should have factoryKey and quoterKey for each protocol', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('factoryKey') expect(content).toContain('quoterKey') }) }) describe('DEFAULT_PROTOCOL_CONFIG', () => { it('should define default configuration', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('DEFAULT_PROTOCOL_CONFIG') expect(content).toContain('UniswapFactory') expect(content).toContain('QuoterV2') }) it('should be used as fallback', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Verify default is returned when protocol is null or not found expect(content).toContain('DEFAULT_PROTOCOL_CONFIG') }) }) describe('getProtocolConfigKeys function', () => { it('should define getProtocolConfigKeys function', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('function getProtocolConfigKeys') expect(content).toContain('protocol: Protocol | null') expect(content).toContain('ProtocolConfig') }) it('should return default config for null protocol', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('if (!protocol)') expect(content).toContain('return DEFAULT_PROTOCOL_CONFIG') }) it('should return default config for unknown protocol', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('if (!config)') expect(content).toContain('return DEFAULT_PROTOCOL_CONFIG') }) it('should return protocol-specific config when found', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('PROTOCOL_CONFIG_MAP[protocol]') expect(content).toContain('return config') }) }) describe('ProtocolConfig interface', () => { it('should define ProtocolConfig interface', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('interface ProtocolConfig') expect(content).toContain('factoryKey: string') expect(content).toContain('quoterKey: string') }) }) describe('Protocol coverage', () => { it('should cover major DEX protocols', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Verify major protocols are included const majorProtocols = [ 'QuickSwap', 'Lynex', 'ThickV2', 'Shadow', 'MachineX', 'Aerodrome', 'PoolShark', 'PancakeSwap', 'Sushi', ] majorProtocols.forEach(protocol => { expect(content).toContain(protocol) }) }) }) describe('Integration', () => { it('should import Protocol from @steerprotocol/sdk', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('@steerprotocol/sdk') expect(content).toContain('Protocol') }) }) describe('Address Resolution Functions', () => { describe('getFactoryAddress', () => { it('should define getFactoryAddress function', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('function getFactoryAddress') expect(content).toContain('protocol: Protocol | null') expect(content).toContain('networkConfig') }) it('should return factory address from network config', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should look up factoryKey in networkConfig expect(content).toContain('factoryKey') const hasAddressLookup = content.includes('networkConfig[') && content.includes('.address') expect(hasAddressLookup).toBe(true) }) it('should use DEFAULT_PROTOCOL_CONFIG for null protocol', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should fall back to default when protocol is null expect(content).toContain('DEFAULT_PROTOCOL_CONFIG.factoryKey') }) it('should use DEFAULT_PROTOCOL_CONFIG for unmapped protocol', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should check if config exists before using it const hasConfigCheck = content.includes('if (!config)') || content.includes('config || DEFAULT') expect(hasConfigCheck).toBe(true) }) it('should handle protocol-specific factory keys', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should use protocol's factoryKey from PROTOCOL_CONFIG_MAP expect(content).toContain('PROTOCOL_CONFIG_MAP') expect(content).toContain('factoryKey') }) }) describe('getQuoterV2Address', () => { it('should define getQuoterV2Address function', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') expect(content).toContain('function getQuoterV2Address') expect(content).toContain('protocol: Protocol | null') expect(content).toContain('networkConfig') }) it('should return quoter address from network config', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should look up quoterKey in networkConfig expect(content).toContain('quoterKey') const hasAddressLookup = content.includes('networkConfig[') && content.includes('.address') expect(hasAddressLookup).toBe(true) }) it('should use DEFAULT_PROTOCOL_CONFIG for null protocol', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should fall back to default when protocol is null expect(content).toContain('DEFAULT_PROTOCOL_CONFIG.quoterKey') }) it('should use DEFAULT_PROTOCOL_CONFIG for unmapped protocol', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should check if config exists before using it const hasConfigCheck = content.includes('if (!config)') || content.includes('config || DEFAULT') expect(hasConfigCheck).toBe(true) }) it('should handle protocol-specific quoter keys', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Should use protocol's quoterKey from PROTOCOL_CONFIG_MAP expect(content).toContain('PROTOCOL_CONFIG_MAP') expect(content).toContain('quoterKey') }) it('should export getQuoterV2Address function', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') const exportsFunction = content.includes('export') && content.includes('getQuoterV2Address') expect(exportsFunction).toBe(true) }) }) describe('Address Resolution Integration', () => { it('should return string addresses', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Functions should return string (address) const hasStringReturn = content.includes(': string') || content.includes('return') expect(hasStringReturn).toBe(true) }) it('should accept networkConfig parameter', () => { const fs = require('fs') const path = require('path') const protocolConfigPath = path.join(__dirname, '../../src/helpers/ProtocolConfig.ts') const content = fs.readFileSync(protocolConfigPath, 'utf-8') // Both functions should accept networkConfig as parameter expect(content).toContain('networkConfig') }) }) }) })