Skip to content

Commit

Permalink
test: add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Jul 31, 2024
1 parent 60137d3 commit 71369bc
Show file tree
Hide file tree
Showing 35 changed files with 2,673 additions and 196 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ jobs:

- name: Run Matchstick tests
run: yarn test
integration-test-core-pool:
runs-on: ubuntu-20.04
needs: unit-test
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Start containers
run: docker compose up -d

- name: Sleep to allow graph-node to become accessible
shell: bash
run: sleep 45s

- name: Generate Core Pool graphql types
run: |
docker exec -i subgraph-hardhat-node yarn workspace venus-subgraph run prepare:docker
docker exec -i subgraph-hardhat-node yarn workspace venus-subgraph run codegen
docker exec -i subgraph-hardhat-node yarn workspace venus-subgraph run create:docker
docker exec -i subgraph-hardhat-node yarn workspace venus-subgraph run deploy:docker
sleep 5s
docker exec -i subgraph-hardhat-node yarn workspace venus-subgraph run generate-subgraph-types
- name: Run Core Pool integration tests
run: |
docker exec -i subgraph-hardhat-node yarn workspace venus-subgraph run test:integration --bail
- name: Stop containers
if: always()
run: |
docker compose down -v
docker system prune -f -a --volumes
integration-test-isolated-pools:
runs-on: ubuntu-20.04
Expand Down
5 changes: 5 additions & 0 deletions copy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ rm ./contracts/governance/contracts/Governance/Timelock.sol

mkdir -p ./contracts/mocks
cp -rf ./mocks/ ./contracts/mocks/contracts
mv ./contracts/mocks/contracts/VBep20DelegateR1.sol ./contracts/protocol/contracts/Tokens/VTokens/legacy/VBep20DelegateR1.sol
mv ./contracts/mocks/contracts/VBep20DelegatorR1.sol ./contracts/protocol/contracts/Tokens/VTokens/legacy/VBep20DelegatorR1.sol

mkdir -p ./contracts/utilities
cp -rf ./node_modules/@venusprotocol/solidity-utilities/contracts ./contracts/utilities
194 changes: 189 additions & 5 deletions deploy/000-core-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ import deployMockTokens from '@venusprotocol/venus-protocol/dist/deploy/007-depl
import deployXvs from '@venusprotocol/venus-protocol/dist/deploy/007-deploy-xvs';
import deployVaults from '@venusprotocol/venus-protocol/dist/deploy/008-deploy-vaults';
import configureVaults from '@venusprotocol/venus-protocol/dist/deploy/009-configure-vaults';
import deployMarkets from '@venusprotocol/venus-protocol/dist/deploy/011-deploy-markets';
// import deployMarkets from '@venusprotocol/venus-protocol/dist/deploy/011-deploy-markets';
import deployPrime from '@venusprotocol/venus-protocol/dist/deploy/012-deploy-prime';
import deployConfigurePrime from '@venusprotocol/venus-protocol/dist/deploy/013-configure-prime';
import deployVaiController from '@venusprotocol/venus-protocol/dist/deploy/013-vai-controller-impl';
import deployTokenRedeemer from '@venusprotocol/venus-protocol/dist/deploy/014-deploy-token-redeemer';
import { DeployFunction } from 'hardhat-deploy/types';
import deployVaiController from '@venusprotocol/venus-protocol/dist/deploy/014-vai-controller-deploy';
import setupVaiController from '@venusprotocol/venus-protocol/dist/deploy/014-vai-controller-set-config';
import deployTokenRedeemer from '@venusprotocol/venus-protocol/dist/deploy/015-deploy-token-redeemer';
import {
InterestRateModels,
getConfig,
getTokenConfig,
} from '@venusprotocol/venus-protocol/dist/helpers/deploymentConfig';
import { BigNumber, BigNumberish } from 'ethers';
import { parseUnits } from 'ethers/lib/utils';
import { ethers } from 'hardhat';
import { DeployFunction, DeployResult } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand All @@ -35,10 +44,185 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await deployXvs(hre);
await deployVaults(hre);
await configureVaults(hre);
await deployMarkets(hre);
// await deployMarkets(hre);

const mantissaToBps = (num: BigNumberish) => {
return BigNumber.from(num).div(parseUnits('1', 14)).toString();
};

const VTOKEN_DECIMALS = 8;
const EMPTY_BYTES_ARRAY = '0x';

const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();
const { tokensConfig, marketsConfig } = await getConfig(hre.network.name);

const comptrollerDeployment = await deployments.get('Unitroller');
const vTreasuryDeployment = await deployments.get('VTreasuryV8');

console.log(`Got deployment of Unitroller with address: ${comptrollerDeployment.address}`);

await deploy('MockUSDT', {
contract: 'MockToken',
from: deployer,
args: ['Tether', 'USDT', 18],
log: true,
autoMine: true,
});

await deploy('MockDOGE', {
contract: 'MockToken',
from: deployer,
args: ['Doge', 'DOGE', 18],
log: true,
autoMine: true,
});

const extraMarkets = [
{
name: 'Venus DOGE',
asset: 'DOGE',
symbol: 'vDOGE',
rateModel: InterestRateModels.JumpRate.toString(),
baseRatePerYear: '0',
multiplierPerYear: parseUnits('0.06875', 18),
jumpMultiplierPerYear: parseUnits('2.5', 18),
kink_: parseUnits('0.8', 18),
collateralFactor: parseUnits('0.9', 18),
liquidationThreshold: parseUnits('0.95', 18),
reserveFactor: parseUnits('0.1', 18),
initialSupply: parseUnits('9000', 18),
supplyCap: parseUnits('5500000000', 18),
borrowCap: parseUnits('4400000000', 18),
vTokenReceiver: vTreasuryDeployment.address,
},
{
name: 'Venus USDT',
asset: 'USDT',
symbol: 'vUSDT',
rateModel: InterestRateModels.JumpRate.toString(),
baseRatePerYear: '0',
multiplierPerYear: parseUnits('0.06875', 18),
jumpMultiplierPerYear: parseUnits('2.5', 18),
kink_: parseUnits('0.8', 18),
collateralFactor: parseUnits('0.9', 18),
liquidationThreshold: parseUnits('0.95', 18),
reserveFactor: parseUnits('0.1', 18),
initialSupply: parseUnits('9000', 18),
supplyCap: parseUnits('5500000', 18),
borrowCap: parseUnits('4400000', 18),
vTokenReceiver: vTreasuryDeployment.address,
},
];

for (const market of [...marketsConfig, ...extraMarkets]) {
const {
name,
asset,
symbol,
rateModel,
baseRatePerYear,
multiplierPerYear,
jumpMultiplierPerYear,
kink_,
} = market;

const token = getTokenConfig(asset, [
...tokensConfig,
{
isMock: true,
name: 'DOGE',
symbol: 'DOGE',
decimals: 18,
},
{
isMock: true,
name: 'USDT',
symbol: 'USDT',
decimals: 18,
},
]);
let tokenContract;
if (token.isMock) {
tokenContract = await ethers.getContract(`Mock${token.symbol}`);
} else {
tokenContract = await ethers.getContractAt(
'@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20',
token.tokenAddress,
);
}

let rateModelAddress: string;
if (rateModel === InterestRateModels.JumpRate.toString()) {
const [b, m, j, k] = [baseRatePerYear, multiplierPerYear, jumpMultiplierPerYear, kink_].map(
mantissaToBps,
);
const rateModelName = `JumpRateModel_base${b}bps_slope${m}bps_jump${j}bps_kink${k}bps`;
console.log(`Deploying interest rate model ${rateModelName}`);
const result: DeployResult = await deploy(rateModelName, {
from: deployer,
contract: 'JumpRateModel',
args: [baseRatePerYear, multiplierPerYear, jumpMultiplierPerYear, kink_],
log: true,
});
rateModelAddress = result.address;
} else {
const [b, m] = [baseRatePerYear, multiplierPerYear].map(mantissaToBps);
const rateModelName = `WhitePaperInterestRateModel_base${b}bps_slope${m}bps`;
console.log(`Deploying interest rate model ${rateModelName}`);
const result: DeployResult = await deploy(rateModelName, {
from: deployer,
contract: 'WhitePaperInterestRateModel',
args: [baseRatePerYear, multiplierPerYear],
log: true,
});
rateModelAddress = result.address;
}

const vBep20DelegateDeployment = await deploy('VBep20DelegateR1', { from: deployer });

const underlyingDecimals = Number(await tokenContract.decimals());
const vTokenImplemenationAddress = vBep20DelegateDeployment.address;

console.log(
`Deploying VBep20 Proxy for ${symbol} with Implementation ${vTokenImplemenationAddress}`,
);

await deploy(`${symbol}`, {
contract: 'VBep20DelegatorR1',
from: deployer,
args: [
tokenContract.address,
comptrollerDeployment.address,
rateModelAddress,
parseUnits('1', underlyingDecimals + 18 - VTOKEN_DECIMALS),
name,
symbol,
VTOKEN_DECIMALS,
deployer,
vTokenImplemenationAddress,
EMPTY_BYTES_ARRAY,
],
log: true,
});
}
const deployerSigner = await ethers.getSigner(deployer);

const comptroller = await ethers.getContractAt('ComptrollerMock', comptrollerDeployment.address);

const vDogeToken = await ethers.getContract('vDOGE');
const vFdusdToken = await ethers.getContract('vFDUSD');
const vUsdtToken = await ethers.getContract('vUSDT');
await comptroller.connect(deployerSigner)._supportMarket(vDogeToken.address);
await comptroller.connect(deployerSigner)._supportMarket(vFdusdToken.address);
await comptroller.connect(deployerSigner)._supportMarket(vUsdtToken.address);

await deployPrime(hre);
await deployConfigurePrime(hre);
await deployVaiController(hre);
await setupVaiController(hre);
await deployTokenRedeemer(hre);
};

Expand Down
17 changes: 15 additions & 2 deletions deploy/002-deploy-oracles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import deployOracle from '@venusprotocol/oracle/dist/deploy/1-deploy-oracles';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

export default deployOracle;
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

await deploy('MockPriceOracleUnderlyingPrice', {
from: deployer,
log: true,
autoMine: true,
});
};

export default func;
Loading

0 comments on commit 71369bc

Please sign in to comment.