Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ExecutionFailed error and improve error handling in execute… #42

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/PointTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall
error PTokenNotDeployed();
error AmountTooSmall();
error NotTrustedReceiver();
error ExecutionFailed(address to, bytes data);

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
Expand Down Expand Up @@ -386,6 +387,10 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall
assembly {
success := delegatecall(_txGas, _to, add(_data, 0x20), mload(_data), 0, 0)
}

if (!success) {
revert ExecutionFailed(_to, _data);
}
}

function _authorizeUpgrade(address _newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}
Expand Down
15 changes: 15 additions & 0 deletions contracts/test/PointTokenVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ contract PointTokenVaultTest is Test {
pointTokenVault.execute(
address(callEcho), abi.encodeWithSelector(CallEcho.callEcho.selector, echo, "Hello"), GAS_LIMIT
);

// Test that failed calls revert with ExecutionFailed error
vm.prank(admin);
vm.expectRevert(
abi.encodeWithSelector(
PointTokenVault.ExecutionFailed.selector,
address(callEcho),
abi.encodeWithSelector(CallEcho.fail.selector)
)
);
pointTokenVault.execute(address(callEcho), abi.encodeWithSelector(CallEcho.fail.selector), GAS_LIMIT);
}

event PTokensClaimed(
Expand Down Expand Up @@ -991,4 +1002,8 @@ contract CallEcho {
function callEcho(Echo echo, string calldata message) public {
echo.echo(message);
}

function fail() public pure {
revert("Failed");
}
}