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

Add additional Foundry test coverage #322

Merged
merged 60 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
fd73e2d
chore: add Foundry initial test environment mocks
kartojal Feb 14, 2023
7aa567d
chore: remove mint at test
kartojal Feb 14, 2023
63e8085
chore: add tests and borrow fuzz to GhoVariableDebtToken
kartojal Feb 20, 2023
05df7e1
chore: add initial test engine for gho borrow
kartojal Feb 21, 2023
d43701c
chore: add percent calc function
kartojal Feb 22, 2023
55aa0ca
fix: Remove discount lock period mechanism (#293)
miguelmtzinf Feb 20, 2023
ecdbc72
fix: Optimize gho debt balanceof (#297)
miguelmtzinf Feb 20, 2023
b6ad733
fix: Simplify GhoToken.addFacilitator function (#295)
miguelmtzinf Feb 20, 2023
1dc6f09
feat: Add helper contract to manage risk params of GHO reserve (#291)
foodaka Feb 20, 2023
e878746
fix: Remove updateLockDiscountPeriod calls from GhoManager (#298)
miguelmtzinf Feb 20, 2023
1cdea12
chore: initial repay engine
kartojal Feb 27, 2023
a789362
chore: add makefile with coverage html report and ignore mocks, add r…
kartojal Mar 1, 2023
28ffe9a
chore: add 100% coverage for GhoVariableDebtToken contract
kartojal Mar 1, 2023
68d9989
chore: add GhoAToken.sol tests
kartojal Mar 1, 2023
6bc762b
fix: Stop prettier formatting dependencies and cache
Zer0dot Apr 3, 2023
f1e960b
feat: Initial flashminter setup
Zer0dot Apr 12, 2023
4ceddc3
misc: Slight optimisation
Zer0dot Apr 13, 2023
cd82952
test: Add Gho FlashMinter unit tests
Zer0dot Apr 14, 2023
402271b
test: Add flash minter unit tests
Zer0dot Apr 18, 2023
dd0314f
fix: Resolve VSCode import callback issue with forge-std/ds-test
Apr 18, 2023
501c89c
test: Add GhoAToken tests for transfer and self-rescue reverts
Apr 18, 2023
8e25323
fix: exclude foundry-test for hardhat coverage tests
Apr 18, 2023
6c2dbc2
test: Add initial GhoToken unit tests
Apr 20, 2023
3e94649
fix: remove stkAave mocks, replace with BGD repo and update impacted …
Apr 25, 2023
89d1195
Merge branch 'main' into chore/foundry-test-suite
Apr 25, 2023
c17e3ba
fix: resolved error in testUpdateDiscountTokenToZero test
Apr 25, 2023
0457b93
fix: increase node testrunner heap alloc to avoid OOM
Apr 25, 2023
66f3f14
fix: setup stkAave behind proxy
Apr 26, 2023
d319705
test: add GhoOracle unit tests
Apr 26, 2023
888ebb5
test: add GhoDiscountRateStrategy unit/fuzz tests
Apr 26, 2023
caff728
test: add GhoInterestRateStrategy fuzz test
Apr 26, 2023
6f134f0
test: add GhoManager unit tests, mocked PoolConfigurator
Apr 27, 2023
ff332a4
fix: remove unnecessary stopPranks that fail in latest forge
Apr 27, 2023
9551aa7
test: added nonce/domain sep unit tests for GhoAToken
Apr 27, 2023
dc8b27a
test: add GhoStableDebtToken unit tests
Apr 27, 2023
00e2550
feat: add combined coverage from hardhat/foundry
Apr 28, 2023
db4ffae
fix: refactor initial foundry tests
May 1, 2023
4845e84
fix: move MockFlashBorrower to common location
May 1, 2023
68ce5ec
feat: add EmptyDiscountRateStrategy fuzz test
May 1, 2023
53b46c4
feat: add UiGhoDataProvider unit tests
May 1, 2023
f268ccd
feat: complete GhoToken unit tests
May 1, 2023
c3faa88
feat: complete GhoVariableDebtToken unit tests
May 1, 2023
95d3625
feat: add last unit test for GhoVariableDebtToken
May 2, 2023
25cefe8
fix: update ordering in constant/event test files
May 2, 2023
524fb1b
Merge pull request #323 from aave/feat/320-unified-coverage-gen
May 4, 2023
e4c6aa5
Merge pull request #324 from aave/fix/321-refactor-foundry-tests
May 4, 2023
5fcdf00
fix: remove unnecessary prank on proxy init
May 4, 2023
d34d73a
fix: naming of fuzz tests to be more descriptive
May 5, 2023
ae957d0
Merge branch 'main' into feat/319-additional-foundry-test-coverage
miguelmtzinf May 10, 2023
e447d7d
fix: re-remove old tests that got re-merged
May 10, 2023
76f1b30
fix: Remove hardhat unitTests folder
miguelmtzinf May 10, 2023
432886b
fix: Fix constants value of tests
miguelmtzinf May 10, 2023
81f3e4e
test: Add couple of test cases
miguelmtzinf May 10, 2023
e410417
test: Rename test titles
miguelmtzinf May 10, 2023
e8612b7
fix: Rename EmptyDiscountRateStrategy to ZeroDiscountRateStrategy
miguelmtzinf May 10, 2023
2eb10cf
fix: Remove unneeded import
miguelmtzinf May 10, 2023
5c8a258
feat: add genhtml back to combined coverage
May 10, 2023
298153f
fix: add error messages on test reverts
May 10, 2023
b814e60
fix: Fix package scripts
miguelmtzinf May 10, 2023
230a761
fix: Fix deploy script of GhoStableDebtToken
miguelmtzinf May 10, 2023
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
Prev Previous commit
Next Next commit
feat: Add helper contract to manage risk params of GHO reserve (#291)
* setup modifier

* setup gho manager and tests

* remove atoken changes

* use interfaces

* adds test for ghomanager as pooladmin
  • Loading branch information
foodaka authored and kartojal committed Feb 22, 2023
commit 1dc6f0957b42c81ffbe8e73c08fdf58fcd4f2141
23 changes: 23 additions & 0 deletions deploy/10_deploy_ghomanager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
const func: DeployFunction = async function ({
getNamedAccounts,
deployments,
}: HardhatRuntimeEnvironment) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const ghoManager = await deploy('GhoManager', {
from: deployer,
args: [],
log: true,
});
console.log(`GHO Manager: ${ghoManager.address}`);

return true;
};

func.id = 'GhoManager';
func.tags = ['GhoManager', 'full_gho_deploy'];

export default func;
55 changes: 55 additions & 0 deletions src/contracts/facilitators/aave/misc/GhoManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import {IPoolConfigurator} from '@aave/core-v3/contracts/interfaces/IPoolConfigurator.sol';
import {IGhoVariableDebtToken} from 'src/contracts/facilitators/aave/tokens/interfaces/IGhoVariableDebtToken.sol';

/**
* @title GhoManager
* @author Aave
* @notice Helper contract for managing key risk parameters of the GHO reserve within the Aave Facilitator
* @dev This contract is intended to be granted as PoolAdmin
*/
contract GhoManager is Ownable {
/**
* @notice Updates the Discount Rate Strategy
* @param ghoVariableDebtToken The address of GhoVariableDebtToken contract
* @param newDiscountRateStrategy The address of DiscountRateStrategy contract
*/
function updateDiscountRateStrategy(
address ghoVariableDebtToken,
address newDiscountRateStrategy
) external onlyOwner {
IGhoVariableDebtToken(ghoVariableDebtToken).updateDiscountRateStrategy(newDiscountRateStrategy);
}

/**
* @notice Updates the Discount Lock Period
* @param ghoVariableDebtToken The address of GhoVariableDebtToken contract
* @param newLockPeriod The new discount lock period (in seconds)
*/
function updateDiscountLockPeriod(
address ghoVariableDebtToken,
uint256 newLockPeriod
) external onlyOwner {
IGhoVariableDebtToken(ghoVariableDebtToken).updateDiscountLockPeriod(newLockPeriod);
}

/**
* @notice Updates the ReserveInterestRateStrategy
* @param poolConfigurator The address of PoolConfigurator contract
* @param asset The address of the GHO deployed contract
* @param newRateStrategyAddress The address of new RateStrategyAddress contract
*/
function setReserveInterestRateStrategyAddress(
address poolConfigurator,
address asset,
address newRateStrategyAddress
) external onlyOwner {
IPoolConfigurator(poolConfigurator).setReserveInterestRateStrategyAddress(
asset,
newRateStrategyAddress
);
}
}
4 changes: 4 additions & 0 deletions src/helpers/contract-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
VariableDebtToken,
StakedTokenV2Rev4,
GhoFlashMinter,
GhoManager,
} from '../../types';

// Prevent error HH9 when importing this file inside tasks or helpers at Hardhat config load
Expand Down Expand Up @@ -67,6 +68,9 @@ export const getGhoVariableDebtToken = async (
address || (await hre.deployments.get('GhoVariableDebtToken')).address
);

export const getGhoManager = async (address?: tEthereumAddress): Promise<GhoManager> =>
getContract('GhoManager', address || (await hre.deployments.get('GhoManager')).address);

export const getBaseImmutableAdminUpgradeabilityProxy = async (
address: tEthereumAddress
): Promise<BaseImmutableAdminUpgradeabilityProxy> =>
Expand Down
7 changes: 7 additions & 0 deletions src/tasks/main/gho-testnet-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ task('gho-testnet-setup', 'Deploy and Configure Gho').setAction(async (params, h
blankSpace();
await hre.run('upgrade-stkAave');

/*****************************************
* CONFIGURE Ghomanager *
******************************************/
blankSpace();

await hre.run('add-gho-manager');

console.log(`\nGho Setup Complete!\n`);

await hre.run('print-all-deployments');
Expand Down
23 changes: 23 additions & 0 deletions src/tasks/testnet-setup/07_add-gho-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { GhoManager } from '../../../types/src/contracts/facilitators/aave/misc/GhoManager';
import { task } from 'hardhat/config';
import { ghoEntityConfig } from '../../helpers/config';
import { getACLManager } from '@aave/deploy-v3';

task('add-gho-manager', 'Adds ghomanager pooladmin role').setAction(async (_, hre) => {
const { ethers } = hre;

const ghoManager = (await ethers.getContract('GhoManager')) as GhoManager;
const aclArtifact = await getACLManager();
const addPoolAdminTx = await aclArtifact.addPoolAdmin(ghoManager.address);

const addPoolAdminTxReceipt = await addPoolAdminTx.wait();
const newPoolAdminEvents = addPoolAdminTxReceipt.events?.find((e) => {
return e.event === 'RoleGranted';
});
if (newPoolAdminEvents?.args) {
console.log(`Gho manager added as a pooladmin: ${JSON.stringify(newPoolAdminEvents.args[0])}`);
} else {
throw new Error(`Error at adding entity. Check tx: ${addPoolAdminTx.hash}`);
}
return;
});
117 changes: 117 additions & 0 deletions src/test/gho-manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import hre from 'hardhat';
import { expect } from 'chai';
import { makeSuite, TestEnv } from './helpers/make-suite';
import { impersonateAccountHardhat } from '../helpers/misc-utils';
import { ghoReserveConfig } from '../helpers/config';
import { ONE_ADDRESS, ZERO_ADDRESS } from '../helpers/constants';
import { ProtocolErrors } from '@aave/core-v3';
import { getPoolConfiguratorProxy } from '@aave/deploy-v3';

export const TWO_ADDRESS = '0x0000000000000000000000000000000000000002';

makeSuite('Gho Manager End-To-End', (testEnv: TestEnv) => {
let ethers;

let poolSigner;
let randomSigner;
let poolConfigurator;

const mockLockPeriod = 3;

before(async () => {
ethers = hre.ethers;

const { pool } = testEnv;

poolSigner = await impersonateAccountHardhat(pool.address);
randomSigner = await impersonateAccountHardhat(ONE_ADDRESS);
poolConfigurator = await getPoolConfiguratorProxy();
});

it('Update discount rate strategy from gho manager', async function () {
const { variableDebtToken, deployer, discountRateStrategy, ghoManager } = testEnv;

await expect(
ghoManager
.connect(deployer.signer)
.updateDiscountRateStrategy(variableDebtToken.address, TWO_ADDRESS)
).to.emit(variableDebtToken, 'DiscountRateStrategyUpdated');
});

it('Get Discount Strategy - after setting', async function () {
const { variableDebtToken } = testEnv;

expect(await variableDebtToken.getDiscountRateStrategy()).to.be.equal(TWO_ADDRESS);
});

it('Update discount rate strategy from gho manager without owner role (revert expected)', async function () {
const { variableDebtToken, deployer, discountRateStrategy, ghoManager } = testEnv;

await expect(
ghoManager
.connect(randomSigner)
.updateDiscountRateStrategy(variableDebtToken.address, ONE_ADDRESS)
).to.be.revertedWith(ProtocolErrors.OWNABLE_ONLY_OWNER);
});

it('Set Rebalance Lock Period', async function () {
const { ghoManager, deployer, variableDebtToken } = testEnv;

await expect(
ghoManager
.connect(deployer.signer)
.updateDiscountLockPeriod(variableDebtToken.address, mockLockPeriod)
)
.to.emit(variableDebtToken, 'DiscountLockPeriodUpdated')
.withArgs(ghoReserveConfig.DISCOUNT_LOCK_PERIOD, mockLockPeriod);
});

it('Get Rebalance Lock Period', async function () {
const { variableDebtToken } = testEnv;
expect(await variableDebtToken.getDiscountLockPeriod()).to.be.equal(mockLockPeriod);
});

it('Updates gho interest rate strategy', async function () {
const { ghoManager, variableDebtToken, gho, poolAdmin } = testEnv;
const randomAddress = ONE_ADDRESS;
await expect(
ghoManager
.connect(poolAdmin.signer)
.setReserveInterestRateStrategyAddress(poolConfigurator.address, gho.address, randomAddress)
).to.emit(poolConfigurator, 'ReserveInterestRateStrategyChanged');
});

it('Check gho interest rate strategy is set correctly', async function () {
const { variableDebtToken, gho, poolAdmin, aaveDataProvider } = testEnv;
const randomAddress = ONE_ADDRESS;
await expect(await aaveDataProvider.getInterestRateStrategyAddress(gho.address)).to.be.equal(
randomAddress
);
});

it('Check permissions of owner modified functions (revert expected)', async () => {
const { variableDebtToken, users, ghoManager, gho } = testEnv;
const nonPoolAdmin = users[2];

const randomAddress = ONE_ADDRESS;
const randomNumber = '0';
const calls = [
{ fn: 'updateDiscountRateStrategy', args: [variableDebtToken.address, randomAddress] },
{ fn: 'updateDiscountLockPeriod', args: [variableDebtToken.address, randomNumber] },
{
fn: 'setReserveInterestRateStrategyAddress',
args: [poolConfigurator.address, gho.address, randomAddress],
},
];
for (const call of calls) {
await expect(
ghoManager.connect(nonPoolAdmin.signer)[call.fn](...call.args)
).to.be.revertedWith(ProtocolErrors.OWNABLE_ONLY_OWNER);
}
});

it('Check GhoManager is PoolAdmin', async function () {
const { ghoManager, aclManager } = testEnv;
await expect(await aclManager.isPoolAdmin(ghoManager.address)).to.be.equal(true);
});
});
6 changes: 6 additions & 0 deletions src/test/helpers/make-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
StakedTokenV2Rev4,
MintableERC20,
GhoFlashMinter,
GhoManager,
} from '../../../types';
import {
getGhoDiscountRateStrategy,
Expand All @@ -32,6 +33,7 @@ import {
getStakedAave,
getMintableErc20,
getGhoFlashMinter,
getGhoManager,
} from '../../helpers/contract-getters';
import {
getPool,
Expand Down Expand Up @@ -85,6 +87,7 @@ export interface TestEnv {
aaveToken: IERC20;
flashMinter: GhoFlashMinter;
faucetOwner: Faucet;
ghoManager: GhoManager;
}

let HardhatSnapshotId: string = '0x1';
Expand Down Expand Up @@ -122,6 +125,7 @@ const testEnv: TestEnv = {
aaveToken: {} as IERC20,
flashMinter: {} as GhoFlashMinter,
faucetOwner: {} as Faucet,
ghoManager: {} as GhoManager,
} as TestEnv;

export async function initializeMakeSuite() {
Expand Down Expand Up @@ -164,6 +168,8 @@ export async function initializeMakeSuite() {
tokenProxyAddresses.variableDebtTokenAddress
);

testEnv.ghoManager = await getGhoManager();

testEnv.aTokenImplementation = await getGhoAToken();
testEnv.stableDebtTokenImplementation = await getStableDebtToken();
testEnv.variableDebtTokenImplementation = await getGhoVariableDebtToken();
Expand Down