From d60d466c836adf8052ae8923ca5d927b0d3156bf Mon Sep 17 00:00:00 2001 From: moody salem Date: Wed, 15 Apr 2020 08:25:33 -0400 Subject: [PATCH] Change the test to verify the actual gas used instead of the buggy estimated gas used --- package.json | 1 + test/UniswapV2Factory.spec.ts | 5 +++-- test/UniswapV2Pair.spec.ts | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 17adc5b..1feab26 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "scripts": { "lint": "yarn prettier ./test/*.ts --check", + "lint:fix": "yarn prettier ./test/*.ts --write", "clean": "rimraf ./build/", "precompile": "yarn clean", "compile": "waffle .waffle.json", diff --git a/test/UniswapV2Factory.spec.ts b/test/UniswapV2Factory.spec.ts index 14cc73d..432aac3 100644 --- a/test/UniswapV2Factory.spec.ts +++ b/test/UniswapV2Factory.spec.ts @@ -66,8 +66,9 @@ describe('UniswapV2Factory', () => { }) it('createPair:gas', async () => { - const gasCost = await factory.estimate.createPair(...TEST_ADDRESSES) - expect(gasCost).to.eq(2512920) + const tx = await factory.createPair(...TEST_ADDRESSES) + const receipt = await tx.wait() + expect(receipt.gasUsed).to.eq(2512920) }) it('setFeeTo', async () => { diff --git a/test/UniswapV2Pair.spec.ts b/test/UniswapV2Pair.spec.ts index 3bd86ab..6258301 100644 --- a/test/UniswapV2Pair.spec.ts +++ b/test/UniswapV2Pair.spec.ts @@ -176,8 +176,9 @@ describe('UniswapV2Pair', () => { const expectedOutputAmount = bigNumberify('453305446940074565') await token1.transfer(pair.address, swapAmount) await mineBlock(provider, (await provider.getBlock('latest')).timestamp + 1) - const gasCost = await pair.estimate.swap(expectedOutputAmount, 0, wallet.address, '0x', overrides) - expect(gasCost).to.eq(79136) + const tx = await pair.swap(expectedOutputAmount, 0, wallet.address, '0x', overrides) + const receipt = await tx.wait() + expect(receipt.gasUsed).to.eq(73462) }) it('burn', async () => {