From 3e7ab4b80162b15c8637733743250c0b42da2477 Mon Sep 17 00:00:00 2001 From: Jonathan Diep Date: Mon, 17 Jun 2024 09:59:17 -0700 Subject: [PATCH] chore: update tests --- test/Quest.t.sol | 58 ++++++++++----------------------- test/QuestClaimable.t.sol | 11 +++---- test/QuestFactory.t.sol | 67 +++++++++++++++----------------------- test/helpers/QuestData.sol | 1 - test/helpers/TestUtils.sol | 16 +++++++-- 5 files changed, 62 insertions(+), 91 deletions(-) diff --git a/test/Quest.t.sol b/test/Quest.t.sol index 50500089..eea3b428 100644 --- a/test/Quest.t.sol +++ b/test/Quest.t.sol @@ -24,7 +24,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { string QUEST_ID = "QUEST_ID"; uint16 QUEST_FEE = 2000; // 20% uint256 CLAIM_FEE = 999; - uint256 REFERRAL_REWARD_FEE = 500; // 5% + uint16 REFERRAL_REWARD_FEE = 250; // 2.5% address protocolFeeRecipient = makeAddr("protocolFeeRecipient"); address questFactoryMock; Quest quest; @@ -37,7 +37,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { string constant DEFAULT_ERC20_SYMBOL = "RTC"; function setUp() public { - defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT_IN_WEI, QUEST_FEE); + defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT_IN_WEI, QUEST_FEE, REFERRAL_REWARD_FEE); rewardTokenAddress = address( new SampleERC20( DEFAULT_ERC20_NAME, @@ -58,8 +58,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { REWARD_AMOUNT_IN_WEI, QUEST_ID, QUEST_FEE, - protocolFeeRecipient, - REFERRAL_REWARD_FEE + protocolFeeRecipient ); // Transfer all tokens to quest vm.prank(admin); @@ -97,8 +96,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { REWARD_AMOUNT_IN_WEI, QUEST_ID, QUEST_FEE, - protocolFeeRecipient, - REFERRAL_REWARD_FEE + protocolFeeRecipient ); } @@ -115,26 +113,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { REWARD_AMOUNT_IN_WEI, QUEST_ID, QUEST_FEE, - protocolFeeRecipient, - REFERRAL_REWARD_FEE - ); - } - - function test_RevertIf_initialize_ReferralRewardFeeTooHigh() public { - address payable questAddress = payable(address(new Quest()).cloneDeterministic(keccak256(abi.encodePacked(msg.sender, "SALT")))); - quest = Quest(questAddress); - vm.prank(questFactoryMock); - vm.expectRevert(abi.encodeWithSelector(ReferralRewardFeeTooHigh.selector)); - quest.initialize( - rewardTokenAddress, - END_TIME, - START_TIME, - TOTAL_PARTICIPANTS, - REWARD_AMOUNT_IN_WEI, - QUEST_ID, - QUEST_FEE, - protocolFeeRecipient, - 600 + protocolFeeRecipient ); } @@ -197,7 +176,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { currentTime = bound(currentTime, startTime, endTime - 1); rewardAmountInWei = bound(rewardAmountInWei, 1, REWARD_AMOUNT_IN_WEI * REWARD_AMOUNT_IN_WEI); // Setup a reward token with fuzzed rewardAmountInWei - defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, rewardAmountInWei, QUEST_FEE); + defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, rewardAmountInWei, QUEST_FEE, REFERRAL_REWARD_FEE); rewardTokenAddress = address( new SampleERC20( DEFAULT_ERC20_NAME, @@ -221,8 +200,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { rewardAmountInWei, QUEST_ID, QUEST_FEE, - protocolFeeRecipient, - REFERRAL_REWARD_FEE + protocolFeeRecipient ); // Transfer all tokens to quest vm.prank(admin); @@ -268,7 +246,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { // simulate ETH from TOTAL_PARTICIPANTS claims vm.deal(address(quest), (CLAIM_FEE * TOTAL_PARTICIPANTS * 2) / 3); - uint256 totalFees = calculateTotalFees(TOTAL_PARTICIPANTS, REWARD_AMOUNT_IN_WEI, QUEST_FEE) / 2; + uint256 totalFees = calculateTotalProtocolFees(TOTAL_PARTICIPANTS, REWARD_AMOUNT_IN_WEI, QUEST_FEE) / 2; uint256 questBalance = SampleERC20(rewardTokenAddress).balanceOf(address(quest)); uint256 questBalanceMinusFees = questBalance - totalFees; @@ -322,15 +300,15 @@ contract TestQuest is Test, TestUtils, Errors, Events { CLAIM REFERRAL FEES //////////////////////////////////////////////////////////////*/ - function test_fuzz_claimReferralFees(uint96 timestamp, uint256 participants, uint256 referralRewardFee) public { + function test_fuzz_claimReferralFees(uint96 timestamp, uint256 participants) public { timestamp = uint96(bound(timestamp, START_TIME+10, END_TIME)); participants = bound(participants, 1, TOTAL_PARTICIPANTS); - referralRewardFee = bound(referralRewardFee, 1, REFERRAL_REWARD_FEE); + // referralRewardFee = bound(referralRewardFee, 1, REFERRAL_REWARD_FEE); vm.startPrank(admin); // Transfer the appropriate amount of Reward tokens to the quest based on fuzzed participants - defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(participants, REWARD_AMOUNT_IN_WEI, QUEST_FEE); + defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(participants, REWARD_AMOUNT_IN_WEI, QUEST_FEE, REFERRAL_REWARD_FEE); rewardTokenAddress = address( new SampleERC20( DEFAULT_ERC20_NAME, @@ -352,8 +330,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { REWARD_AMOUNT_IN_WEI, QUEST_ID, QUEST_FEE, - protocolFeeRecipient, - referralRewardFee + protocolFeeRecipient ); vm.startPrank(admin); @@ -432,15 +409,15 @@ contract TestQuest is Test, TestUtils, Errors, Events { ); } - function test_fuzz_claimReferralFees_withdrawAfterClaim(uint96 timestamp, uint256 participants, uint256 referralRewardFee) public { + function test_fuzz_claimReferralFees_withdrawAfterClaim(uint96 timestamp, uint256 participants) public { timestamp = uint96(bound(timestamp, START_TIME+10, END_TIME)); participants = bound(participants, 1, TOTAL_PARTICIPANTS); - referralRewardFee = bound(referralRewardFee, 1, REFERRAL_REWARD_FEE); + // referralRewardFee = bound(referralRewardFee, 1, REFERRAL_REWARD_FEE); vm.startPrank(admin); // Transfer the appropriate amount of Reward tokens to the quest based on fuzzed participants - defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(participants, REWARD_AMOUNT_IN_WEI, QUEST_FEE); + defaultTotalRewardsPlusFee = calculateTotalRewardsPlusFee(participants, REWARD_AMOUNT_IN_WEI, QUEST_FEE, REFERRAL_REWARD_FEE); rewardTokenAddress = address( new SampleERC20( DEFAULT_ERC20_NAME, @@ -462,8 +439,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { REWARD_AMOUNT_IN_WEI, QUEST_ID, QUEST_FEE, - protocolFeeRecipient, - referralRewardFee + protocolFeeRecipient ); vm.startPrank(admin); @@ -586,7 +562,7 @@ contract TestQuest is Test, TestUtils, Errors, Events { function test_maxProtocolReward() public { assertEq( quest.maxProtocolReward(), - calculateTotalFees(TOTAL_PARTICIPANTS, REWARD_AMOUNT_IN_WEI, QUEST_FEE), + calculateTotalProtocolFees(TOTAL_PARTICIPANTS, REWARD_AMOUNT_IN_WEI, QUEST_FEE), "maxProtocolReward should be correct" ); } diff --git a/test/QuestClaimable.t.sol b/test/QuestClaimable.t.sol index 9321aa8f..a0dd6696 100644 --- a/test/QuestClaimable.t.sol +++ b/test/QuestClaimable.t.sol @@ -35,6 +35,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils { uint256 REWARD_AMOUNT = 10; uint16 QUEST_FEE = 2000; uint256 MINT_FEE = 100; + uint16 REFERRAL_REWARD_FEE = 250; address protocolFeeRecipient = makeAddr("protocolFeeRecipient"); address questCreator = makeAddr(("questCreator")); address participant = makeAddr(("participant")); @@ -71,7 +72,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils { //////////////////////////////////////////////////////////////*/ function test_claim_with_referrer() public { vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE, REFERRAL_REWARD_FEE)); address questAddress = questFactory.createERC20Quest( 101, address(sampleERC20), @@ -82,8 +83,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils { "550e8400-e29b-41d4-a716-446655440000", "actionType", "questName", - "projectName", - 500 + "projectName" ); vm.warp(START_TIME + 1); @@ -108,7 +108,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils { function test_claim_without_referrer() public { referrer = address(0); vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE, REFERRAL_REWARD_FEE)); address questAddress = questFactory.createERC20Quest( 101, address(sampleERC20), @@ -119,8 +119,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils { "550e8400-e29b-41d4-a716-446655440000", "actionType", "questName", - "projectName", - 500 + "projectName" ); vm.warp(START_TIME + 1); diff --git a/test/QuestFactory.t.sol b/test/QuestFactory.t.sol index 2c027625..3121b8f2 100644 --- a/test/QuestFactory.t.sol +++ b/test/QuestFactory.t.sol @@ -32,7 +32,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { SampleERC1155 sampleERC1155; SampleERC20 sampleERC20; uint256 claimSignerPrivateKey; - uint16 REFERRAL_FEE = 2000; + uint16 REFERRAL_FEE = 250; uint256 NFT_QUEST_FEE = 10; uint16 QUEST_FEE = 2000; uint256 MINT_FEE = 100; @@ -48,8 +48,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { PROJECT_NAME: "projectName", CHAIN_ID : 7777777, TX_HASH : hex'7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516', - JSON_MSG : '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"actionType":"actionType"}', - REFERRAL_REWARD_FEE: 500 + JSON_MSG : '{"actionTxHashes":["0x7e1975a6bf513022a8cc382a3cdb1e1dbcd58ebb1cb9abf11e64aadb21262516"],"actionNetworkChainIds":[7777777],"actionType":"actionType"}' }); address protocolFeeRecipient = makeAddr("protocolFeeRecipient"); address questCreator = makeAddr(("questCreator")); @@ -63,7 +62,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { questFactory = QuestFactory(questFactoryAddress); sampleERC1155 = new SampleERC1155(); - sampleERC20 = new SampleERC20("name", "symbol", calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE), questCreator); + sampleERC20 = new SampleERC20("name", "symbol", calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE), questCreator); claimSignerPrivateKey = uint256(vm.envUint("TEST_CLAIM_SIGNER_PRIVATE_KEY")); vm.deal(owner, 1000000); vm.deal(participant, 1000000); @@ -119,7 +118,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { function test_createERC20Quest() public{ vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); vm.expectEmit(true,false,true,true); emit QuestCreated(questCreator, address(0), QUEST.PROJECT_NAME, QUEST.QUEST_NAME, QUEST.QUEST_ID_STRING, "erc20", QUEST.ACTION_TYPE, QUEST.CHAIN_ID, address(sampleERC20), QUEST.END_TIME, QUEST.START_TIME, QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT); @@ -134,21 +133,20 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); Quest quest = Quest(payable(questAddress)); assertEq(quest.startTime(), QUEST.START_TIME, "startTime should be set"); assertEq(quest.queued(), true, "queued should be set"); - assertEq(sampleERC20.balanceOf(address(quest)), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE), "balance should be set"); + assertEq(sampleERC20.balanceOf(address(quest)), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE), "balance should be set"); vm.stopPrank(); } function test_RevertIf_createERC20Quest_QuestIdUsed() public{ vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -159,8 +157,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.expectRevert(abi.encodeWithSelector(QuestIdUsed.selector)); @@ -174,8 +171,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); } @@ -184,7 +180,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { questFactory.setErc20QuestAddress(address(0)); vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); vm.expectRevert(abi.encodeWithSelector(Erc20QuestAddressNotSet.selector)); questFactory.createERC20Quest( @@ -197,8 +193,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); } @@ -252,7 +247,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { vm.deal(participant, 1000000); vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); address questAddress = questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -263,8 +258,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.warp(QUEST.START_TIME + 1); @@ -292,7 +286,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { vm.deal(participant, 1000000); vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); address questAddress = questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -303,8 +297,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.warp(QUEST.START_TIME + 1); @@ -324,7 +317,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { function test_claimCompressed_erc20_with_ref() public{ vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); address questAddress = questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -335,8 +328,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.warp(QUEST.START_TIME + 1); @@ -391,7 +383,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { function test_claimOptimized_revert_deprecated() public{ vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -402,8 +394,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.warp(QUEST.START_TIME + 1); @@ -423,7 +414,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { function test_cancelQuest() public { vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); address questAddress = questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -434,8 +425,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.startPrank(questCreator); @@ -448,7 +438,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { function test_cancelQuest_alreadyStarted() public { vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); address questAddress = questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -459,8 +449,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.warp(QUEST.START_TIME + 1); @@ -474,7 +463,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { function test_cancelQuest_unauthorized() public { vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); address questAddress = questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -485,8 +474,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); vm.startPrank(anyone); @@ -499,7 +487,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { //////////////////////////////////////////////////////////////*/ function test_questData() public { vm.startPrank(questCreator); - sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE)); + sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE)); address questAddress = questFactory.createERC20Quest( QUEST.CHAIN_ID, address(sampleERC20), @@ -510,8 +498,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils { QUEST.QUEST_ID_STRING, QUEST.ACTION_TYPE, QUEST.QUEST_NAME, - QUEST.PROJECT_NAME, - QUEST.REFERRAL_REWARD_FEE + QUEST.PROJECT_NAME ); IQuestFactory.QuestData memory questData = questFactory.questData(QUEST.QUEST_ID_STRING); diff --git a/test/helpers/QuestData.sol b/test/helpers/QuestData.sol index 4dbc980e..3f397b0a 100644 --- a/test/helpers/QuestData.sol +++ b/test/helpers/QuestData.sol @@ -18,7 +18,6 @@ contract QuestData is Test { bytes32 TX_HASH; string JSON_MSG; uint256 REWARD_AMOUNT; - uint256 REFERRAL_REWARD_FEE; } } diff --git a/test/helpers/TestUtils.sol b/test/helpers/TestUtils.sol index 1779ec8c..b69ed045 100644 --- a/test/helpers/TestUtils.sol +++ b/test/helpers/TestUtils.sol @@ -8,17 +8,19 @@ contract TestUtils is Test { function calculateTotalRewardsPlusFee( uint256 totalParticipants, uint256 rewardAmount, - uint16 questFee + uint16 questFee, + uint16 affiliateFee ) internal pure returns (uint256) { return calculateTotalRewards(totalParticipants, rewardAmount) - + calculateTotalFees(totalParticipants, rewardAmount, questFee); + + calculateTotalProtocolFees(totalParticipants, rewardAmount, questFee) + + calculateTotalAffiliateFees(totalParticipants, rewardAmount, affiliateFee); } function calculateTotalRewards(uint256 totalParticipants, uint256 rewardAmount) internal pure returns (uint256) { return totalParticipants * rewardAmount; } - function calculateTotalFees( + function calculateTotalProtocolFees( uint256 totalParticipants, uint256 rewardAmount, uint16 questFee @@ -26,6 +28,14 @@ contract TestUtils is Test { return (totalParticipants * rewardAmount * questFee) / 10_000; } + function calculateTotalAffiliateFees( + uint256 totalParticipants, + uint256 rewardAmount, + uint16 affiliateFee + ) internal pure returns (uint256) { + return (totalParticipants * rewardAmount * affiliateFee) / 10_000; + } + function signHash(bytes32 msgHash, uint256 privateKey) internal pure returns (bytes memory) { bytes32 digest = ECDSA.toEthSignedMessageHash(msgHash); (uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);