Skip to content

Commit

Permalink
Merge pull request #299 from VenusProtocol/VEN-1831
Browse files Browse the repository at this point in the history
[VEN-1831]: Multichain fork tests
  • Loading branch information
Debugger022 authored Jul 26, 2024
2 parents 3858317 + 230e80e commit e22dbc6
Show file tree
Hide file tree
Showing 13 changed files with 1,188 additions and 906 deletions.
16 changes: 16 additions & 0 deletions contracts/test/Mocks/MockPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import { ProtocolShareReserve } from "@venusprotocol/protocol-reserve/contracts/
import { VToken } from "../../VToken.sol";

contract MockPriceOracle is ResilientOracleInterface {
struct TokenConfig {
/// @notice asset address
address asset;
/// @notice `oracles` stores the oracles based on their role in the following order:
/// [main, pivot, fallback],
/// It can be indexed with the corresponding enum OracleRole value
address[3] oracles;
/// @notice `enableFlagsForOracles` stores the enabled state
/// for each oracle in the same order as `oracles`
bool[3] enableFlagsForOracles;
}

mapping(address => uint256) public assetPrices;

//set price in 6 decimal precision
Expand All @@ -28,6 +40,10 @@ contract MockPriceOracle is ResilientOracleInterface {
return assetPrices[asset];
}

function getTokenConfig(address asset) external view returns (TokenConfig memory) {}

function setTokenConfig(TokenConfig memory tokenConfig) public {}

//https://compound.finance/docs/prices
function getUnderlyingPrice(address vToken) public view override returns (uint256) {
return assetPrices[VToken(vToken).underlying()];
Expand Down
17 changes: 14 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,22 @@ extendConfig((config: HardhatConfig) => {
"node_modules/@venusprotocol/protocol-reserve/deployments/ethereum",
],
bscmainnet: [
"node_modules/@venusprotocol/protocol-reserve/deployments/bscmainnet",
"node_modules/@venusprotocol/oracle/deployments/bscmainnet",
"node_modules/@venusprotocol/venus-protocol/deployments/bscmainnet",
"node_modules/@venusprotocol/protocol-reserve/deployments/bscmainnet",
],
opbnbmainnet: [
"node_modules/@venusprotocol/oracle/deployments/opbnbmainnet",
"node_modules/@venusprotocol/protocol-reserve/deployments/opbnbmainnet",
],
opbnbtestnet: [
"node_modules/@venusprotocol/oracle/deployments/opbnbtestnet",
"node_modules/@venusprotocol/protocol-reserve/deployments/opbnbtestnet",
],
arbitrumsepolia: [
"node_modules/@venusprotocol/oracle/deployments/arbitrumsepolia",
"node_modules/@venusprotocol/protocol-reserve/deployments/arbitrumsepolia",
],
opbnbmainnet: ["node_modules/@venusprotocol/oracle/deployments/opbnbmainnet"],
arbitrumsepolia: ["node_modules/@venusprotocol/protocol-reserve/deployments/arbitrumsepolia"],
arbitrumone: ["node_modules/@venusprotocol/protocol-reserve/deployments/arbitrumone"],
},
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"@venusprotocol/governance-contracts": "2.1.0",
"@venusprotocol/oracle": "2.0.0",
"@venusprotocol/oracle": "2.3.0",
"@venusprotocol/protocol-reserve": "2.2.0",
"@venusprotocol/venus-protocol": "9.0.0",
"bignumber.js": "9.0.0",
Expand Down
19 changes: 3 additions & 16 deletions tests/hardhat/Fork/NativeTokenGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import { Comptroller, ERC20, NativeTokenGateway, VToken } from "../../../typecha
import { initMainnetUser, setForkBlock } from "./utils";

const ADMIN = "0x285960C5B22fD66A736C7136967A3eB15e93CC67";
const COMPTROLLER_BEACON = "0xAE2C3F21896c02510aA187BdA0791cDA77083708";
const VTOKEN_BEACON = "0xfc08aADC7a1A93857f6296C3fb78aBA1d286533a";
const COMPTROLLER_ADDRESS = "0x687a01ecF6d3907658f7A7c714749fAC32336D1B";
const POOL_REGISTRY = "0x61CAff113CCaf05FFc6540302c37adcf077C5179";
const VWETH = "0x7c8ff7d2A1372433726f879BD945fFb250B94c65";
const USDT = "0xdAC17F958D2ee523a2206206994597C13D831ec7";
const VUSDT = "0x8C3e3821259B82fFb32B2450A95d2dcbf161C24E";

const USER1 = "0xf89d7b9c864f589bbF53a82105107622B35EaA40";
const USER2 = "0x974CaA59e49682CdA0AD2bbe82983419A2ECC400";
const BLOCK_NUMBER = 19139865;
const BLOCK_NUMBER = 19781700;

async function configureTimeLock() {
impersonatedTimeLock = await initMainnetUser(ADMIN, ethers.utils.parseUnits("2"));
Expand All @@ -44,16 +41,6 @@ async function setup() {
usdt = await ethers.getContractAt("@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20", USDT);

const comptroller = await ethers.getContractAt("Comptroller", COMPTROLLER_ADDRESS);
const newComptrollerFactory = await ethers.getContractFactory("Comptroller");
const newComptrollerImplementation = await newComptrollerFactory.deploy(POOL_REGISTRY);
const beaconContract = await ethers.getContractAt("UpgradeableBeacon", COMPTROLLER_BEACON);

const newVToken = await ethers.getContractFactory("VToken");
const newVTokenImplementation = await newVToken.deploy();
const vTokenBeaconContract = await ethers.getContractAt("UpgradeableBeacon", VTOKEN_BEACON);

await beaconContract.connect(impersonatedTimeLock).upgradeTo(newComptrollerImplementation.address);
await vTokenBeaconContract.connect(impersonatedTimeLock).upgradeTo(newVTokenImplementation.address);

vusdt = await ethers.getContractAt("VToken", VUSDT);
vweth = await ethers.getContractAt("VToken", VWETH);
Expand Down Expand Up @@ -94,7 +81,7 @@ if (FORK && FORKED_NETWORK === "ethereum") {
const balanceAfterSupplying = await vweth.balanceOf(await user1.getAddress());
await expect(balanceAfterSupplying.sub(balanceBeforeSupplying).toString()).to.closeTo(
parseUnits("10", 8),
parseUnits("1", 5),
parseUnits("1", 7),
);
await expect(tx).to.changeEtherBalances([user1], [supplyAmount.mul(-1)]);
});
Expand All @@ -115,7 +102,7 @@ if (FORK && FORKED_NETWORK === "ethereum") {

await expect(ethBalanceAfter.sub(ethBalanceBefore)).to.closeTo(redeemAmount, parseUnits("1", 16));

expect(await vweth.balanceOf(await user1.getAddress())).to.eq(0);
expect(await vweth.balanceOf(await user1.getAddress())).to.closeTo(0, 10);
});
});

Expand Down
Loading

0 comments on commit e22dbc6

Please sign in to comment.