Skip to content

Commit

Permalink
✅ Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax authored and MerlinEgalite committed Jun 28, 2022
1 parent 46d1258 commit 72b176d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions test-foundry/aave-v3/helpers/User.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ contract User is Test {
morpho.setDefaultMaxGasForMatching(_maxGasForMatching);
}

function claimRewards(address[] calldata _assets, bool _toSwap)
function claimRewards(address[] calldata _assets, bool _tradeForMorphoToken)
external
returns (address[] memory rewardTokens, uint256[] memory claimedAmounts)
{
return morpho.claimRewards(_assets, _toSwap);
return morpho.claimRewards(_assets, _tradeForMorphoToken);
}

function setPauseStatus(address _marketAddress, bool _newStatus) external {
Expand Down
20 changes: 13 additions & 7 deletions test-foundry/compound/TestRewards.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ contract TestRewards is TestSetup {
supplier2.supply(cDai, toSupply);

hevm.roll(block.number + 1_000);
supplier1.claimRewards(cTokens, false);
uint256 claimedAmount = supplier1.claimRewards(cTokens, false);

index = comptroller.compSupplyState(cDai).index;

uint256 expectedClaimed = (onPool * (index - userIndex)) / 1e36;
uint256 balanceAfter = supplier1.balanceOf(comp);
uint256 expectedNewBalance = expectedClaimed + balanceBefore;

assertEq(claimedAmount, expectedClaimed, "unexpected claimed amount");
testEquality(balanceAfter, expectedNewBalance, "balance after wrong");
}

Expand All @@ -58,10 +59,11 @@ contract TestRewards is TestSetup {
hevm.roll(block.number + 1_000);
unclaimedRewards = lens.getUserUnclaimedRewards(cTokens, address(supplier1));

supplier1.claimRewards(cTokens, false);
uint256 claimedAmount = supplier1.claimRewards(cTokens, false);
index = comptroller.compSupplyState(cDai).index;

uint256 expectedClaimed = (onPool * (index - userIndex)) / 1e36;
assertEq(claimedAmount, expectedClaimed, "unexpected claimed amount");
testEquality(unclaimedRewards, expectedClaimed);
}

Expand All @@ -84,13 +86,14 @@ contract TestRewards is TestSetup {
assertEq(unclaimedRewards, 0, "unclaimed rewards should be 0");

hevm.roll(block.number + 1_000);
supplier1.claimRewards(cTokens, false);
uint256 claimedAmount = supplier1.claimRewards(cTokens, false);

index = comptroller.compBorrowState(cUsdc).index;

uint256 expectedClaimed = (onPool * (index - userIndex)) / 1e36;
uint256 balanceAfter = supplier1.balanceOf(comp);

assertEq(claimedAmount, expectedClaimed, "unexpected claimed amount");
testEquality(balanceAfter, expectedClaimed, "balance after wrong");
}

Expand All @@ -115,10 +118,11 @@ contract TestRewards is TestSetup {

unclaimedRewards = lens.getUserUnclaimedRewards(cTokens, address(supplier1));

supplier1.claimRewards(cTokens, false);
uint256 claimedAmount = supplier1.claimRewards(cTokens, false);
index = comptroller.compBorrowState(cUsdc).index;

uint256 expectedClaimed = (onPool * (index - userIndex)) / 1e36;
assertEq(claimedAmount, expectedClaimed, "unexpected claimed amount");
testEquality(unclaimedRewards, expectedClaimed);
}

Expand Down Expand Up @@ -212,8 +216,7 @@ contract TestRewards is TestSetup {
assertEq(allUnclaimedRewards, 0);
}

// TODO: investigate why this test fails.
function _testUsersShouldClaimRewardsIndependently() public {
function testUsersShouldClaimRewardsIndependently() public {
interactWithCompound();
interactWithMorpho();

Expand Down Expand Up @@ -264,7 +267,9 @@ contract TestRewards is TestSetup {

hevm.prank(address(morpho));
uint256 unclaimedRewards1 = rewardsManager.claimRewards(tokensInArray, address(supplier1));
hevm.prank(address(morpho));
uint256 unclaimedRewards2 = rewardsManager.claimRewards(tokensInArray, address(supplier2));
hevm.prank(address(morpho));
uint256 unclaimedRewards3 = rewardsManager.claimRewards(tokensInArray, address(supplier3));

assertEq(unclaimedRewards1, 0);
Expand Down Expand Up @@ -315,14 +320,15 @@ contract TestRewards is TestSetup {
cTokens[0] = cDai;

hevm.roll(block.number + 1_000);
supplier1.claimRewards(cTokens, true);
uint256 claimedAmount = supplier1.claimRewards(cTokens, true);

uint256 index = comptroller.compSupplyState(cDai).index;
uint256 expectedClaimed = (onPool * (index - userIndex)) / 1e36;
uint256 expectedMorphoTokens = (expectedClaimed * 11_000) / 10_000; // 10% bonus with a dumb oracle 1:1 exchange from COMP to MORPHO.

uint256 morphoBalance = supplier1.balanceOf(address(morphoToken));
uint256 rewardBalanceAfter = supplier1.balanceOf(comp);
assertEq(claimedAmount, expectedClaimed);
testEquality(morphoBalance, expectedMorphoTokens);
testEquality(rewardBalanceBefore, rewardBalanceAfter);
}
Expand Down

0 comments on commit 72b176d

Please sign in to comment.