Skip to content

Commit

Permalink
clean up the uniswap v3 factory test and add back the tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Nov 18, 2020
1 parent 420d415 commit c07abe0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion test/TickMath.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
39 changes: 20 additions & 19 deletions test/UniswapV3Factory.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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 () => {
Expand All @@ -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', () => {
Expand All @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions test/shared/fixtures.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit c07abe0

Please sign in to comment.