refactor: migrate test infrastructure from ethers v5 to v6#473
refactor: migrate test infrastructure from ethers v5 to v6#473gtg7784 wants to merge 16 commits intoUniswap:mainfrom
Conversation
- ethers ^5.7.2 → ^6.13.0 - @nomicfoundation/hardhat-ethers ^3.0.0 (replaces @nomiclabs/hardhat-ethers) - @nomicfoundation/hardhat-chai-matchers ^2.0.0 (replaces @nomicfoundation/hardhat-chai-matchers v1) - @typechain/ethers-v6 ^0.5.0 (replaces @typechain/ethers-v5) - @typechain/hardhat ^9.0.0 - typescript ^5.0.0, ts-node ^10.9.0, typechain ^8.3.0 - Remove hardhat-typechain, ts-generator - Configure typechain outDir to 'typechain' for backward compatibility - Update tsconfig target to es2020 for bigint support
- Replace ethers.constants.AddressZero with ethers.ZeroAddress - Replace BigNumber return types with native bigint - Update expandTo18DecimalsBN/expandTo6DecimalsBN to return bigint - Convert BigNumber.from() to BigInt() throughout
- Replace defaultAbiCoder import from ethers/lib/utils with AbiCoder from ethers - Use AbiCoder.defaultAbiCoder() for encoding
- Update imports from @ethersproject/* to ethers - Use ReadonlyArray<string> for log topics compatibility - Replace ethers.utils.id with id, AbiCoder imports from ethers - Update bigint types for interface parameter encoding
- Replace splitSignature with Signature.from() - Replace _signTypedData with signTypedData - Replace contract.address with await contract.getAddress() - Replace wallet.getChainId() with provider.getNetwork() pattern - Import BigNumberish, MaxUint256, Signature from ethers
- Replace MaxUint256 import from ethers constants to ethers top-level - Replace BigNumber types with bigint throughout - Replace contract.address with await contract.getAddress() - Replace gasUsed.mul(effectiveGasPrice) with bigint multiplication - Use 'as unknown as' cast for ethers v6 Contract type compatibility - Import TransactionResponse from ethers instead of @ethersproject
- Replace BigNumber arithmetic with native bigint operators
- Convert BigInt('...') for large price constants
- Use .toString() for JSBI compatibility with v6 bigint returns
- Update sqrtPrice parameter types to bigint
- Replace _signTypedData with signTypedData - Replace contract.address with await contract.getAddress() - Update BigNumber types to bigint
- Replace @ethersproject/* imports with ethers - Replace @nomiclabs/hardhat-ethers with @nomicfoundation/hardhat-ethers - Replace BigNumber types with bigint, .sub()/.add() with native operators - Pre-cache contract addresses via getAddress() - Use 'as unknown as' for TypeChain contract casts
- Replace @nomiclabs/hardhat-ethers with @nomicfoundation/hardhat-ethers - Use 'as unknown as' for TypeChain contract casts - Pre-cache contract addresses via getAddress()
- Replace @ethersproject/* imports with ethers - Replace BigNumber types with bigint, arithmetic with native operators - Pre-cache contract addresses via getAddress() - Use 'as unknown as' for TypeChain contract casts
- Replace @ethersproject/* imports with ethers - Replace BigNumber/BigNumberish types with bigint/number - Replace .sub()/.add()/.mul() with native bigint operators - Pre-cache permit2Address, routerAddress via getAddress() - Use 'as unknown as' for TypeChain contract casts
- Replace @ethersproject/* imports with ethers - Replace BigNumber types with bigint throughout - Replace .sub()/.add()/.mul()/.div() with native bigint operators - Pre-cache all contract addresses (permit2, router, v4PositionManager, tokens) - Use BigInt(ONE_PERCENT_BIPS) for percentage calculations - Use 'as unknown as' for TypeChain contract casts
- Replace @ethersproject/* imports with ethers - Replace BigNumber types with bigint, BigNumber.from() with BigInt() - Replace .sub()/.add()/.mul() with native bigint operators - Pre-cache all contract addresses via getAddress() - Use 'as unknown as' for TypeChain contract casts
- Replace @ethersproject/* imports with ethers - Replace ethers.utils.Interface/AbiCoder/id with ethers v6 equivalents - Replace BigNumber types with bigint, BigNumber.from() with BigInt/0n - Replace .sub()/.add() with native bigint operators - Replace receipt.events?.find() with interface.parseLog() pattern - Pre-cache contract addresses via getAddress() - Use 'as unknown as' for TypeChain contract casts
- Migrate all 6 gas test files to ethers v6 patterns - Replace @ethersproject/* and @nomiclabs/* imports - Replace BigNumber/BigNumberish types with bigint - Replace .sub()/.add() with native bigint operators - Replace receipt.events?.find() with interface.parseLog() - Pre-cache contract addresses via getAddress() - Use 'as unknown as' for TypeChain contract casts - Remove obsolete gas snapshots (to be regenerated)
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Caution Review the following alerts detected in dependencies. According to your organization's Security Policy, you must resolve all "Block" alerts before proceeding. It is recommended to resolve "Warn" alerts too. Learn more about Socket for GitHub.
|
Summary
Migrate the entire TypeScript test infrastructure from ethers v5 to ethers v6, updating all 29 TypeScript files across shared helpers, integration tests, and gas benchmark tests.
^5.7.2→^6.13.0and all associated Hardhat/TypeChain pluginsBigNumberwith nativebigintthroughout (265+ occurrences)contract.addresswithawait contract.getAddress()/ pre-cached addressesethers.utils.*namespace with ethers v6 top-level exportsreceipt.events?.find()withinterface.parseLog()patternMotivation
ethers v6 brings native
bigintsupport, smaller bundle size, and improved TypeScript types. This migration modernizes the test infrastructure while keeping all contract interfaces and test logic unchanged.Changes
Infrastructure (3 files)
package.jsonhardhat.config.tstsconfig.jsontarget: es2020for bigint supportShared Helpers (14 files)
BigNumber→bigint,BigNumberishretained (valid in v6)ethers.constants.AddressZero→ethers.ZeroAddressdefaultAbiCoderfromethers/lib/utils→AbiCoderfrometherssplitSignature→Signature.from(),_signTypedData→signTypedDatacontract.address→await contract.getAddress()Test Files (7 files)
UniversalRouter.test.ts,CheckOwnership.test.ts,UniswapV2.test.tsUniswapV3.test.ts,UniswapV4.test.ts,UniswapMixed.test.tsV3ToV4Migration.test.tsGas Tests (6 files)
yarn test:gas)Key Migration Patterns
Verification
npm run compilepasses — 158 Solidity files compiled, 374 ethers-v6 typings generated@ethersproject/*,ethers.utils.*,.sub()/.add()/.mul()/.div())INFURA_API_KEYin.envfor mainnet fork execution