Skip to content

Commit

Permalink
Merge pull request #111 from VenusProtocol/governance-integration-tests
Browse files Browse the repository at this point in the history
Governance integration tests
  • Loading branch information
coreyar authored Oct 5, 2023
2 parents 4d029b3 + f4b7ba3 commit 712176a
Show file tree
Hide file tree
Showing 64 changed files with 839 additions and 991 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,33 @@ jobs:
shell: bash
run: sleep 45s

- name: Generate graphql types
- name: Generate Isolated Pools graphql types
run: |
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run prepare:docker
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run codegen
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run create:docker
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run deploy:docker
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run prepare:docker
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run codegen
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run create:docker
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run deploy:docker
sleep 5s
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run generate-subgraph-types
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run generate-subgraph-types
- name: Run integration tests
- name: Run Isolated Pools integration integration tests
run: |
docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run test:integration
- name: Generate Governance graphql types
run: |
docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run prepare:local
docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run codegen
docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run create:docker
docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run deploy:docker
sleep 5s
docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run generate-subgraph-types
# @TODO - turn on once the integration tests pass
# - name: Run Governance integration integration tests
# run: |
# docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run test:integration

- name: Stop containers
if: always()
run: |
Expand Down
9 changes: 8 additions & 1 deletion copy_contracts.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /bin/sh
# For convience we are going to copy contracts and artifacts locally so they can be
# For convience we are going to copy contracts and artifacts locally so they can be
# Make sure packages are patched properly
yarn patch-package

rm -rf ./contracts
mkdir -p ./contracts/isolated-pools
Expand All @@ -14,5 +16,10 @@ mkdir -p ./contracts/protocol
cp -rf ./node_modules/@venusprotocol/venus-protocol/contracts/ ./contracts/protocol/contracts
rm -rf contracts/protocol/contracts/test

rm contracts/protocol/contracts/Governance/GovernorBravoDelegate.sol
rm contracts/protocol/contracts/Governance/GovernorBravoDelegator.sol
rm contracts/protocol/contracts/Governance/Timelock.sol
rm -rf contracts/protocol/contracts/Lens/VenusLens.sol

mkdir -p ./contracts/mocks
cp -rf ./mocks/ ./contracts/mocks/contracts
20 changes: 20 additions & 0 deletions deploy/000-governance-access-control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import accessControl from '@venusprotocol/governance-contracts/dist/deploy/001-access-control';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

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

await deploy('Timelock', {
from: deployer,
args: [deployer, 3600],
log: true,
autoMine: true,
});

await accessControl(hre);
};

export default func;
2 changes: 0 additions & 2 deletions deploy/001-deploy-mock-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import deployMockTokens from '@venusprotocol/isolated-pools/dist/deploy/001-deploy-mock-tokens';

deployMockTokens.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default deployMockTokens;
2 changes: 0 additions & 2 deletions deploy/002-deploy-oracles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import deployOracle from '@venusprotocol/oracle/dist/deploy/1-deploy-oracles';

deployOracle.skip = async () => process.env.PACKAGE == 'venus-governance';

export default deployOracle;
2 changes: 0 additions & 2 deletions deploy/003-configure-feeds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import configureFeeds from '@venusprotocol/oracle/dist/deploy/2-configure-feeds';

configureFeeds.skip = async () => process.env.PACKAGE == 'venus-governance';

export default configureFeeds;
2 changes: 0 additions & 2 deletions deploy/004-swap-router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/004-swap-router';

deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default deployPoolLens;
2 changes: 0 additions & 2 deletions deploy/005-access-control.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import accessControl from '@venusprotocol/isolated-pools/dist/deploy/005-access-control';

accessControl.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default accessControl;
2 changes: 0 additions & 2 deletions deploy/006-deploy-pool-registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/006-deploy-pool-registry';

deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default deployPoolLens;
2 changes: 0 additions & 2 deletions deploy/007-deploy-pool-lens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/007-deploy-pool-lens';

deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default deployPoolLens;
2 changes: 0 additions & 2 deletions deploy/008-deploy-comptrollers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import accessControlConfigure from '@venusprotocol/isolated-pools/dist/deploy/008-deploy-comptrollers';

accessControlConfigure.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default accessControlConfigure;
2 changes: 0 additions & 2 deletions deploy/009-deploy-vtokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/009-deploy-vtokens';

deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default deployPoolLens;
2 changes: 0 additions & 2 deletions deploy/010-deploy-reward-distributors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/010-deploy-reward-distributors';

deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default deployPoolLens;
2 changes: 0 additions & 2 deletions deploy/011-initial-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/011-initial-liquidity';

upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default upgradeComptroller;
2 changes: 0 additions & 2 deletions deploy/012-transfer-pools-ownership.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/012-transfer-pools-ownership';

upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default upgradeComptroller;
2 changes: 0 additions & 2 deletions deploy/013-vip-based-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/013-vip-based-config';

upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default upgradeComptroller;
2 changes: 0 additions & 2 deletions deploy/014-riskfund-protocolshare.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/014-riskfund-protocolshare';

upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default upgradeComptroller;
2 changes: 0 additions & 2 deletions deploy/015-transfer-funds-ownership.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/015-funds-config';

upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default upgradeComptroller;
2 changes: 0 additions & 2 deletions deploy/016-scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ const scenarios: DeployFunction = async function (hre: HardhatRuntimeEnvironment
await pool1Comptroller.connect(addressSigner).enterMarkets(pools[0].vTokens.map(m => m.vToken));
};

scenarios.skip = async () => process.env.PACKAGE !== 'isolated-pools';

export default scenarios;
64 changes: 64 additions & 0 deletions deploy/017-vaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ethers } from 'hardhat';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

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

const xvsDeployment = await deploy('XVS', {
from: deployer,
args: [deployer],
log: true,
autoMine: true,
});
const xvsAddress = xvsDeployment.address;

const xvsVaultDeployment = await deploy('XVSVault', {
from: deployer,
args: [],
log: true,
autoMine: true,
});

const xvsVaultAddress = xvsVaultDeployment.address;

const xvsVaultProxyDeployment = await deploy('XVSVaultProxy', {
from: deployer,
args: [],
log: true,
autoMine: true,
});

const xvsVaultProxyAddress = xvsVaultProxyDeployment.address;

await deploy('XVSStore', {
from: deployer,
args: [],
log: true,
autoMine: true,
});

const xvsVault = await ethers.getContract('XVSVault');
const xvsStore = await ethers.getContract('XVSStore');
const xvsVaultProxy = await ethers.getContract('XVSVaultProxy');
const accessControlManager = await ethers.getContract('AccessControlManager');

let txn = await xvsVault.setXvsStore(xvsAddress, xvsStore.address);
await txn.wait(1);

txn = await xvsVault.setAccessControl(accessControlManager.address);
await txn.wait(1);

// Become Implementation of XVSVaultProxy
await xvsVaultProxy._setPendingImplementation(xvsVaultAddress);
await xvsVault._become(xvsVaultProxyAddress);

// Set new owner to xvs store
await xvsStore.setNewOwner(xvsVaultAddress);
};

func.tags = ['XVS vault'];

export default func;
78 changes: 78 additions & 0 deletions deploy/018-governance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ethers } from 'hardhat';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

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

const timelock = await ethers.getContract('Timelock');
const xvsVault = await ethers.getContract('XVSVault');

await deploy('GovernorAlpha', {
from: deployer,
args: [timelock.address, xvsVault.address, deployer],
log: true,
autoMine: true,
});

await deploy('GovernorAlpha2', {
from: deployer,
args: [timelock.address, xvsVault.address, deployer, 20],
log: true,
autoMine: true,
});

const governorBravoDelegateDeployment = await deploy('GovernorBravoDelegate', {
from: deployer,
args: [],
log: true,
autoMine: true,
});

const governorBravoDelegate = await ethers.getContractAt(
'GovernorBravoDelegate',
governorBravoDelegateDeployment.address,
);
const minVotingDelay = await governorBravoDelegate.MIN_VOTING_DELAY();
const minVotingPeriod = await governorBravoDelegate.MIN_VOTING_PERIOD();
const minProposalThreshold = await governorBravoDelegate.MIN_PROPOSAL_THRESHOLD();
const proposalConfigs = [
{
votingDelay: minVotingDelay.add(3),
votingPeriod: minVotingPeriod.add(3),
proposalThreshold: minProposalThreshold.add(3),
},
{
votingDelay: minVotingDelay.add(2),
votingPeriod: minVotingPeriod.add(2),
proposalThreshold: minProposalThreshold.add(2),
},
{
votingDelay: minVotingDelay.add(1),
votingPeriod: minVotingPeriod.add(1),
proposalThreshold: minProposalThreshold.add(1),
},
];

const timelocks = [timelock.address, timelock.address, timelock.address];

await deploy('GovernorBravoDelegator', {
from: deployer,
args: [
xvsVault.address,
deployer,
governorBravoDelegate.address,
proposalConfigs,
timelocks,
deployer,
],
log: true,
autoMine: true,
});
};

func.tags = ['Governance'];

export default func;
31 changes: 31 additions & 0 deletions deploy/019-configure-vaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ethers } from 'hardhat';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre;
const { deployer } = await getNamedAccounts();

const accessControlManager = await ethers.getContract('AccessControlManager');
const xvsVault = await ethers.getContract('XVSVault');
const xvs = await ethers.getContract('XVS');

const tx = await accessControlManager.giveCallPermission(
ethers.constants.AddressZero,
'add(address,uint256,address,uint256,uint256)',
deployer,
);
await tx.wait();
// Add token pool to xvs vault
const allocPoint = 100;
const token = xvs.address;
const rewardToken = xvs.address;
const rewardPerBlock = ethers.BigNumber.from(10).pow(16).toString();
const lockPeriod = 300;

await xvsVault.add(rewardToken, allocPoint, token, rewardPerBlock, lockPeriod);
};

func.tags = ['Configure XVS Vault'];

export default func;
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
postgres:
condition: service_started
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000"]
test: ["CMD", "curl", "-f", "http://graph-node:8000"]
interval: 30s
timeout: 12s
retries: 10
Expand Down Expand Up @@ -45,7 +45,6 @@ services:
volumes:
- ./:/usr/app
- /usr/app/node_modules
- /usr/app/contracts
restart: always
healthcheck:
test: ["CMD", "node", "./hardhat-healthcheck.js"]
Expand Down
9 changes: 8 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'module-alias/register';
import '@nomicfoundation/hardhat-toolbox';
import 'hardhat-deploy';
import 'hardhat-dependency-compiler';
import { HardhatUserConfig } from 'hardhat/config';
import 'module-alias/register';

const compilers = {
compilers: [
Expand Down Expand Up @@ -88,6 +88,13 @@ const config: HardhatUserConfig = {
sources: `${__dirname}/contracts`,
artifacts: `${__dirname}/artifacts`,
},
dependencyCompiler: {
paths: [
'@venusprotocol/governance-contracts/contracts/Governance/Timelock.sol',
'@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegate.sol',
'@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegator.sol',
],
},
// Hardhat deploy
namedAccounts: {
deployer: 0, // here this will by default take the first account as deployer
Expand Down
Loading

0 comments on commit 712176a

Please sign in to comment.