From 8aad3104bda7e6175e02e90e7599b964a8533915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= Date: Fri, 23 Jun 2023 21:36:05 +0200 Subject: [PATCH 1/2] Allow ChainVaultTest to work on localhost network --- .../strategy/StrategyThenaGammaTest.t.sol | 2 +- .../vault/deploy-generic-minichef-strat.ts | 5 ++-- tasks/test-data.ts | 25 +++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/forge/test/strategy/StrategyThenaGammaTest.t.sol b/forge/test/strategy/StrategyThenaGammaTest.t.sol index 260462f5..2d3d762c 100644 --- a/forge/test/strategy/StrategyThenaGammaTest.t.sol +++ b/forge/test/strategy/StrategyThenaGammaTest.t.sol @@ -15,7 +15,7 @@ import "../interfaces/IUniV3Quoter.sol"; import "../../../contracts/BIFI/vaults/BeefyVaultV7.sol"; import "../../../contracts/BIFI/interfaces/common/IERC20Extended.sol"; import "../../../contracts/BIFI/strategies/Common/StratFeeManager.sol"; -import "../../../contracts/BIFI/strategies/Thena/StrategyThenaGamma.sol"; +import "../../../contracts/BIFI/strategies/Gamma/StrategyThenaGamma.sol"; import "../../../contracts/BIFI/utils/AlgebraUtils.sol"; import "./BaseStrategyTest.t.sol"; //import "../vault/util/HardhatNetworkManager.sol"; diff --git a/scripts/vault/deploy-generic-minichef-strat.ts b/scripts/vault/deploy-generic-minichef-strat.ts index 01742c76..22b29745 100644 --- a/scripts/vault/deploy-generic-minichef-strat.ts +++ b/scripts/vault/deploy-generic-minichef-strat.ts @@ -5,6 +5,7 @@ import { verifyContract } from "../../utils/verifyContract"; import vaultV7 from "../../artifacts/contracts/BIFI/vaults/BeefyVaultV7.sol/BeefyVaultV7.json"; import vaultV7Factory from "../../artifacts/contracts/BIFI/vaults/BeefyVaultV7Factory.sol/BeefyVaultV7Factory.json"; + const { platforms: { beefyfinance, synapse, sushi }, tokens: { @@ -25,8 +26,8 @@ if (!process.env.STRATEGIST_ADDRESS) { } const vaultParams = { - mooName: "Moo SynapseSushiLP ETH-SYN", - mooSymbol: "mooSynapseSushiLPETH-SYN", + mooName: "Moo SynapseLP ETH-SYN", + mooSymbol: "mooSynapseLPETH-SYN", delay: 21600, }; diff --git a/tasks/test-data.ts b/tasks/test-data.ts index 9511435c..80bc3881 100644 --- a/tasks/test-data.ts +++ b/tasks/test-data.ts @@ -1,6 +1,8 @@ +import { ethers } from "ethers"; import { task } from "hardhat/config"; import { HttpNetworkConfig } from "hardhat/types"; -import { addressBook } from "blockchain-addressbook"; +import { addressBook, addressBookByChainId } from "blockchain-addressbook"; +import Chain from "blockchain-addressbook/build/types/chain"; task("test-data:network-config", "Exports the current HardHat config to inject in forge tests").setAction( async (taskArgs: { data: "networks" | "addressbook" }, hre, runSuper) => { @@ -10,14 +12,11 @@ task("test-data:network-config", "Exports the current HardHat config to inject i if (netName === "hardhat") { // we can't use a net without url continue; - } else if (netName === "localhost") { - // we can't use a net without chain id - continue; } else { netConf = netConf as HttpNetworkConfig; cleanedNets.push({ name: netName, - chaidId: netConf.chainId, + chaidId: netConf.chainId || -1, url: netConf.url, }); } @@ -28,11 +27,21 @@ task("test-data:network-config", "Exports the current HardHat config to inject i task("test-data:addressbook:beefy", "Fetch beefy addressbook to inject platform addresses in forge tests") .addParam("chain", "The chain name to fetch config from") - .setAction(async (taskArgs: { chain: keyof typeof addressBook}, hre, runSuper) => { - if (!(taskArgs.chain in addressBook)) { + .setAction(async (taskArgs: { chain: keyof typeof addressBook & "localhost"}, hre, runSuper) => { + if (!(taskArgs.chain in addressBook) && taskArgs.chain !== "localhost") { throw new Error(`Chain "${taskArgs.chain}" is not an address book chain. Chains: ${Object.keys(addressBook)}`); } - const { beefyfinance } = addressBook[taskArgs.chain].platforms; + + let chainConfig: Chain; + if (taskArgs.chain === "localhost") { + const netConf = hre.config.networks.localhost as HttpNetworkConfig; + const provider = new ethers.providers.JsonRpcProvider(netConf.url); + const chainId = await provider.getNetwork().then(n => n.chainId); + chainConfig = addressBookByChainId[(chainId + "") as keyof typeof addressBookByChainId]; + } else { + chainConfig = addressBook[taskArgs.chain]; + } + const { beefyfinance } = chainConfig.platforms; const data = { keeper: beefyfinance.keeper, strategyOwner: beefyfinance.strategyOwner, From b5b07c489532157958f6c7b17d8eaa2a38bc099b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= Date: Fri, 23 Jun 2023 21:41:57 +0200 Subject: [PATCH 2/2] Document ChainVaultTest.t.sol usage --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index 6ee82c0f..3bd05971 100644 --- a/readme.md +++ b/readme.md @@ -23,6 +23,12 @@ For extra help in debugging a deployed vault during development, you can use the To prep to run the test suite, input the correct vault address, vaultOwner and stratOwner for the chain your testing in `ProdVaultTest.t.sol`, and modify the `yarn forgeTest:vault` script in package.json to pass in the correct RPC url of the chain your vault is on. Then run `yarn forgeTest:vault` to execute the test run. You can use `console.log` within the tests in `ProdVaultTest.t.sol` to output to the console. +#### 3.1. Using a local fork of the chain +To avoid having to deploy the contracts to a testnet, you can use a local fork of the chain. +In one console start an anvil fork: `anvil -f https://rpc.ankr.com/eth --accounts 3 --balance 300 --no-cors` +Then in another console deploy your contracts to the forked chain using hardhat `localhost` network: `npx hardhat run scripts/vault/deploy-generic-minichef-strat.ts --network localhost` +Finally grab the vault address and run `ChainVaultTest.t.sol`: `CHAIN=ethereum VAULT=0x047c41817954b51309a2bd6f60e47bC115C23f1F forge test --match-contract ChainVaultsTest --ffi` + ### 4. Deploy the smart contracts Once you are confident that everything works as expected you can do the official deploy of the vault + strategy contracts. There are [some scripts](https://github.com/beefyfinance/beefy-contracts/blob/master/scripts/) to help make deploying easier.