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
test: add GhoManager unit tests, mocked PoolConfigurator
  • Loading branch information
cedephrase committed Apr 27, 2023
commit 6f134f0d9d92bd5356dafb8f81c5a58e7cfc1d07
4 changes: 4 additions & 0 deletions src/contracts/foundry-test/TestEnv.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {WETH9Mock} from '@aave/periphery-v3/contracts/mocks/WETH9Mock.sol';
import {ERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/ERC20.sol';
import {GhoAToken} from '../facilitators/aave/tokens/GhoAToken.sol';
import {GhoToken} from '../gho/GhoToken.sol';
import {MockedConfigurator} from './mocks/MockedConfigurator.sol';
import {MockedPool} from './mocks/MockedPool.sol';
import {MockedProvider} from './mocks/MockedProvider.sol';
import {MockedAclManager} from './mocks/MockedAclManager.sol';
Expand All @@ -28,6 +29,7 @@ import {IERC20} from 'aave-stk-v1-5/src/interfaces/IERC20.sol';
import {IGhoVariableDebtTokenTransferHook} from 'aave-stk-v1-5/src/interfaces/IGhoVariableDebtTokenTransferHook.sol';
import {GhoOracle} from '../facilitators/aave/oracle/GhoOracle.sol';
import {AdminUpgradeabilityProxy} from '@aave/core-v3/contracts/dependencies/openzeppelin/upgradeability/AdminUpgradeabilityProxy.sol';
import {Errors} from '@aave/core-v3/contracts/protocol/libraries/helpers/Errors.sol';

contract TestEnv is Test {
address constant faucet = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
Expand All @@ -48,6 +50,7 @@ contract TestEnv is Test {
MockedPool POOL;
MockedAclManager ACL_MANAGER;
MockedProvider PROVIDER;
MockedConfigurator CONFIGURATOR;
WETH9Mock WETH;
GhoVariableDebtToken GHO_DEBT_TOKEN;
GhoAToken GHO_ATOKEN;
Expand All @@ -61,6 +64,7 @@ contract TestEnv is Test {
ACL_MANAGER = new MockedAclManager();
PROVIDER = new MockedProvider(address(ACL_MANAGER));
POOL = new MockedPool(IPoolAddressesProvider(address(PROVIDER)));
CONFIGURATOR = new MockedConfigurator(IPool(POOL));
GHO_ORACLE = new GhoOracle();
GHO_TOKEN = new GhoToken();
AAVE_TOKEN = new TestnetERC20('AAVE', 'AAVE', 18, faucet);
Expand Down
75 changes: 75 additions & 0 deletions src/contracts/foundry-test/TestGhoManager.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';

import './TestEnv.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {Errors} from '@aave/core-v3/contracts/protocol/libraries/helpers/Errors.sol';
import {DebtUtils} from './libraries/DebtUtils.sol';
import {GhoActions} from './libraries/GhoActions.sol';
import {GhoManager} from '../facilitators/aave/misc/GhoManager.sol';

contract TestGhoManager is Test, GhoActions {
GhoManager ghoManager;
address public alice;

event DiscountRateStrategyUpdated(
address indexed oldDiscountRateStrategy,
address indexed newDiscountRateStrategy
);

event ReserveInterestRateStrategyChanged(
address indexed asset,
address oldStrategy,
address newStrategy
);

function setUp() public {
ghoManager = new GhoManager();
alice = users[0];
}

function testUpdateDiscountRateStrategy() public {
vm.expectEmit(true, true, false, true, address(GHO_DEBT_TOKEN));
emit DiscountRateStrategyUpdated(
address(GHO_DISCOUNT_STRATEGY),
address(GHO_DISCOUNT_STRATEGY)
);
ghoManager.updateDiscountRateStrategy(address(GHO_DEBT_TOKEN), address(GHO_DISCOUNT_STRATEGY));
}

function testRevertUnauthorizedUpdateDiscountRateStrategy() public {
vm.prank(alice);
vm.expectRevert();
ghoManager.updateDiscountRateStrategy(address(GHO_DEBT_TOKEN), address(GHO_DISCOUNT_STRATEGY));
}

function testSetReserveInterestRateStrategy() public {
address oldInterestStrategy = POOL.getReserveInterestRateStrategyAddress(address(GHO_TOKEN));
GhoInterestRateStrategy newInterestStrategy = new GhoInterestRateStrategy(2e25);
vm.expectEmit(true, true, true, true, address(CONFIGURATOR));
emit ReserveInterestRateStrategyChanged(
address(GHO_TOKEN),
oldInterestStrategy,
address(newInterestStrategy)
);
ghoManager.setReserveInterestRateStrategyAddress(
address(CONFIGURATOR),
address(GHO_TOKEN),
address(newInterestStrategy)
);
}

function testRevertUnauthorizedSetReserveInterestRateStrategy() public {
address oldInterestStrategy = POOL.getReserveInterestRateStrategyAddress(address(GHO_TOKEN));
GhoInterestRateStrategy newInterestStrategy = new GhoInterestRateStrategy(2e25);
vm.prank(alice);
vm.expectRevert();
ghoManager.setReserveInterestRateStrategyAddress(
address(CONFIGURATOR),
address(GHO_TOKEN),
address(newInterestStrategy)
);
}
}
29 changes: 29 additions & 0 deletions src/contracts/foundry-test/mocks/MockedConfigurator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';

contract MockedConfigurator {
IPool internal _pool;

event ReserveInterestRateStrategyChanged(
address indexed asset,
address oldStrategy,
address newStrategy
);

constructor(IPool pool) {
_pool = pool;
}

function setReserveInterestRateStrategyAddress(
address asset,
address newRateStrategyAddress
) external {
DataTypes.ReserveData memory reserve = _pool.getReserveData(asset);
address oldRateStrategyAddress = reserve.interestRateStrategyAddress;
_pool.setReserveInterestRateStrategyAddress(asset, newRateStrategyAddress);
emit ReserveInterestRateStrategyChanged(asset, oldRateStrategyAddress, newRateStrategyAddress);
}
}
13 changes: 13 additions & 0 deletions src/contracts/foundry-test/mocks/MockedPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {Helpers} from '@aave/core-v3/contracts/protocol/libraries/helpers/Helper
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
import {StableDebtToken} from '@aave/core-v3/contracts/protocol/tokenization/StableDebtToken.sol';
import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/ERC20.sol';
import {Errors} from '@aave/core-v3/contracts/protocol/libraries/helpers/Errors.sol';

/**
* @dev MockedPool removes assets and users validations from Pool contract.
Expand Down Expand Up @@ -96,4 +97,16 @@ contract MockedPool is Pool {

return paybackAmount;
}

function setReserveInterestRateStrategyAddress(
address asset,
address rateStrategyAddress
) external override {
require(asset != address(0), Errors.ZERO_ADDRESS_NOT_VALID);
_reserves[asset].interestRateStrategyAddress = rateStrategyAddress;
}

function getReserveInterestRateStrategyAddress(address asset) external returns (address) {
return _reserves[asset].interestRateStrategyAddress;
}
}