-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tentative fork testing utils
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const ADDRESSES = { | ||
bscmainnet: { | ||
BUSD: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56", | ||
USDT: "0x55d398326f99059fF775485246999027B3197955", | ||
PancakeSwapRouter: "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", | ||
MoveDebtDelegate: "0x89621C48EeC04A85AfadFD37d32077e65aFe2226", | ||
Unitroller: "0xfD36E2c2a6789Db23113685031d7F16329158384", | ||
NormalTimelock: "0x939bD8d64c0A9583A7Dcea9933f7b21697ab6396", | ||
vUSDT: "0xfD5840Cd36d94D7229439859C0112a4185BC0255", | ||
vBUSD: "0x95c78222B3D6e262426483D42CfA53685A67Ab9D", | ||
}, | ||
bsctestnet: {}, | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { impersonateAccount, setBalance } from "@nomicfoundation/hardhat-network-helpers"; | ||
import { NumberLike } from "@nomicfoundation/hardhat-network-helpers/dist/src/types"; | ||
import { ethers } from "hardhat"; | ||
import hre from "hardhat"; | ||
|
||
import { ADDRESSES } from "./constants"; | ||
|
||
export type Network = keyof typeof ADDRESSES; | ||
export type ForkConfig<N extends Network> = { [T in N]: number }; | ||
export type Addresses<N extends Network> = typeof ADDRESSES[N]; | ||
|
||
export const resetFork = async (network: Network, blockNumber: number) => { | ||
await hre.network.provider.request({ | ||
method: "hardhat_reset", | ||
params: [ | ||
{ | ||
forking: { | ||
jsonRpcUrl: process.env[`ARCHIVE_NODE_${network}`], | ||
blockNumber, | ||
}, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
export const forking = <N extends Network>(config: ForkConfig<N>, fn: (addresses: Addresses<N>) => void) => { | ||
if (!process.env.FORK || process.env.FORK === "false") { | ||
return; | ||
} | ||
const config_ = Object.entries(config) as [N, number][]; | ||
config_.forEach(([network, blockNumber]) => { | ||
describe(`Forking ${network} at block #${blockNumber}`, () => { | ||
before(async () => { | ||
await resetFork(network, blockNumber); | ||
}); | ||
fn(ADDRESSES[network]); | ||
}); | ||
}); | ||
}; | ||
|
||
export const initMainnetUser = async (user: string, balance?: NumberLike) => { | ||
await impersonateAccount(user); | ||
if (balance !== undefined) { | ||
await setBalance(user, balance); | ||
} | ||
return ethers.getSigner(user); | ||
}; |