Skip to content

Commit

Permalink
test: initialize constructor unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-man committed Sep 4, 2024
1 parent 750eb61 commit 038e3be
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/TestGhoBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {MockUpgradeable} from './mocks/MockUpgradeable.sol';
import {PriceOracle} from '@aave/core-v3/contracts/mocks/oracle/PriceOracle.sol';
import {TestnetERC20} from '@aave/periphery-v3/contracts/mocks/testnet-helpers/TestnetERC20.sol';
import {WETH9Mock} from '@aave/periphery-v3/contracts/mocks/WETH9Mock.sol';
import {MockRedemption} from './mocks/MockRedemption.sol';

// interfaces
import {IAaveIncentivesController} from '@aave/core-v3/contracts/interfaces/IAaveIncentivesController.sol';
Expand Down Expand Up @@ -78,6 +79,7 @@ import {FixedFeeStrategy} from '../contracts/facilitators/gsm/feeStrategy/FixedF
import {SampleLiquidator} from '../contracts/facilitators/gsm/misc/SampleLiquidator.sol';
import {SampleSwapFreezer} from '../contracts/facilitators/gsm/misc/SampleSwapFreezer.sol';
import {GsmRegistry} from '../contracts/facilitators/gsm/misc/GsmRegistry.sol';
import {GsmConverter} from '../contracts/facilitators/gsm/converter/GsmConverter.sol';

contract TestGhoBase is Test, Constants, Events {
using WadRayMath for uint256;
Expand All @@ -102,11 +104,13 @@ contract TestGhoBase is Test, Constants, Events {
TestnetERC20 AAVE_TOKEN;
IStakedAaveV3 STK_TOKEN;
TestnetERC20 USDC_TOKEN;
TestnetERC20 BUIDL_TOKEN;
MockERC4626 USDC_4626_TOKEN;
MockPool POOL;
MockAclManager ACL_MANAGER;
MockAddressesProvider PROVIDER;
MockConfigurator CONFIGURATOR;
MockRedemption REDEMPTION;
PriceOracle PRICE_ORACLE;
WETH9Mock WETH;
GhoVariableDebtToken GHO_DEBT_TOKEN;
Expand Down Expand Up @@ -174,6 +178,12 @@ contract TestGhoBase is Test, Constants, Events {
);
STK_TOKEN = IStakedAaveV3(address(stkAaveProxy));
USDC_TOKEN = new TestnetERC20('USD Coin', 'USDC', 6, FAUCET);
BUIDL_TOKEN = new TestnetERC20(
'BlackRock USD Institutional Digital Liquidity Fund',
'BUIDL',
6,
FAUCET
);
USDC_4626_TOKEN = new MockERC4626('USD Coin 4626', '4626', address(USDC_TOKEN));
address ghoTokenAddress = address(GHO_TOKEN);
address discountToken = address(STK_TOKEN);
Expand Down Expand Up @@ -306,6 +316,8 @@ contract TestGhoBase is Test, Constants, Events {
controlledFacilitators[1] = address(GHO_GSM);
vm.prank(SHORT_EXECUTOR);
GHO_STEWARD_V2.setControlledFacilitator(controlledFacilitators, true);

REDEMPTION = new MockRedemption(address(BUIDL_TOKEN), address(USDC_TOKEN));
}

function ghoFaucet(address to, uint256 amount) public {
Expand Down
38 changes: 38 additions & 0 deletions src/test/TestGsmConverter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import './TestGhoBase.t.sol';

contract TestGsmConverter is TestGhoBase {
// using PercentageMath for uint256;
// using PercentageMath for uint128;

function setUp() public {
// (gsmSignerAddr, gsmSignerKey) = makeAddrAndKey('gsmSigner');
}

function testConstructor() public {
GsmConverter gsmConverter = new GsmConverter(
address(GHO_GSM),
address(REDEMPTION),
address(BUIDL_TOKEN),
address(USDC_TOKEN)
);
assertEq(gsmConverter.GSM(), address(GHO_GSM), 'Unexpected GSM address');
assertEq(
gsmConverter.REDEMPTION_CONTRACT(),
address(REDEMPTION),
'Unexpected redemption contract address'
);
assertEq(
gsmConverter.REDEEMABLE_ASSET(),
address(BUIDL_TOKEN),
'Unexpected redeemable asset address'
);
assertEq(
gsmConverter.REDEEMED_ASSET(),
address(USDC_TOKEN),
'Unexpected redeemed asset address'
);
}
}
63 changes: 63 additions & 0 deletions src/test/mocks/MockRedemption.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2024 Circle Internet Financial, LTD. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pragma solidity ^0.8.10;

import {IRedemption} from '../../contracts/facilitators/gsm/dependencies/circle/IRedemption.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

/**
* @title MockRedemption
* @dev Asset token is ERC20-compatible
* @dev Liquidity token is ERC20-compatible
*/
contract MockRedemption is IRedemption {
using SafeERC20 for IERC20;

/**
* @inheritdoc IRedemption
*/
address public immutable asset;

/**
* @inheritdoc IRedemption
*/
address public immutable liquidity;

/**
* @param _asset Address of asset token
* @param _liquidity Address of liquidity token
*/
constructor(address _asset, address _liquidity) {
asset = _asset;
liquidity = _liquidity;
}

function test_coverage_ignore() public virtual {
// Intentionally left blank.
// Excludes contract from coverage.
}

/**
* @inheritdoc IRedemption
*/
function redeem(uint256 amount) external {
// Intentionally left blank.
}
}

0 comments on commit 038e3be

Please sign in to comment.