Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ChainVaultTest to work on localhost network #236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion forge/test/strategy/StrategyThenaGammaTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 3 additions & 2 deletions scripts/vault/deploy-generic-minichef-strat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
};

Expand Down
25 changes: 17 additions & 8 deletions tasks/test-data.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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,
});
}
Expand All @@ -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,
Expand Down