Skip to content

Commit

Permalink
Remove type funtion calls from tests (#8)
Browse files Browse the repository at this point in the history
* SomeToken: replaced type calls with resulting values.

* UniswapV2Swap: replaced type calls with resulting values.

* LendingPool: replaced type calls with resulting values.

* AaveLendingPool: replaced type calls with resulting values.

* LidoStaking: replaced type calls with resulting values.
  • Loading branch information
mariaKt authored Aug 20, 2024
1 parent 9f58a58 commit 3a8eb32
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
8 changes: 5 additions & 3 deletions test/examples/lending/AaveLendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ contract AaveLendingPool {

ILendingPoolAddressesProvider public addressesProvider;

uint256 internal UINT256_MAX = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

/* LendingPoolCore variables*/
mapping(address => ReserveData) internal reserves;
mapping(address => mapping(address => UserReserveData))
Expand Down Expand Up @@ -298,13 +300,13 @@ contract AaveLendingPool {
);

require(
_amount != type(uint256).max || msg.sender == _onBehalfOf,
_amount != UINT256_MAX || msg.sender == _onBehalfOf,
"To repay on behalf of an user an explicit amount to repay is needed."
);

vars.paybackAmount = vars.compoundedBorrowBalance + vars.originationFee;

if (_amount != type(uint256).max && _amount < vars.paybackAmount) {
if (_amount != UINT256_MAX && _amount < vars.paybackAmount) {
vars.paybackAmount = _amount;
}

Expand Down Expand Up @@ -1173,7 +1175,7 @@ contract AaveLendingPool {
uint256 totalFeesETH,
uint256 liquidationThreshold
) internal returns (uint256) {
if (borrowBalanceETH == 0) return type(uint256).max;
if (borrowBalanceETH == 0) return UINT256_MAX;

return
((collateralBalanceETH * liquidationThreshold) / 100) /
Expand Down
4 changes: 3 additions & 1 deletion test/examples/lending/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ contract LendingPool {
bool supported;
}

uint256 internal UINT256_MAX = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

uint256 internal MAX_PROTOCOL_FEE = 0.5e4; // 5%
uint256 public PRECISION = 1e18; // 18 decimals precision
uint256 public BPS = 1e5; // 5 decimals precision
Expand Down Expand Up @@ -163,7 +165,7 @@ contract LendingPool {
_accrueInterest(token);
uint256 userBorrowShare = userShares[msg.sender][token].borrow;
uint256 shares = _toShares(vaults[token].totalBorrow, amount, true);
if (amount == type(uint256).max || shares > userBorrowShare) {
if (amount == UINT256_MAX || shares > userBorrowShare) {
shares = userBorrowShare;
amount = _toAmount(vaults[token].totalBorrow, shares, true);
}
Expand Down
2 changes: 1 addition & 1 deletion test/examples/staking/LidoStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract Lido{

/*stETH variables start*/
address internal INITIAL_TOKEN_HOLDER = address(0xdead);
uint256 internal INFINITE_ALLOWANCE = type(uint256).max;
uint256 internal INFINITE_ALLOWANCE = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
mapping (address => uint256) private shares;
mapping (address => mapping (address => uint256)) private allowances;
uint256 internal TOTAL_SHARES_POSITION;
Expand Down
16 changes: 12 additions & 4 deletions test/examples/swaps/UniswapV2Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ contract UniswapV2Router02 {

contract UniswapV2Pair{

uint112 internal UINT112_MAX = 0xffffffffffffffffffffffffffff;

address public token0;
address public token1;

Expand Down Expand Up @@ -300,7 +302,7 @@ contract UniswapV2Pair{
}

function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private {
require(balance0 <= type(uint112).max && balance1 <= type(uint112).max, "UniswapV2: OVERFLOW");
require(balance0 <= UINT112_MAX && balance1 <= UINT112_MAX, "UniswapV2: OVERFLOW");
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
Expand All @@ -316,6 +318,8 @@ contract UniswapV2Pair{

contract WETHMock {

uint256 internal UINT256_MAX = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;

Expand Down Expand Up @@ -362,7 +366,7 @@ contract WETHMock {
function transferFrom(address from, address to, uint256 value) external returns (bool) {
if (from != msg.sender) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
if (allowed != UINT256_MAX) {
require(allowed >= value, "WETH: request exceeds allowance");
uint256 reduced = allowed - value;
allowance[from][msg.sender] = reduced;
Expand Down Expand Up @@ -393,6 +397,8 @@ contract WETHMock {

contract DAIMock {

uint internal UINT_MAX = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

uint256 public totalSupply;

mapping (address => uint) public balanceOf;
Expand Down Expand Up @@ -437,7 +443,7 @@ contract DAIMock {
public returns (bool)
{
require(balanceOf[src] >= wad, "Dai/insufficient-balance");
if (src != msg.sender && allowance[src][msg.sender] != type(uint).max) {
if (src != msg.sender && allowance[src][msg.sender] != UINT_MAX) {
require(allowance[src][msg.sender] >= wad, "Dai/insufficient-allowance");
allowance[src][msg.sender] = allowance[src][msg.sender] - wad;
}
Expand All @@ -455,6 +461,8 @@ contract DAIMock {
}

contract USDCMock {
uint256 internal UINT256_MAX = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

uint256 private _totalSupply;

mapping(address account => uint256) private _balances;
Expand Down Expand Up @@ -537,7 +545,7 @@ contract USDCMock {

function _spendAllowance(address owner, address spender, uint256 value) internal {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance != UINT256_MAX) {
require(currentAllowance >= value, "USDC: insufficient allowance");
_approve(owner, spender, currentAllowance - value, false);

Expand Down
4 changes: 3 additions & 1 deletion test/examples/tokens/SomeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pragma solidity ^0.8.20;

contract SomeToken {

uint256 internal UINT256_MAX = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

uint256 private _totalSupply;

string private _name;
Expand Down Expand Up @@ -113,7 +115,7 @@ contract SomeToken {

function _spendAllowance(address owner, address spender, uint256 value) internal {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance != UINT256_MAX) {
require(currentAllowance >= value, "SomeToken: insufficient allowance");
_approve(owner, spender, currentAllowance - value, false);

Expand Down

0 comments on commit 3a8eb32

Please sign in to comment.