|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { getAddress } from 'viem'; |
| 3 | +import { contract } from './contract'; |
| 4 | +import { publicClient } from '../../test/utils'; |
| 5 | + |
| 6 | +// Uniswap V3 Factory on Base Sepolia |
| 7 | +const UNISWAP_V3_FACTORY = getAddress('0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24'); |
| 8 | +const UNISWAP_V3_FACTORY_ABI = [ |
| 9 | + { |
| 10 | + name: 'owner', |
| 11 | + type: 'function', |
| 12 | + stateMutability: 'view', |
| 13 | + inputs: [], |
| 14 | + outputs: [{ name: '', type: 'address' }], |
| 15 | + }, |
| 16 | + { |
| 17 | + name: 'feeAmountTickSpacing', |
| 18 | + type: 'function', |
| 19 | + stateMutability: 'view', |
| 20 | + inputs: [{ name: 'fee', type: 'uint24' }], |
| 21 | + outputs: [{ name: '', type: 'int24' }], |
| 22 | + }, |
| 23 | + { |
| 24 | + name: 'getPool', |
| 25 | + type: 'function', |
| 26 | + stateMutability: 'view', |
| 27 | + inputs: [ |
| 28 | + { name: 'tokenA', type: 'address' }, |
| 29 | + { name: 'tokenB', type: 'address' }, |
| 30 | + { name: 'fee', type: 'uint24' }, |
| 31 | + ], |
| 32 | + outputs: [{ name: 'pool', type: 'address' }], |
| 33 | + }, |
| 34 | +] as const; |
| 35 | + |
| 36 | +const USDC = getAddress('0x036CbD53842c5426634e7929541eC2318f3dCF7e'); |
| 37 | +const WETH = getAddress('0x4200000000000000000000000000000000000006'); |
| 38 | + |
| 39 | +// --------------------------------------------------------------------------- |
| 40 | +// Tests |
| 41 | +// --------------------------------------------------------------------------- |
| 42 | + |
| 43 | +describe('contract — Uniswap V3 Factory (Base Sepolia)', () => { |
| 44 | + const factory = contract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI); |
| 45 | + |
| 46 | + it('stores the correct address and abi', () => { |
| 47 | + expect(factory.address).toBe(UNISWAP_V3_FACTORY); |
| 48 | + expect(factory.abi).toBe(UNISWAP_V3_FACTORY_ABI); |
| 49 | + }); |
| 50 | + |
| 51 | + it('read(owner) returns a valid address', async () => { |
| 52 | + const owner = await factory.read('owner', []); |
| 53 | + expect(owner).toMatch(/^0x[0-9a-fA-F]{40}$/); |
| 54 | + }); |
| 55 | + |
| 56 | + it('read(feeAmountTickSpacing) returns 60 for the 0.3% fee tier', async () => { |
| 57 | + const tickSpacing = await factory.read('feeAmountTickSpacing', [3000]); |
| 58 | + expect(tickSpacing).toBe(60); |
| 59 | + }); |
| 60 | + |
| 61 | + it('read(feeAmountTickSpacing) returns 200 for the 1% fee tier', async () => { |
| 62 | + const tickSpacing = await factory.read('feeAmountTickSpacing', [10000]); |
| 63 | + expect(tickSpacing).toBe(200); |
| 64 | + }); |
| 65 | + |
| 66 | + it('read(getPool) returns an address for USDC/WETH 0.3% pool', async () => { |
| 67 | + const pool = await factory.read('getPool', [USDC, WETH, 3000]); |
| 68 | + expect(pool).toMatch(/^0x[0-9a-fA-F]{40}$/); |
| 69 | + }); |
| 70 | + |
| 71 | + it('read(getPool) is symmetric — same pool regardless of token order', async () => { |
| 72 | + const [poolA, poolB] = await Promise.all([ |
| 73 | + factory.read('getPool', [USDC, WETH, 3000]), |
| 74 | + factory.read('getPool', [WETH, USDC, 3000]), |
| 75 | + ]); |
| 76 | + expect(poolA).toBe(poolB); |
| 77 | + }); |
| 78 | +}); |
0 commit comments