diff --git a/test/QuestBudget.t.sol b/test/QuestBudget.t.sol index 9da75f69..b52ae703 100644 --- a/test/QuestBudget.t.sol +++ b/test/QuestBudget.t.sol @@ -1231,6 +1231,71 @@ contract QuestBudgetTest is Test, TestUtils, IERC1155Receiver { questBudget.payManagementFee(questId_); } + function testPayManagementFee_NotQuestCreator() public { + // Set management fee + vm.prank(questBudget.owner()); + questBudget.setManagementFee(500); // 5% + + // Authorize a different address to create quests + address questCreator = address(0xc0ffee); + address[] memory accounts = new address[](1); + bool[] memory authorized = new bool[](1); + accounts[0] = questCreator; + authorized[0] = true; + questBudget.setAuthorized(accounts, authorized); + + // Set quest data + uint32 txHashChainId_ = 1; + address rewardTokenAddress_ = address(mockERC20); + uint256 endTime_ = block.timestamp + 1 days; + uint256 startTime_ = block.timestamp; + uint256 totalParticipants_ = 10; + uint256 rewardAmount_ = 1 ether; + string memory questId_ = "testQuest"; + string memory actionType_ = "testAction"; + string memory questName_ = "Test Quest"; + string memory projectName_ = "Test Project"; + uint256 referralRewardFee_ = 250; + uint256 numberMinted_ = 10; + uint256 maxTotalRewards = totalParticipants_ * rewardAmount_; + uint256 questFee = uint256(mockQuestFactory.questFee()); + uint256 referralRewardFee = uint256(mockQuestFactory.referralRewardFee()); + uint256 maxProtocolReward = (maxTotalRewards * questFee) / 10_000; + uint256 maxReferralReward = (maxTotalRewards * referralRewardFee) / 10_000; + uint256 maxManagementFee = (maxTotalRewards * questBudget.managementFee()) / 10_000; + uint256 requiredApprovalAmount = maxTotalRewards + maxProtocolReward + maxReferralReward + maxManagementFee; + + // Allocate tokens to questBudget + mockERC20.mint(address(questBudget), requiredApprovalAmount); + + // Create quest using authorized address + vm.prank(questCreator); + address questAddress = questBudget.createERC20Quest( + txHashChainId_, rewardTokenAddress_, endTime_, startTime_, + totalParticipants_, rewardAmount_, questId_, actionType_, questName_, projectName_, referralRewardFee_ + ); + + // Mock quest data + mockQuestFactory.setQuestData(questId_, IQuestFactory.QuestData({ + questAddress: questAddress, + rewardToken: address(mockERC20), + queued: false, + questFee: 250, // 2.5% + startTime: startTime_, + endTime: endTime_, + totalParticipants: totalParticipants_, + numberMinted: numberMinted_, + redeemedTokens: numberMinted_ * rewardAmount_, + rewardAmountOrTokenId: rewardAmount_, + hasWithdrawn: true + })); + + // Attempt to call payManagementFee as budget owner (not quest creator) + vm.prank(questBudget.owner()); + vm.expectRevert("Only the quest creator can claim the management fee"); + questBudget.payManagementFee(questId_); + } + function testPayManagementFee_NotAuthorized() public { vm.prank(address(0xc0ffee));