From 4e8b2fa659ba87ab916beb3eb3c8335fb1238d9f Mon Sep 17 00:00:00 2001 From: Francisco Date: Wed, 30 Nov 2022 15:44:38 -0300 Subject: [PATCH] Add additional conditions when testing ERC4626 roundtrip (#3839) --- test/token/ERC20/extensions/ERC4626.t.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/token/ERC20/extensions/ERC4626.t.sol b/test/token/ERC20/extensions/ERC4626.t.sol index 4863c14d5..0aac0d411 100644 --- a/test/token/ERC20/extensions/ERC4626.t.sol +++ b/test/token/ERC20/extensions/ERC4626.t.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.0; import "erc4626-tests/ERC4626.test.sol"; +import {SafeCast} from "../../../../contracts/utils/math/SafeCast.sol"; import {ERC20Mock} from "../../../../contracts/mocks/ERC20Mock.sol"; import {ERC4626Mock, IERC20Metadata} from "../../../../contracts/mocks/ERC4626Mock.sol"; @@ -14,4 +15,22 @@ contract ERC4626StdTest is ERC4626Test { _vaultMayBeEmpty = false; _unlimitedAmount = true; } + + // solhint-disable-next-line func-name-mixedcase + function test_RT_mint_withdraw(ERC4626Test.Init memory init, uint256 shares) public override { + // There is an edge case where we currently behave different than the property tests, + // when all assets are lost to negative yield. + + // Sum all initially deposited assets. + int256 initAssets = 0; + for (uint256 i = 0; i < init.share.length; i++) { + vm.assume(init.share[i] <= uint256(type(int256).max - initAssets)); + initAssets += SafeCast.toInt256(init.share[i]); + } + + // Reject tests where the yield loses all assets from the vault. + vm.assume(init.yield > -initAssets); + + super.test_RT_mint_withdraw(init, shares); + } }