Skip to content

Commit

Permalink
test(evm): add fuzz testing for additional fees
Browse files Browse the repository at this point in the history
Just wanted to ensure that fee calculations behave as expected when
additional fees are added to boost.
  • Loading branch information
topocount committed Dec 12, 2024
1 parent 0bd6aa0 commit 376dcef
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/evm/test/BoostCore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,13 @@ contract BoostCoreTest is Test {
vm.stopPrank();
}

function testFuzzClaimIncentive_ProtocolFeeTransfer(uint256 rewardAmount) public {
function testFuzzClaimIncentive_ProtocolFeeTransfer(uint256 rewardAmount, uint64 additionalProtocolFee) public {
uint160 claimant = uint160(makeAddr("claimant"));
uint16 claimLimit = 1_000;
additionalProtocolFee = uint64(bound(additionalProtocolFee, 0, 9_000));
rewardAmount = bound(rewardAmount, 10_000, (type(uint256).max >> 15) / claimLimit);
uint256 amountToMint =
(rewardAmount + rewardAmount * boostCore.protocolFee() / boostCore.FEE_DENOMINATOR()) * claimLimit;
uint64 totalFee = uint64(boostCore.protocolFee()) + additionalProtocolFee;
uint256 amountToMint = (rewardAmount + rewardAmount * totalFee / boostCore.FEE_DENOMINATOR()) * claimLimit;
mockERC20.mint(address(this), amountToMint);
mockERC20.approve(address(budget), amountToMint);
budget.allocate(
Expand All @@ -570,7 +571,8 @@ contract BoostCoreTest is Test {
address feeReceiver = makeAddr("0xfee");
boostCore.setProtocolFeeReceiver(feeReceiver);

bytes memory createBoostCalldata = _makeValidCreateCalldataWithVariableRewardAmount(1, rewardAmount, claimLimit);
bytes memory createBoostCalldata =
_makeValidCreateCalldataWithVariableRewardAmount(1, rewardAmount, claimLimit, additionalProtocolFee);

// Create the boost
boostCore.createBoost(createBoostCalldata);
Expand All @@ -581,7 +583,7 @@ contract BoostCoreTest is Test {

// Calculate expected fee
uint256 claimAmount = incentive.reward();
uint256 protocolFeePercentage = boostCore.protocolFee();
uint256 protocolFeePercentage = boost.protocolFee;

uint256 expectedFee = (claimAmount * protocolFeePercentage) / boostCore.FEE_DENOMINATOR();

Expand Down Expand Up @@ -614,7 +616,7 @@ contract BoostCoreTest is Test {
);
}

assertGt(1_000, mockERC20.balanceOf(address(boostCore)), "unclaimedFunds In boost core");
assertEq(0, mockERC20.balanceOf(address(boostCore)), "unclaimedFunds In boost core");
}

function testClaimIncentive_ProtocolFeeTransfer() public {
Expand Down Expand Up @@ -900,7 +902,8 @@ contract BoostCoreTest is Test {
function _makeValidCreateCalldataWithVariableRewardAmount(
uint256 incentiveCount,
uint256 rewardAmount,
uint16 claimLimit
uint16 claimLimit,
uint64 protocolFee
) internal returns (bytes memory createCalldata) {
createCalldata = LibZip.cdCompress(
abi.encode(
Expand All @@ -910,7 +913,7 @@ contract BoostCoreTest is Test {
validator: BoostLib.Target({isBase: true, instance: address(0), parameters: ""}),
allowList: _makeDenyList(),
incentives: _makeIncentives(incentiveCount, rewardAmount, claimLimit),
protocolFee: 0,
protocolFee: protocolFee,
maxParticipants: 10_000,
owner: address(1)
})
Expand Down

0 comments on commit 376dcef

Please sign in to comment.