Skip to content

Commit

Permalink
chore:delegate call test execFromExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Jul 7, 2024
1 parent ef1949a commit 3197d80
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
30 changes: 29 additions & 1 deletion contracts/mocks/MockExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ import { IModule } from "contracts/interfaces/modules/IModule.sol";
import { EncodedModuleTypes } from "contracts/lib/ModuleTypeLib.sol";
import { INexus } from "contracts/interfaces/INexus.sol";
import { MODULE_TYPE_EXECUTOR } from "contracts/types/Constants.sol";
import { ModeLib, ExecutionMode, ExecType, CallType, CALLTYPE_BATCH, CALLTYPE_SINGLE, EXECTYPE_DEFAULT, EXECTYPE_TRY } from "contracts/lib/ModeLib.sol";
import {
ModeLib,
ExecutionMode,
ExecType,
CallType,
CALLTYPE_BATCH,
CALLTYPE_SINGLE,
CALLTYPE_DELEGATECALL,
EXECTYPE_DEFAULT,
EXECTYPE_TRY
} from "contracts/lib/ModeLib.sol";
import { ExecLib } from "contracts/lib/ExecLib.sol";
import { MODE_DEFAULT, ModePayload } from "contracts/lib/ModeLib.sol";

import { IExecutor } from "../../contracts/interfaces/modules/IExecutor.sol";
import "../../contracts/types/DataTypes.sol";
Expand All @@ -27,6 +38,21 @@ contract MockExecutor is IExecutor {
return account.executeFromExecutor(ModeLib.encodeSimpleSingle(), ExecLib.encodeSingle(target, value, callData));
}

function execDelegatecall(
INexus account,
bytes calldata callData
)
external
returns (bytes[] memory returnData)
{
return account.executeFromExecutor(
ModeLib.encode(
CALLTYPE_DELEGATECALL, EXECTYPE_DEFAULT, MODE_DEFAULT, ModePayload.wrap(0x00)
),
callData
);
}

function executeBatchViaAccount(INexus account, Execution[] calldata execs) external returns (bytes[] memory returnData) {
return account.executeFromExecutor(ModeLib.encodeSimpleBatch(), ExecLib.encodeBatch(execs));
}
Expand Down Expand Up @@ -72,4 +98,6 @@ contract MockExecutor is IExecutor {
function isInitialized(address) external pure override returns (bool) {
return false;
}

receive() external payable {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import "../../../shared/TestAccountExecution_Base.t.sol";

contract TestAccountExecution_ExecuteFromExecutor is TestAccountExecution_Base {
MockExecutor public mockExecutor;
MockDelegateTarget delegateTarget;

/// @notice Sets up the testing environment and installs the MockExecutor module
function setUp() public {
setUpTestAccountExecution_Base();

mockExecutor = new MockExecutor();
counter = new Counter();
delegateTarget = new MockDelegateTarget();

// Install MockExecutor as executor module on BOB_ACCOUNT
bytes memory callDataInstall = abi.encodeWithSelector(IModuleManager.installModule.selector, uint256(2), address(mockExecutor), "");
Expand Down Expand Up @@ -48,6 +50,21 @@ contract TestAccountExecution_ExecuteFromExecutor is TestAccountExecution_Base {
ENTRYPOINT.handleOps(userOpsExec, payable(address(BOB.addr)));
assertEq(counter.getNumber(), 1, "Counter should have incremented");
}

/// @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);
// }

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

0 comments on commit 3197d80

Please sign in to comment.