Skip to content

Commit

Permalink
tests: add decimals tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Oct 29, 2024
1 parent c85bfb8 commit b05e00c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/fuzz/MultiBlockHarvester.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "../utils/FunctionUtils.sol";

import "contracts/savings/Savings.sol";
import "../mock/MockTokenPermit.sol";
import "../mock/MockScaleDecimals.sol";
import "contracts/helpers/MultiBlockHarvester.sol";

import "contracts/transmuter/Storage.sol";
Expand Down Expand Up @@ -330,6 +331,22 @@ contract MultiBlockHarvestertTest is Fixture, FunctionUtils {
assertEq(currentTargetExposure, targetExposure + 1);
}

function test_ScaleDecimals() public {
MockScaleDecimals decimals = new MockScaleDecimals(1e8, accessControlManager, agToken, transmuter);

uint256 amount = decimals.scaleDecimals(18, 20, 1e18, true);
assertEq(amount, 1e20);

amount = decimals.scaleDecimals(20, 18, 1e18, false);
assertEq(amount, 1e20);

amount = decimals.scaleDecimals(18, 20, 1e18, false);
assertEq(amount, 1e16);

amount = decimals.scaleDecimals(20, 18, 1e18, true);
assertEq(amount, 1e16);
}

function test_harvest_IncreaseExposureXEVT(uint256 amount) external {
amount = 7022;
_loadReserve(EURC, amount);
Expand Down
24 changes: 24 additions & 0 deletions test/mock/MockScaleDecimals.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.19;

import "contracts/helpers/BaseHarvester.sol";

contract MockScaleDecimals is BaseHarvester {
constructor(
uint96 initialMaxSlippage,
IAccessControlManager definitiveAccessControlManager,
IAgToken definitiveAgToken,
ITransmuter definitiveTransmuter
) BaseHarvester(initialMaxSlippage, definitiveAccessControlManager, definitiveAgToken, definitiveTransmuter) {}

function harvest(address yieldBearingAsset, uint256 scale, bytes calldata extraData) external override {}

function scaleDecimals(
uint256 decimalsTokenIn,
uint256 decimalsTokenOut,
uint256 amountIn,
bool assetIn
) external pure returns (uint256) {
return _scaleAmountBasedOnDecimals(decimalsTokenIn, decimalsTokenOut, amountIn, assetIn);
}
}

0 comments on commit b05e00c

Please sign in to comment.