diff --git a/test/TickMath.spec.ts b/test/TickMath.spec.ts index f2b93a790..54c715822 100644 --- a/test/TickMath.spec.ts +++ b/test/TickMath.spec.ts @@ -1,5 +1,5 @@ import {ethers} from 'hardhat' -import {Contract, BigNumber, BigNumberish} from 'ethers' +import {BigNumber, BigNumberish} from 'ethers' import {TickMathTest} from '../typechain/TickMathTest' import {expect} from './shared/expect' import snapshotGasCost from './shared/snapshotGasCost' diff --git a/test/UniswapV3Factory.spec.ts b/test/UniswapV3Factory.spec.ts index 375ebb07f..7c22cdf63 100644 --- a/test/UniswapV3Factory.spec.ts +++ b/test/UniswapV3Factory.spec.ts @@ -1,10 +1,9 @@ import {expect} from './shared/expect' -import {Contract} from 'ethers' import {waffle, ethers} from 'hardhat' import snapshotGasCost from './shared/snapshotGasCost' +import {UniswapV3Factory} from '../typechain/UniswapV3Factory' import {getCreate2Address} from './shared/utilities' -import {factoryFixture} from './shared/fixtures' const TEST_ADDRESSES: [string, string] = [ '0x1000000000000000000000000000000000000000', @@ -14,10 +13,12 @@ const TEST_ADDRESSES: [string, string] = [ describe('UniswapV3Factory', () => { const [wallet, other] = waffle.provider.getWallets() - let factory: Contract + let factory: UniswapV3Factory + let pairBytecode: string beforeEach('deploy factory', async () => { const factoryFactory = await ethers.getContractFactory('UniswapV3Factory') - factory = await factoryFactory.deploy(await wallet.getAddress()) + pairBytecode = (await ethers.getContractFactory('UniswapV3Pair')).bytecode + factory = (await factoryFactory.deploy(await wallet.getAddress())) as UniswapV3Factory }) it('initial feeToSetter is deployer', async () => { @@ -29,25 +30,25 @@ describe('UniswapV3Factory', () => { }) async function createPair(tokens: [string, string]) { - // const create2Address = getCreate2Address(factory.address, tokens, UniswapV3Pair.bytecode) - await factory.createPair(...tokens) - // .to.emit(factory, 'PairCreated') - // .withArgs(TEST_ADDRESSES[0], TEST_ADDRESSES[1], create2Address, BigNumber.from(1)) + const reverseTokens: [string, string] = [tokens[1], tokens[0]] + + const create2Address = getCreate2Address(factory.address, tokens, pairBytecode) + await expect(factory.createPair(...tokens)) + .to.emit(factory, 'PairCreated') + .withArgs(TEST_ADDRESSES[0], TEST_ADDRESSES[1], create2Address, 1) await expect(factory.createPair(...tokens)).to.be.revertedWith('UniswapV3::createPair: pair already exists') - await expect(factory.createPair(...tokens.slice().reverse())).to.be.revertedWith( - 'UniswapV3::createPair: pair already exists' - ) - // expect(await factory.getPair(...tokens)).to.eq(create2Address) - // expect(await factory.getPair(...tokens.slice().reverse())).to.eq(create2Address) - // expect(await factory.allPairs(0)).to.eq(create2Address) + await expect(factory.createPair(...reverseTokens)).to.be.revertedWith('UniswapV3::createPair: pair already exists') + expect(await factory.getPair(...tokens)).to.eq(create2Address) + expect(await factory.getPair(...reverseTokens)).to.eq(create2Address) + expect(await factory.allPairs(0)).to.eq(create2Address) expect(await factory.allPairsLength()).to.eq(1) const pairContractFactory = await ethers.getContractFactory('UniswapV3Pair') - // const pair = new Contract(create2Address, JSON.stringify(UniswapV3Pair.abi), waffle.provider) - // expect(await pair.factory()).to.eq(factory.address) - // expect(await pair.token0()).to.eq(TEST_ADDRESSES[0]) - // expect(await pair.token1()).to.eq(TEST_ADDRESSES[1]) + const pair = pairContractFactory.attach(create2Address) + expect(await pair.factory()).to.eq(factory.address) + expect(await pair.token0()).to.eq(TEST_ADDRESSES[0]) + expect(await pair.token1()).to.eq(TEST_ADDRESSES[1]) } describe('#createPair', () => { @@ -56,7 +57,7 @@ describe('UniswapV3Factory', () => { }) it('succeeds in reverse', async () => { - await createPair(TEST_ADDRESSES.slice().reverse() as [string, string]) + await createPair([TEST_ADDRESSES[1], TEST_ADDRESSES[0]]) }) it('gas', async () => { diff --git a/test/shared/fixtures.ts b/test/shared/fixtures.ts index e4d59799f..ae9d15da6 100644 --- a/test/shared/fixtures.ts +++ b/test/shared/fixtures.ts @@ -1,5 +1,5 @@ -import {Contract, Signer} from 'ethers' -import {waffle, ethers} from 'hardhat' +import {Signer} from 'ethers' +import {ethers} from 'hardhat' import {TestERC20} from '../../typechain/TestERC20' import {TestUniswapV3Callee} from '../../typechain/TestUniswapV3Callee' import {MockTimeUniswapV3Pair} from '../../typechain/MockTimeUniswapV3Pair' diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..1522f0b91 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es2018", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "outDir": "dist", + "typeRoots": ["./typechain", "./node_modules/@types"], + "types": ["@nomiclabs/hardhat-ethers", "@nomiclabs/hardhat-waffle"] + }, + "include": ["./test"], + "files": ["./hardhat.config.ts"] +}