Skip to content

Commit 878a58a

Browse files
make unit tests compatible with external test nodes (Uniswap#155)
* allow testing against a remote node by getting wallets via the other method * Revert "add gas test for nftManager#positions (Uniswap#139)" This reverts commit cdc178d * use snapshot for gas estimates * apply other arbitrum patch changes * snapshots * Fix code style issues with Prettier Co-authored-by: Lint Action <[email protected]>
1 parent 0e8ffed commit 878a58a

22 files changed

+211
-178
lines changed

hardhat.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export default {
6363
kovan: {
6464
url: `https://kovan.infura.io/v3/${process.env.INFURA_API_KEY}`,
6565
},
66+
arbitrum: {
67+
url: `http://localhost:8547`,
68+
gas: 8000000,
69+
},
6670
},
6771
etherscan: {
6872
// Your API key for Etherscan

test/CallbackValidation.spec.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Contract, constants } from 'ethers'
1+
import { Contract, constants, Wallet } from 'ethers'
22
import { waffle, ethers } from 'hardhat'
33
import { Fixture } from 'ethereum-waffle'
44
import completeFixture from './shared/completeFixture'
@@ -7,7 +7,8 @@ import { TestERC20, TestCallbackValidation } from '../typechain'
77
import { FeeAmount } from './shared/constants'
88

99
describe('CallbackValidation', () => {
10-
const [nonpairAddr, ...wallets] = waffle.provider.getWallets()
10+
let nonpairAddr: Wallet, wallets: Wallet[]
11+
1112
const callbackValidationFixture: Fixture<{
1213
callbackValidation: TestCallbackValidation
1314
tokens: [TestERC20, TestERC20]
@@ -16,10 +17,10 @@ describe('CallbackValidation', () => {
1617
const { factory } = await completeFixture(wallets, provider)
1718
const tokenFactory = await ethers.getContractFactory('TestERC20')
1819
const callbackValidationFactory = await ethers.getContractFactory('TestCallbackValidation')
19-
const tokens = (await Promise.all([
20-
tokenFactory.deploy(constants.MaxUint256.div(2)), // do not use maxu256 to avoid overflowing
21-
tokenFactory.deploy(constants.MaxUint256.div(2)),
22-
])) as [TestERC20, TestERC20]
20+
const tokens: [TestERC20, TestERC20] = [
21+
(await tokenFactory.deploy(constants.MaxUint256.div(2))) as TestERC20, // do not use maxu256 to avoid overflowing
22+
(await tokenFactory.deploy(constants.MaxUint256.div(2))) as TestERC20,
23+
]
2324
const callbackValidation = (await callbackValidationFactory.deploy()) as TestCallbackValidation
2425

2526
return {
@@ -36,6 +37,8 @@ describe('CallbackValidation', () => {
3637
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
3738

3839
before('create fixture loader', async () => {
40+
;[nonpairAddr, ...wallets] = await (ethers as any).getSigners()
41+
3942
loadFixture = waffle.createFixtureLoader(wallets)
4043
})
4144

test/Multicall.spec.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
import { Wallet } from 'ethers'
12
import { ethers, waffle } from 'hardhat'
23
import { TestMulticall } from '../typechain/TestMulticall'
34
import { expect } from './shared/expect'
45

56
import snapshotGasCost from './shared/snapshotGasCost'
67

78
describe('Multicall', async () => {
8-
const wallets = waffle.provider.getWallets()
9+
let wallets: Wallet[]
910

1011
let multicall: TestMulticall
1112

13+
before('get wallets', async () => {
14+
wallets = await (ethers as any).getSigners()
15+
})
16+
1217
beforeEach('create multicall', async () => {
1318
const multicallTestFactory = await ethers.getContractFactory('TestMulticall')
1419
multicall = (await multicallTestFactory.deploy()) as TestMulticall

test/NFTDescriptor.spec.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigNumber, constants } from 'ethers'
1+
import { BigNumber, constants, Wallet } from 'ethers'
22
import { encodePriceSqrt } from './shared/encodePriceSqrt'
33
import { waffle, ethers } from 'hardhat'
44
import { expect } from './shared/expect'
@@ -18,7 +18,7 @@ const LOWEST_SQRT_RATIO = 4310618292
1818
const HIGHEST_SQRT_RATIO = BigNumber.from(33849).mul(TEN.pow(34))
1919

2020
describe('NFTDescriptor', () => {
21-
const wallets = waffle.provider.getWallets()
21+
let wallets: Wallet[]
2222

2323
const nftDescriptorFixture: Fixture<{
2424
tokens: [TestERC20Metadata, TestERC20Metadata, TestERC20Metadata, TestERC20Metadata]
@@ -34,12 +34,13 @@ describe('NFTDescriptor', () => {
3434
},
3535
})
3636
const nftDescriptor = (await NFTDescriptorFactory.deploy()) as NFTDescriptorTest
37-
const tokens = (await Promise.all([
38-
tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST1'), // do not use maxu256 to avoid overflowing
39-
tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST2'),
40-
tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST3'),
41-
tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST4'),
42-
])) as [TestERC20Metadata, TestERC20Metadata, TestERC20Metadata, TestERC20Metadata]
37+
const TestERC20Metadata = tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST1')
38+
const tokens: [TestERC20Metadata, TestERC20Metadata, TestERC20Metadata, TestERC20Metadata] = [
39+
(await tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST1')) as TestERC20Metadata, // do not use maxu256 to avoid overflowing
40+
(await tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST2')) as TestERC20Metadata,
41+
(await tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST3')) as TestERC20Metadata,
42+
(await tokenFactory.deploy(constants.MaxUint256.div(2), 'Test ERC20', 'TEST4')) as TestERC20Metadata,
43+
]
4344
tokens.sort((a, b) => (a.address.toLowerCase() < b.address.toLowerCase() ? -1 : 1))
4445
return {
4546
nftDescriptor,
@@ -53,6 +54,8 @@ describe('NFTDescriptor', () => {
5354
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
5455

5556
before('create fixture loader', async () => {
57+
wallets = await (ethers as any).getSigners()
58+
5659
loadFixture = waffle.createFixtureLoader(wallets)
5760
})
5861

test/NonfungiblePositionManager.spec.ts

+6-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigNumberish, constants } from 'ethers'
1+
import { BigNumberish, constants, Wallet } from 'ethers'
22
import { waffle, ethers } from 'hardhat'
33

44
import { Fixture } from 'ethereum-waffle'
@@ -9,7 +9,6 @@ import {
99
IWETH9,
1010
IUniswapV3Factory,
1111
SwapRouter,
12-
NonfungiblePositionManagerPositionsGasTest,
1312
} from '../typechain'
1413
import completeFixture from './shared/completeFixture'
1514
import { computePoolAddress } from './shared/computePoolAddress'
@@ -28,8 +27,8 @@ import { extractJSONFromURI } from './shared/extractJSONFromURI'
2827
import { abi as IUniswapV3PoolABI } from '@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json'
2928

3029
describe('NonfungiblePositionManager', () => {
31-
const wallets = waffle.provider.getWallets()
32-
const [wallet, other] = wallets
30+
let wallets: Wallet[]
31+
let wallet: Wallet, other: Wallet
3332

3433
const nftFixture: Fixture<{
3534
nft: MockTimeNonfungiblePositionManager
@@ -65,6 +64,9 @@ describe('NonfungiblePositionManager', () => {
6564
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
6665

6766
before('create fixture loader', async () => {
67+
wallets = await (ethers as any).getSigners()
68+
;[wallet, other] = wallets
69+
6870
loadFixture = waffle.createFixtureLoader(wallets)
6971
})
7072

@@ -1166,38 +1168,6 @@ describe('NonfungiblePositionManager', () => {
11661168
})
11671169
})
11681170

1169-
describe('#positions', async () => {
1170-
it('gas', async () => {
1171-
const positionsGasTestFactory = await ethers.getContractFactory('NonfungiblePositionManagerPositionsGasTest')
1172-
const positionsGasTest = (await positionsGasTestFactory.deploy(
1173-
nft.address
1174-
)) as NonfungiblePositionManagerPositionsGasTest
1175-
1176-
await nft.createAndInitializePoolIfNecessary(
1177-
tokens[0].address,
1178-
tokens[1].address,
1179-
FeeAmount.MEDIUM,
1180-
encodePriceSqrt(1, 1)
1181-
)
1182-
1183-
await nft.mint({
1184-
token0: tokens[0].address,
1185-
token1: tokens[1].address,
1186-
tickLower: getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]),
1187-
tickUpper: getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM]),
1188-
fee: FeeAmount.MEDIUM,
1189-
recipient: other.address,
1190-
amount0Desired: 15,
1191-
amount1Desired: 15,
1192-
amount0Min: 0,
1193-
amount1Min: 0,
1194-
deadline: 10,
1195-
})
1196-
1197-
await snapshotGasCost(positionsGasTest.getGasCostOfPositions(1))
1198-
})
1199-
})
1200-
12011171
describe('fees accounting', () => {
12021172
beforeEach('create two positions', async () => {
12031173
await nft.createAndInitializePoolIfNecessary(

test/NonfungibleTokenPositionDescriptor.spec.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { constants } from 'ethers'
1+
import { constants, Wallet } from 'ethers'
22
import { waffle, ethers } from 'hardhat'
33
import { expect } from './shared/expect'
44
import { Fixture } from 'ethereum-waffle'
@@ -17,7 +17,7 @@ const TBTC = '0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa'
1717
const WBTC = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'
1818

1919
describe('NonfungibleTokenPositionDescriptor', () => {
20-
const [...wallets] = waffle.provider.getWallets()
20+
let wallets: Wallet[]
2121

2222
const nftPositionDescriptorCompleteFixture: Fixture<{
2323
nftPositionDescriptor: NonfungibleTokenPositionDescriptor
@@ -26,11 +26,11 @@ describe('NonfungibleTokenPositionDescriptor', () => {
2626
}> = async (wallets, provider) => {
2727
const { factory, nft, router, nftDescriptor } = await completeFixture(wallets, provider)
2828
const tokenFactory = await ethers.getContractFactory('TestERC20')
29-
const tokens = (await Promise.all([
30-
tokenFactory.deploy(constants.MaxUint256.div(2)), // do not use maxu25e6 to avoid overflowing
31-
tokenFactory.deploy(constants.MaxUint256.div(2)),
32-
tokenFactory.deploy(constants.MaxUint256.div(2)),
33-
])) as [TestERC20, TestERC20, TestERC20]
29+
const tokens: [TestERC20, TestERC20, TestERC20] = [
30+
(await tokenFactory.deploy(constants.MaxUint256.div(2))) as TestERC20, // do not use maxu256 to avoid overflowing
31+
(await tokenFactory.deploy(constants.MaxUint256.div(2))) as TestERC20,
32+
(await tokenFactory.deploy(constants.MaxUint256.div(2))) as TestERC20,
33+
]
3434
tokens.sort((a, b) => (a.address.toLowerCase() < b.address.toLowerCase() ? -1 : 1))
3535

3636
return {
@@ -48,6 +48,8 @@ describe('NonfungibleTokenPositionDescriptor', () => {
4848
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
4949

5050
before('create fixture loader', async () => {
51+
wallets = await (ethers as any).getSigners()
52+
5153
loadFixture = waffle.createFixtureLoader(wallets)
5254
})
5355

test/OracleLibrary.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ describe('OracleLibrary', () => {
1010
let tokens: TestERC20[]
1111
let oracle: OracleTest
1212

13-
const wallets = waffle.provider.getWallets()
14-
1513
const oracleTestFixture = async () => {
1614
const tokenFactory = await ethers.getContractFactory('TestERC20')
17-
const tokens = (await Promise.all([
18-
tokenFactory.deploy(constants.MaxUint256.div(2)), // do not use maxu256 to avoid overflowing
19-
tokenFactory.deploy(constants.MaxUint256.div(2)),
20-
])) as [TestERC20, TestERC20]
15+
const tokens: [TestERC20, TestERC20] = [
16+
(await tokenFactory.deploy(constants.MaxUint256.div(2))) as TestERC20, // do not use maxu256 to avoid overflowing
17+
(await tokenFactory.deploy(constants.MaxUint256.div(2))) as TestERC20,
18+
]
2119

2220
tokens.sort((a, b) => (a.address.toLowerCase() < b.address.toLowerCase() ? -1 : 1))
2321

@@ -31,7 +29,7 @@ describe('OracleLibrary', () => {
3129
}
3230

3331
before('create fixture loader', async () => {
34-
loadFixture = waffle.createFixtureLoader(wallets)
32+
loadFixture = waffle.createFixtureLoader(await (ethers as any).getSigners())
3533
})
3634

3735
beforeEach('deploy fixture', async () => {

test/Path.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { decodePath, encodePath } from './shared/path'
99
import snapshotGasCost from './shared/snapshotGasCost'
1010

1111
describe('Path', () => {
12-
const wallets = waffle.provider.getWallets()
13-
1412
let path: PathTest
1513

1614
let tokenAddresses = [
@@ -28,7 +26,7 @@ describe('Path', () => {
2826
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
2927

3028
before('create fixture loader', async () => {
31-
loadFixture = waffle.createFixtureLoader(wallets)
29+
loadFixture = waffle.createFixtureLoader(await (ethers as any).getSigners())
3230
})
3331

3432
beforeEach('deploy PathTest', async () => {

test/PeripheryImmutableState.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { expect } from './shared/expect'
77
import { v3RouterFixture } from './shared/externalFixtures'
88

99
describe('PeripheryImmutableState', () => {
10-
const wallets = waffle.provider.getWallets()
11-
1210
const nonfungiblePositionManagerFixture: Fixture<{
1311
weth9: IWETH9
1412
factory: Contract
@@ -33,7 +31,7 @@ describe('PeripheryImmutableState', () => {
3331
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
3432

3533
before('create fixture loader', async () => {
36-
loadFixture = waffle.createFixtureLoader(wallets)
34+
loadFixture = waffle.createFixtureLoader(await (ethers as any).getSigners())
3735
})
3836

3937
beforeEach('load fixture', async () => {

test/PoolAddress.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { expect } from './shared/expect'
77
import snapshotGasCost from './shared/snapshotGasCost'
88

99
describe('PoolAddress', () => {
10-
const wallets = waffle.provider.getWallets()
11-
1210
let poolAddress: PoolAddressTest
1311

1412
const poolAddressTestFixture = async () => {
@@ -19,7 +17,7 @@ describe('PoolAddress', () => {
1917
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
2018

2119
before('create fixture loader', async () => {
22-
loadFixture = waffle.createFixtureLoader(wallets)
20+
loadFixture = waffle.createFixtureLoader(await (ethers as any).getSigners())
2321
})
2422

2523
beforeEach('deploy PoolAddressTest', async () => {

test/PoolTicksCounter.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { deployMockContract, Fixture, MockContract } from 'ethereum-waffle'
77
import { Artifact } from 'hardhat/types'
88

99
describe('PoolTicksCounter', () => {
10-
const wallets = waffle.provider.getWallets()
11-
1210
const TICK_SPACINGS = [200, 60, 10]
1311

1412
TICK_SPACINGS.forEach((TICK_SPACING) => {
@@ -22,6 +20,7 @@ describe('PoolTicksCounter', () => {
2220
}
2321

2422
before(async () => {
23+
const wallets = await (ethers as any).getSigners()
2524
PoolAbi = await artifacts.readArtifact('IUniswapV3Pool')
2625
const poolTicksHelperFactory = await ethers.getContractFactory('PoolTicksCounterTest')
2726
PoolTicksCounter = (await poolTicksHelperFactory.deploy()) as PoolTicksCounterTest

test/Quoter.spec.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fixture } from 'ethereum-waffle'
2-
import { constants } from 'ethers'
2+
import { constants, Wallet } from 'ethers'
33
import { ethers, waffle } from 'hardhat'
44
import { MockTimeNonfungiblePositionManager, Quoter, TestERC20 } from '../typechain'
55
import completeFixture from './shared/completeFixture'
@@ -9,11 +9,10 @@ import { expandTo18Decimals } from './shared/expandTo18Decimals'
99
import { expect } from './shared/expect'
1010
import { encodePath } from './shared/path'
1111
import { createPool } from './shared/quoter'
12-
import { getMaxTick, getMinTick } from './shared/ticks'
1312

1413
describe('Quoter', () => {
15-
const wallets = waffle.provider.getWallets()
16-
const [wallet, trader] = wallets
14+
let wallet: Wallet
15+
let trader: Wallet
1716

1817
const swapRouterFixture: Fixture<{
1918
nft: MockTimeNonfungiblePositionManager
@@ -24,12 +23,10 @@ describe('Quoter', () => {
2423

2524
// approve & fund wallets
2625
for (const token of tokens) {
27-
await Promise.all([
28-
token.approve(router.address, constants.MaxUint256),
29-
token.approve(nft.address, constants.MaxUint256),
30-
token.connect(trader).approve(router.address, constants.MaxUint256),
31-
token.transfer(trader.address, expandTo18Decimals(1_000_000)),
32-
])
26+
await token.approve(router.address, constants.MaxUint256)
27+
await token.approve(nft.address, constants.MaxUint256)
28+
await token.connect(trader).approve(router.address, constants.MaxUint256)
29+
await token.transfer(trader.address, expandTo18Decimals(1_000_000))
3330
}
3431

3532
const quoterFactory = await ethers.getContractFactory('Quoter')
@@ -49,6 +46,8 @@ describe('Quoter', () => {
4946
let loadFixture: ReturnType<typeof waffle.createFixtureLoader>
5047

5148
before('create fixture loader', async () => {
49+
const wallets = await (ethers as any).getSigners()
50+
;[wallet, trader] = wallets
5251
loadFixture = waffle.createFixtureLoader(wallets)
5352
})
5453

0 commit comments

Comments
 (0)