forked from Uniswap/v3-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiquidityMath.spec.ts
44 lines (41 loc) · 1.51 KB
/
LiquidityMath.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { expect } from './shared/expect'
import { LiquidityMathTest } from '../typechain/LiquidityMathTest'
import { ethers, waffle } from 'hardhat'
import snapshotGasCost from './shared/snapshotGasCost'
const { BigNumber } = ethers
describe('LiquidityMath', () => {
let liquidityMath: LiquidityMathTest
const fixture = async () => {
const factory = await ethers.getContractFactory('LiquidityMathTest')
return (await factory.deploy()) as LiquidityMathTest
}
beforeEach('deploy LiquidityMathTest', async () => {
liquidityMath = await waffle.loadFixture(fixture)
})
describe('#addDelta', () => {
it('1 + 0', async () => {
expect(await liquidityMath.addDelta(1, 0)).to.eq(1)
})
it('1 + -1', async () => {
expect(await liquidityMath.addDelta(1, -1)).to.eq(0)
})
it('1 + 1', async () => {
expect(await liquidityMath.addDelta(1, 1)).to.eq(2)
})
it('2**128-15 + 15 overflows', async () => {
await expect(liquidityMath.addDelta(BigNumber.from(2).pow(128).sub(15), 15)).to.be.revertedWith('LA')
})
it('0 + -1 underflows', async () => {
await expect(liquidityMath.addDelta(0, -1)).to.be.revertedWith('LS')
})
it('3 + -4 underflows', async () => {
await expect(liquidityMath.addDelta(3, -4)).to.be.revertedWith('LS')
})
it('gas add', async () => {
await snapshotGasCost(liquidityMath.getGasCostOfAddDelta(15, 4))
})
it('gas sub', async () => {
await snapshotGasCost(liquidityMath.getGasCostOfAddDelta(15, -4))
})
})
})