From 31765c578c51d2c84cc271ae1d044fac320a2bd5 Mon Sep 17 00:00:00 2001 From: Ana Julia Date: Sun, 7 Jul 2024 18:46:59 -0300 Subject: [PATCH] testFork_FirstDepositorsAlwaysReceiveMoreRewards --- test/Staking.integration.t.sol | 66 +++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/test/Staking.integration.t.sol b/test/Staking.integration.t.sol index 4ba1f88..bc0e077 100644 --- a/test/Staking.integration.t.sol +++ b/test/Staking.integration.t.sol @@ -118,7 +118,7 @@ contract StakingIntegrationTest is Test { IERC20(STAKING_TOKEN).approve(address(staking), staked); staking.stake(staked); - uint256 jump = 86.81 days; + uint256 jump = 86 days; _jumpAhead(jump); @@ -130,6 +130,70 @@ contract StakingIntegrationTest is Test { assertApproxEqAbs(APR, 20e18, 1e18); } + function testFork_FirstDepositorsAlwaysReceiveMoreRewards() public { + uint256 depositorsCount = 400; + + _setRewardAndFund(); + + uint256 jumpBetweenStakes = 1 hours; + + uint256[] memory timeStaked = new uint256[](depositorsCount); + uint256 previousDepositorShares; + + uint256 timestampFirstStake = vm.getBlockTimestamp(); + + for (uint256 i = 1; i <= depositorsCount; i++) { + address participant = address(uint160(i)); + + deal(STAKING_TOKEN, participant, MIN_STAKE); + + vm.prank(CONTRACT_OWNER); + staking.setKeyper(participant, true); + + vm.startPrank(participant); + IERC20(STAKING_TOKEN).approve(address(staking), MIN_STAKE); + staking.stake(MIN_STAKE); + vm.stopPrank(); + + uint256 shares = staking.balanceOf(participant); + if (i > 1) { + assertGt(previousDepositorShares, shares); + } + previousDepositorShares = shares; + + timeStaked[i - 1] = vm.getBlockTimestamp(); + + _jumpAhead(jumpBetweenStakes); + } + + uint256 previousRewardsReceived; + + // collect rewards and calculate rewards + for (uint256 i = 1; i <= depositorsCount; i++) { + address participant = address(uint160(i)); + + uint256 expectedTimestamp = timeStaked[i - 1] + 365 days; + // jump the diferrence between expected and actual time + _jumpAhead(expectedTimestamp - vm.getBlockTimestamp()); + + vm.startPrank(participant); + uint256 rewardsReceived = staking.claimRewards(0); + + vm.stopPrank(); + + if (i > 1) { + assertGt(rewardsReceived, previousRewardsReceived); + } + + _jumpAhead(jumpBetweenStakes); + + uint256 assetsAfter = staking.convertToAssets( + staking.balanceOf(participant) + ); + assertApproxEqAbs(assetsAfter, MIN_STAKE, 2); + } + } + function testForkFuzz_MultipleDepositorsStakeMinStakeSameBlock( uint256 _depositorsCount, uint256 _jump