-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
ERC4626
test coverage (#4134)
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
- Loading branch information
1 parent
788d6a1
commit dd1265c
Showing
4 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
contract ERC20ExcessDecimalsMock { | ||
function decimals() public pure returns (uint256) { | ||
return type(uint256).max; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
openzeppelin/=contracts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "erc4626-tests/ERC4626.test.sol"; | ||
import {ERC4626Test} from "erc4626-tests/ERC4626.test.sol"; | ||
|
||
import {SafeCast} from "../../../../contracts/utils/math/SafeCast.sol"; | ||
import {ERC20Mock} from "../../../../contracts/mocks/ERC20Mock.sol"; | ||
import {ERC4626Mock} from "../../../../contracts/mocks/ERC4626Mock.sol"; | ||
import {SafeCast} from "openzeppelin/utils/math/SafeCast.sol"; | ||
import {ERC20} from "openzeppelin/token/ERC20/ERC20.sol"; | ||
import {ERC4626} from "openzeppelin/token/ERC20/extensions/ERC4626.sol"; | ||
|
||
import {ERC20Mock} from "openzeppelin/mocks/ERC20Mock.sol"; | ||
import {ERC4626Mock} from "openzeppelin/mocks/ERC4626Mock.sol"; | ||
import {ERC4626OffsetMock} from "openzeppelin/mocks/token/ERC4626OffsetMock.sol"; | ||
|
||
contract ERC4626VaultOffsetMock is ERC4626OffsetMock { | ||
constructor( | ||
ERC20 underlying_, | ||
uint8 offset_ | ||
) ERC20("My Token Vault", "MTKNV") ERC4626(underlying_) ERC4626OffsetMock(offset_) {} | ||
} | ||
|
||
contract ERC4626StdTest is ERC4626Test { | ||
ERC20 private _underlying = new ERC20Mock(); | ||
|
||
function setUp() public override { | ||
_underlying_ = address(new ERC20Mock()); | ||
_underlying_ = address(_underlying); | ||
_vault_ = address(new ERC4626Mock(_underlying_)); | ||
_delta_ = 0; | ||
_vaultMayBeEmpty = true; | ||
_unlimitedAmount = true; | ||
} | ||
|
||
/** | ||
* @dev Check the case where calculated `decimals` value overflows the `uint8` type. | ||
*/ | ||
function testFuzzDecimalsOverflow(uint8 offset) public { | ||
/// @dev Remember that the `_underlying` exhibits a `decimals` value of 18. | ||
offset = uint8(bound(uint256(offset), 238, uint256(type(uint8).max))); | ||
ERC4626VaultOffsetMock erc4626VaultOffsetMock = new ERC4626VaultOffsetMock(_underlying, offset); | ||
vm.expectRevert(); | ||
erc4626VaultOffsetMock.decimals(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters