Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Update harvest tests:
Browse files Browse the repository at this point in the history
- Use defined acceptable Comet rounding error margin variable
- Accommodate swap quote rounding
  • Loading branch information
kphed committed Jan 15, 2024
1 parent 3157ddf commit d7b6e81
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions test/BrrETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ contract BrrETHTest is Helper {
{
uint256 rewardFee = vault.rewardFee();
uint256 rewardFeeShare = amount.mulDiv(rewardFee, _FEE_BASE);

// NOTE: The quote-fetching method rounds down, so this may be off by 1.
// Using `mulDivUp` would not result in the exact value either.
uint256 preFeeAmount = amount.mulDiv(_FEE_BASE, _SWAP_FEE_DEDUCTED);

protocolFeeReceiverShare = rewardFeeShare / 2;
feeDistributorShare = rewardFeeShare - protocolFeeReceiverShare;
feeDistributorSwapFeeShare =
Expand Down Expand Up @@ -394,7 +398,7 @@ contract BrrETHTest is Helper {
uint256 feeDistributorSwapFeeShare
) = _calculateFees(quote);
quote -= protocolFeeReceiverShare + feeDistributorShare;
uint256 newAssets = quote - 1;
uint256 newAssets = quote - _COMET_ROUNDING_ERROR_MARGIN;
uint256 totalAssets = vault.totalAssets();
uint256 totalSupply = vault.totalSupply();
uint256 protocolFeeReceiverBalance = _WETH.balanceOf(
Expand All @@ -412,7 +416,9 @@ contract BrrETHTest is Helper {

vault.harvest();

assertEq(totalAssets + newAssets, vault.totalAssets());
// Takes the Comet rounding error margin into account.
assertLe(totalAssets + newAssets, vault.totalAssets());

assertEq(totalSupply, vault.totalSupply());
assertEq(
protocolFeeReceiverBalance +
Expand Down Expand Up @@ -460,7 +466,7 @@ contract BrrETHTest is Helper {
uint256 feeDistributorSwapFeeShare
) = _calculateFees(quote);
quote -= protocolFeeReceiverShare + feeDistributorShare;
uint256 newAssets = quote - 5;
uint256 newAssets = quote - _COMET_ROUNDING_ERROR_MARGIN;
uint256 totalAssets = vault.totalAssets();
uint256 totalSupply = vault.totalSupply();
uint256 protocolFeeReceiverBalance = _WETH.balanceOf(
Expand All @@ -483,7 +489,10 @@ contract BrrETHTest is Helper {
assertEq(totalSupply, vault.totalSupply());

if (vault.owner() == vault.feeDistributor()) {
assertEq(
// The router's `getSwapOutput` method deducts fees and rounds down. To account for
// cases where our test calculations are off by 1, we're using `assertLe` - as long
// as the actual account balances are greater than our calculations, everything is fine.
assertLe(
protocolFeeReceiverBalance +
protocolFeeReceiverShare +
feeDistributorShare +
Expand All @@ -495,7 +504,7 @@ contract BrrETHTest is Helper {
protocolFeeReceiverBalance + protocolFeeReceiverShare,
_WETH.balanceOf(vault.owner())
);
assertEq(
assertLe(
feeDistributorBalance +
feeDistributorShare +
feeDistributorSwapFeeShare,
Expand Down

0 comments on commit d7b6e81

Please sign in to comment.