Skip to content

Commit

Permalink
test: add missing tests from QA regression
Browse files Browse the repository at this point in the history
  • Loading branch information
nmagariang authored and jmendiola222 committed Dec 4, 2024
1 parent 4d73f57 commit bc2be32
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 10 deletions.
16 changes: 15 additions & 1 deletion test/BackersManagerRootstockCollective.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ contract BackersManagerRootstockCollectiveTest is BaseTest {
assertEq(address(backersManager).balance, 0);
}

/**
* SCENARIO: notifyRewardAmount is called with zero value - should not revert and rewards don't change
*/
function test_NotifyRewardAmountZeroValue() public {
// GIVEN a BackersManager contract
// WHEN 0 ether in rewardToken and 0 coinbase are added
// THEN it does not revert and rewards don't change
backersManager.notifyRewardAmount(0 ether);
// THEN reward for reward token is 0 ether
assertEq(backersManager.rewardsERC20(), 0 ether);
// THEN Coinbase reward is 0
assertEq(backersManager.rewardsCoinbase(), 0);
}

/**
* SCENARIO: notifyRewardAmount reverts when there are no active gauges
*/
Expand Down Expand Up @@ -516,7 +530,7 @@ contract BackersManagerRootstockCollectiveTest is BaseTest {
}

/**
* SCENARIO: should revert is distribution window did not start
* SCENARIO: should revert if distribution window did not start
*/
function test_RevertOnlyInDistributionWindow() public {
// GIVEN a BackerManager contract
Expand Down
17 changes: 14 additions & 3 deletions test/BuilderRegistryRootstockCollective.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,31 @@ contract BuilderRegistryRootstockCollectiveTest is BaseTest {
// GIVEN a new builder
address _newBuilder = makeAddr("newBuilder");
address _newRewardReceiver = makeAddr("newRewardReceiver");
uint64 _backerRewardPercentage = 0.1 ether;
// AND a kycApprover
vm.prank(kycApprover);
// WHEN calls activateBuilder
// THEN BuilderActivated event is emitted
vm.expectEmit();
emit BuilderActivated(_newBuilder, _newRewardReceiver, 0.1 ether);
backersManager.activateBuilder(_newBuilder, _newRewardReceiver, 0.1 ether);
emit BuilderActivated(_newBuilder, _newRewardReceiver, _backerRewardPercentage);
backersManager.activateBuilder(_newBuilder, _newRewardReceiver, _backerRewardPercentage);

// THEN builder is kycApproved
(, bool _kycApproved,,,,,) = backersManager.builderState(_newBuilder);
(, bool _kycApproved, bool _communityApproved,,,,) = backersManager.builderState(_newBuilder);
assertEq(_kycApproved, true);
// THEN builder is not community approved
assertEq(_communityApproved, false);

// THEN builder rewards receiver is set
assertEq(backersManager.builderRewardReceiver(_newBuilder), _newRewardReceiver);

(uint64 _previous, uint64 _next, uint128 _cooldownEndTime) = backersManager.backerRewardPercentage(_newBuilder);
// THEN previous backer reward percentage is 10%
assertEq(_previous, _backerRewardPercentage);
// THEN next backer reward percentage is 10%
assertEq(_next, _backerRewardPercentage);
// THEN backer reward percentage cooldown end time is the current block time
assertEq(_cooldownEndTime, block.timestamp);
}

/**
Expand Down
72 changes: 72 additions & 0 deletions test/GaugeRootstockCollective.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,78 @@ contract GaugeRootstockCollectiveTest is BaseTest {
assertEq(builder.balance, 70 ether);
}

/**
* SCENARIO: builder claims his rewards at any time during the cycle by asset receiving the total rewards of the
* asset claimed.
*/
function test_ClaimBuilderRewardsRewardToken() public {
// GIVEN a builder with 30% of reward percentage for backers
vm.startPrank(builder);
backersManager.setBackerRewardPercentage(0.3 ether);
skip(rewardPercentageCooldown);
// AND alice allocates to gauge
vm.startPrank(alice);
backersManager.allocate(gauge, 1 ether);

// AND 100 rewardToken and 100 coinbase are distributed
_distribute(100 ether, 100 ether);

// THEN builderRewards is 70 ether in rewardToken and 70 ether in coinbase
assertEq(gauge.builderRewards(address(rewardToken)), 70 ether);
assertEq(gauge.builderRewards(UtilsLib._COINBASE_ADDRESS), 70 ether);

// AND another cycle finishes without a new distribution
_skipAndStartNewCycle();

// WHEN builder claims rewards by rewardToken
vm.startPrank(builder);
gauge.claimBuilderReward(address(rewardToken));
// THEN builder rewardToken balance is 70 ether
assertEq(rewardToken.balanceOf(builder), 70 ether);
// THEN builderRewards in rewardToken is 0
assertEq(gauge.builderRewards(address(rewardToken)), 0 ether);
// THEN builder coinbase balance is 0 ether
assertEq(builder.balance, 0 ether);
// THEN builderRewards in coinbase is 70 ether
assertEq(gauge.builderRewards(UtilsLib._COINBASE_ADDRESS), 70 ether);
}

/**
* SCENARIO: builder claims his rewards at any time during the cycle by asset receiving the total rewards of the
* asset claimed.
*/
function test_ClaimBuilderRewardsCoinbase() public {
// GIVEN a builder with 30% of reward percentage for backers
vm.startPrank(builder);
backersManager.setBackerRewardPercentage(0.3 ether);
skip(rewardPercentageCooldown);
// AND alice allocates to gauge
vm.startPrank(alice);
backersManager.allocate(gauge, 1 ether);

// AND 100 rewardToken and 100 coinbase are distributed
_distribute(100 ether, 100 ether);

// THEN builderRewards is 70 ether in rewardToken and 70 ether in coinbase
assertEq(gauge.builderRewards(address(rewardToken)), 70 ether);
assertEq(gauge.builderRewards(UtilsLib._COINBASE_ADDRESS), 70 ether);

// AND another cycle finishes without a new distribution
_skipAndStartNewCycle();

// WHEN builder claims rewards by Coinbase
vm.startPrank(builder);
gauge.claimBuilderReward(UtilsLib._COINBASE_ADDRESS);
// THEN builder rewardToken balance is 70 ether
assertEq(rewardToken.balanceOf(builder), 0 ether);
// THEN builderRewards in rewardToken is 70 ether
assertEq(gauge.builderRewards(address(rewardToken)), 70 ether);
// THEN builder coinbase balance is 70 ether
assertEq(builder.balance, 70 ether);
// THEN builderRewards in coinbase is 0 ether
assertEq(gauge.builderRewards(UtilsLib._COINBASE_ADDRESS), 0 ether);
}

/**
* SCENARIO: reward receiver claims his rewards at any time during the cycle receiving the total amount of rewards.
*/
Expand Down
13 changes: 7 additions & 6 deletions test/HaltedBuilderBehavior.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,18 @@ abstract contract HaltedBuilderBehavior is BaseTest {
// AND half cycle pass
_skipRemainingCycleFraction(2);
// AND alice removes allocations
vm.prank(alice);
backersManager.allocate(gauge, 0 ether);

// WHEN builder is halted
_haltGauge();

// // THEN gauge rewardShares is 30240000 ether = 100 * 1/2 WEEK
// assertEq(gauge.rewardShares(), 30_240_000 ether);
// // THEN alice total allocation is 6
// assertEq(backersManager.backerTotalAllocation(alice), 6 ether);
// // THEN totalPotentialReward is 8467200 ether = 14 * 1 WEEK
// assertEq(backersManager.totalPotentialReward(), 8_467_200 ether);
// THEN gauge rewardShares is 30240000 ether = 100 * 1/2 WEEK
assertEq(gauge.rewardShares(), 30_240_000 ether);
// THEN alice total allocation is 6
assertEq(backersManager.backerTotalAllocation(alice), 6 ether);
// THEN totalPotentialReward is 8467200 ether = 14 * 1 WEEK
assertEq(backersManager.totalPotentialReward(), 8_467_200 ether);
}

/**
Expand Down
Loading

0 comments on commit bc2be32

Please sign in to comment.