Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
test_RevertIf_NotAuthorizedTargetSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
0xrajath committed Apr 9, 2024
1 parent 4e30027 commit 8731bae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/interfaces/ILlamaAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pragma solidity ^0.8.23;
/// @author Llama ([email protected])
/// @notice This is the interface for Llama accounts which can be used to hold assets for a Llama instance.
interface ILlamaAccount {
/// @dev External call failed.
/// @param result Data returned by the called function.
error FailedExecution(bytes result);

// -------- For Inspection --------

/// @notice Returns the address of the Llama instance's executor.
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/ILlamaCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ interface ILlamaCore {
/// @param current The current state of the action.
error InvalidActionState(ActionState current);

/// @dev Action execution failed.
/// @param reason Data returned by the function called by the action.
error FailedActionExecution(bytes reason);

function actionGuard(address target, bytes4 selector) external view returns (address guard);

function actionsCount() external view returns (uint256);
Expand Down
29 changes: 29 additions & 0 deletions test/rewards-claimer/LlamaRewardsClaimAccountExtension.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {MockRewardsContract} from "test/mock/MockRewardsContract.sol";
import {LlamaRewardsClaimTestSetup} from "test/rewards-claimer/LlamaRewardsClaimTestSetup.sol";

import {ILlamaAccount} from "src/interfaces/ILlamaAccount.sol";
import {ILlamaCore} from "src/interfaces/ILlamaCore.sol";
import {ActionInfo} from "src/lib/Structs.sol";
import {LlamaRewardsClaimAccountExtension} from "src/rewards-claimer/LlamaRewardsClaimAccountExtension.sol";
import {LlamaRewardsClaimGuard} from "src/rewards-claimer/LlamaRewardsClaimGuard.sol";
import {LlamaRewardsClaimStorage} from "src/rewards-claimer/LlamaRewardsClaimStorage.sol";

contract LlamaRewardsClaimAccountExtensionTest is LlamaRewardsClaimTestSetup {
event ethWithdrawn(address indexed from, address indexed to, uint256 amount);
Expand Down Expand Up @@ -104,4 +106,31 @@ contract ClaimRewards is LlamaRewardsClaimAccountExtensionTest {
assertEq(address(ACCOUNT).balance, initialLlamaAccountETHBalance + 5 ether);
assertEq(USDC.balanceOf(address(ACCOUNT)), initialLlamaAccountUSDCBalance + 5 ether);
}

function test_RevertIf_NotAuthorizedTargetSelector() public {
ActionInfo memory actionInfo = _createAndQueueActionClaimRewards();

// Unauthorize target selector.
LlamaRewardsClaimStorage.TargetSelectorAuthorization[] memory data =
new LlamaRewardsClaimStorage.TargetSelectorAuthorization[](1);
data[0] = LlamaRewardsClaimStorage.TargetSelectorAuthorization(
address(rewardsContract1), MockRewardsContract.withdrawETH.selector, false
);
vm.prank(address(EXECUTOR));
rewardsClaimStorage.setAuthorizedTargetSelectors(data);

bytes memory expectedErr = abi.encodeWithSelector(
ILlamaCore.FailedActionExecution.selector,
abi.encodeWithSelector(
ILlamaAccount.FailedExecution.selector,
abi.encodeWithSelector(
LlamaRewardsClaimAccountExtension.UnauthorizedTargetSelector.selector,
address(rewardsContract1),
MockRewardsContract.withdrawETH.selector
)
)
);
vm.expectRevert(expectedErr);
CORE.executeAction(actionInfo);
}
}

0 comments on commit 8731bae

Please sign in to comment.