/** * Tests for QuoterFactory * * Verifies dynamic quoter contract creation with address resolution */ describe('QuoterFactory', () => { it('should have QuoterFactory module available', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); expect(fs.existsSync(quoterFactoryPath)).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('QuoterFactory'); }); describe('QuoterFactory class', () => { it('should define QuoterFactory class', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('class QuoterFactory'); expect(content).toContain('export'); }); it('should accept networkConfig in constructor', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('constructor'); expect(content).toContain('networkConfig'); }); it('should have ProtocolDetector as dependency', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('ProtocolDetector'); }); it('should have AbiManager as dependency', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('AbiManager'); }); }); describe('createQuoterV2 method', () => { it('should define createQuoterV2 method', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('createQuoterV2'); expect(content).toContain('beaconName'); expect(content).toContain('signer: ContractRunner'); }); it('should get protocol from beaconName', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); // Should use ProtocolDetector to get protocol expect(content).toContain('getProtocol'); }); it('should resolve quoter address using getQuoterV2Address', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('getQuoterV2Address'); }); it('should get quoter ABI from AbiManager', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('getQuoterV2Abi'); }); it('should return ethers.Contract instance', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); const returnsContract = content.includes('new Contract'); expect(returnsContract).toBe(true); }); it('should handle error when quoter address not found', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); const hasErrorHandling = content.includes('throw new Error') || (content.includes('if (!') && content.includes('address')); expect(hasErrorHandling).toBe(true); }); }); describe('Integration with ProtocolConfig', () => { it('should import getQuoterV2Address', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('getQuoterV2Address'); const importsProtocolConfig = content.includes('ProtocolConfig') || content.includes('./ProtocolConfig'); expect(importsProtocolConfig).toBe(true); }); it('should pass protocol and networkConfig to getQuoterV2Address', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); // Should call getQuoterV2Address with protocol and networkConfig expect(content).toContain('getQuoterV2Address'); expect(content).toContain('networkConfig'); }); }); describe('Protocol-specific handling', () => { it('should handle Algebra protocols', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); // AbiManager should handle protocol-specific ABIs expect(content).toContain('getQuoterV2Abi'); }); it('should handle Shadow protocol', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); // AbiManager should handle protocol-specific ABIs expect(content).toContain('getQuoterV2Abi'); }); it('should handle ThickV2 protocol', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); // AbiManager should handle protocol-specific ABIs expect(content).toContain('getQuoterV2Abi'); }); it('should handle Aerodrome protocol', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); // AbiManager should handle protocol-specific ABIs expect(content).toContain('getQuoterV2Abi'); }); }); describe('Imports', () => { it('should import ethers', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('ethers'); }); it('should import ProtocolDetector', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('ProtocolDetector'); }); it('should import AbiManager', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('AbiManager'); }); it('should import getQuoterV2Address', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); expect(content).toContain('getQuoterV2Address'); }); }); describe('Type safety', () => { it('should have proper return type for createQuoterV2', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); const hasReturnType = content.includes(': ethers.Contract') || content.includes(': Contract'); expect(hasReturnType).toBe(true); }); it('should type networkConfig parameter', () => { const fs = require('fs'); const path = require('path'); const quoterFactoryPath = path.join( __dirname, '../../src/helpers/QuoterFactory.ts', ); const content = fs.readFileSync(quoterFactoryPath, 'utf-8'); const hasNetworkConfigType = content.includes('networkConfig: NetworkConfig') || content.includes('networkConfig: any'); expect(hasNetworkConfigType).toBe(true); }); }); });