Skip to content

Commit

Permalink
refactor and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Jul 7, 2024
1 parent de62519 commit 48176cb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
5 changes: 4 additions & 1 deletion contracts/base/ExecutionHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,14 @@ contract ExecutionHelper is IExecutionHelperEventsAndErrors {
/// @param execType The execution type, which can be DEFAULT (revert on failure) or TRY (return on failure).
function _handleDelegateCallExecutionAndReturnData(bytes calldata executionCalldata, ExecType execType) internal returns(bytes[] memory returnData) {

Check warning on line 198 in contracts/base/ExecutionHelper.sol

View check run for this annotation

Codecov / codecov/patch

contracts/base/ExecutionHelper.sol#L198

Added line #L198 was not covered by tests
(address delegate, bytes calldata callData) = executionCalldata.decodeDelegateCall();
returnData = new bytes[](1);
bool success;
if (execType == EXECTYPE_DEFAULT) {
returnData[0] = _executeDelegatecall(delegate, callData);
}
else if (execType == EXECTYPE_TRY) {
(, returnData[0]) = _tryExecuteDelegatecall(delegate, callData);
(success, returnData[0]) = _tryExecuteDelegatecall(delegate, callData);

Check warning on line 206 in contracts/base/ExecutionHelper.sol

View check run for this annotation

Codecov / codecov/patch

contracts/base/ExecutionHelper.sol#L206

Added line #L206 was not covered by tests
if (!success) emit TryDelegateCallUnsuccessful(0, returnData[0]);
}
else revert UnsupportedExecType(execType);

Check warning on line 209 in contracts/base/ExecutionHelper.sol

View check run for this annotation

Codecov / codecov/patch

contracts/base/ExecutionHelper.sol#L209

Added line #L209 was not covered by tests
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/interfaces/base/IExecutionHelperEventsAndErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ interface IExecutionHelperEventsAndErrors {
/// @notice Event emitted when a transaction fails to execute successfully.
event TryExecuteUnsuccessful(uint256 batchExecutionindex, bytes result);

/// @notice Event emitted when a transaction fails to execute successfully.
event TryDelegateCallUnsuccessful(uint256 batchExecutionindex, bytes result);

/// @notice Error thrown when an execution with an unsupported ExecType was made.
/// @param execType The unsupported execution type.
error UnsupportedExecType(ExecType execType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ contract TestAccountExecution_ExecuteFromExecutor is TestAccountExecution_Base {
}

/// @notice Tests delegate call execution via MockExecutor
// function test_ExecuteDelegateCallFromExecutor_Success() public {

// (bool res, ) = payable(address(BOB_ACCOUNT)).call{ value: 2 ether}(""); // Fund BOB_ACCOUNT
// assertEq(res, true, "Funding BOB_ACCOUNT should succeed");

// address valueTarget = makeAddr("valueTarget");
// uint256 value = 1 ether;
// bytes memory sendValueCallData =
// abi.encodeWithSelector(MockDelegateTarget.sendValue.selector, valueTarget, value);
// mockExecutor.execDelegatecall(BOB_ACCOUNT, sendValueCallData);
// // Assert that the value was set ie that execution was successful
// assertTrue(valueTarget.balance == value);
// }
// Review
function test_ExecuteDelegateCallFromExecutor_Success() public {

(bool res, ) = payable(address(BOB_ACCOUNT)).call{ value: 2 ether}(""); // Fund BOB_ACCOUNT
assertEq(res, true, "Funding BOB_ACCOUNT should succeed");

address valueTarget = makeAddr("valueTarget");
uint256 value = 1 ether;
bytes memory sendValueCallData =
abi.encodeWithSelector(MockDelegateTarget.sendValue.selector, valueTarget, value);
mockExecutor.execDelegatecall(BOB_ACCOUNT, sendValueCallData);
// Assert that the value was set ie that execution was successful
// assertTrue(valueTarget.balance == value);
}

/// @notice Tests batch execution via MockExecutor
function test_ExecBatchFromExecutor_Success() public {
Expand Down

0 comments on commit 48176cb

Please sign in to comment.