ERC4626.t.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "erc4626-tests/ERC4626.test.sol";
  4. import {SafeCast} from "../../../../contracts/utils/math/SafeCast.sol";
  5. import {ERC20Mock} from "../../../../contracts/mocks/ERC20Mock.sol";
  6. import {ERC4626Mock} from "../../../../contracts/mocks/ERC4626Mock.sol";
  7. contract ERC4626StdTest is ERC4626Test {
  8. function setUp() public override {
  9. _underlying_ = address(new ERC20Mock());
  10. _vault_ = address(new ERC4626Mock(_underlying_));
  11. _delta_ = 0;
  12. _vaultMayBeEmpty = false;
  13. _unlimitedAmount = true;
  14. }
  15. // solhint-disable-next-line func-name-mixedcase
  16. function test_RT_mint_withdraw(ERC4626Test.Init memory init, uint256 shares) public override {
  17. // There is an edge case where we currently behave different than the property tests,
  18. // when all assets are lost to negative yield.
  19. // Sum all initially deposited assets.
  20. int256 initAssets = 0;
  21. for (uint256 i = 0; i < init.share.length; i++) {
  22. vm.assume(init.share[i] <= uint256(type(int256).max - initAssets));
  23. initAssets += SafeCast.toInt256(init.share[i]);
  24. }
  25. // Reject tests where the yield loses all assets from the vault.
  26. vm.assume(init.yield > -initAssets);
  27. super.test_RT_mint_withdraw(init, shares);
  28. }
  29. }