Skip to content

Commit

Permalink
chore: cleanup mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Feb 23, 2024
1 parent 100d124 commit 98e8d7b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 147 deletions.
3 changes: 2 additions & 1 deletion accounts/safe7579/test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { SafeERC7579 } from "src/SafeERC7579.sol";
import { ModuleManager } from "src/core/ModuleManager.sol";
import { MockValidator } from "./mocks/MockValidator.sol";
import { MockExecutor } from "./mocks/MockExecutor.sol";
import { MockTarget } from "./mocks/MockTarget.sol";
import { MockFallback } from "./mocks/MockFallback.sol";
import { MockTarget } from "@rhinestone/modulekit/src/mocks/MockTarget.sol";

import { Safe } from "@safe-global/safe-contracts/contracts/Safe.sol";
import { LibClone } from "solady/src/utils/LibClone.sol";
Expand Down
13 changes: 5 additions & 8 deletions accounts/safe7579/test/SafeERC7579.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ pragma solidity ^0.8.23;
import "erc7579/interfaces/IERC7579Account.sol";
import "erc7579/lib/ModeLib.sol";
import "erc7579/lib/ExecutionLib.sol";
import { MockTarget } from "./mocks/MockTarget.sol";
import { MockFallback } from "./mocks/MockFallback.sol";
import "./Base.t.sol";
import { TestBaseUtil, MockTarget, MockFallback } from "./Base.t.sol";

contract MSATest is TestBaseUtil {
function setUp() public override {
Expand All @@ -15,7 +13,7 @@ contract MSATest is TestBaseUtil {

function test_execSingle() public {
// Create calldata for the account to execute
bytes memory setValueOnTarget = abi.encodeCall(MockTarget.setValue, 1337);
bytes memory setValueOnTarget = abi.encodeCall(MockTarget.set, 1337);

// Encode the call into the calldata for the userOp
bytes memory userOpCalldata = abi.encodeCall(
Expand All @@ -41,7 +39,6 @@ contract MSATest is TestBaseUtil {
userOps[0] = userOp;

// Send the userOp to the entrypoint
console2.log("userOps");
entrypoint.handleOps(userOps, payable(address(0x69)));

// Assert that the value was set ie that execution was successful
Expand All @@ -50,7 +47,7 @@ contract MSATest is TestBaseUtil {

function test_execBatch() public {
// Create calldata for the account to execute
bytes memory setValueOnTarget = abi.encodeCall(MockTarget.setValue, 1337);
bytes memory setValueOnTarget = abi.encodeCall(MockTarget.set, 1337);
address target2 = address(0x420);
uint256 target2Amount = 1 wei;

Expand Down Expand Up @@ -91,12 +88,12 @@ contract MSATest is TestBaseUtil {
IERC7579Account(address(safe)),
address(target),
0,
abi.encodeWithSelector(MockTarget.setValue.selector, 1337)
abi.encodeWithSelector(MockTarget.set.selector, 1337)
);
}

function test_execBatchFromExecutor() public {
bytes memory setValueOnTarget = abi.encodeCall(MockTarget.setValue, 1338);
bytes memory setValueOnTarget = abi.encodeCall(MockTarget.set, 1338);
Execution[] memory executions = new Execution[](2);
executions[0] = Execution({ target: address(target), value: 0, callData: setValueOnTarget });
executions[1] = Execution({ target: address(target), value: 0, callData: setValueOnTarget });
Expand Down
16 changes: 2 additions & 14 deletions accounts/safe7579/test/mocks/MockExecutor.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IExecutor } from "erc7579/interfaces/IERC7579Module.sol";
import { IERC7579Account, Execution } from "erc7579/interfaces/IERC7579Account.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
import { MockExecutor as MockExecutorBase } from "@rhinestone/modulekit/src/mocks/MockExecutor.sol";

contract MockExecutor is IExecutor {
function onInstall(bytes calldata data) external override { }

function onUninstall(bytes calldata data) external override { }

contract MockExecutor is MockExecutorBase {
function executeViaAccount(
IERC7579Account account,
address target,
Expand All @@ -36,12 +32,4 @@ contract MockExecutor is IExecutor {
ModeLib.encodeSimpleBatch(), ExecutionLib.encodeBatch(execs)
);
}

function isModuleType(uint256 typeID) external view returns (bool) {
return typeID == 2;
}

function isInitialized(address smartAccount) external view returns (bool) {
return false;
}
}
19 changes: 2 additions & 17 deletions accounts/safe7579/test/mocks/MockFallback.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IFallback } from "erc7579/interfaces/IERC7579Module.sol";
import { IERC7579Account, Execution } from "erc7579/interfaces/IERC7579Account.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
import { HandlerContext } from "@safe-global/safe-contracts/contracts/handler/HandlerContext.sol";
import { MockFallback as MockFallbackBase } from "@rhinestone/modulekit/src/mocks/MockFallback.sol";

contract MockFallback is IFallback, HandlerContext {
function onInstall(bytes calldata data) external override { }

function onUninstall(bytes calldata data) external override { }

contract MockFallback is MockFallbackBase, HandlerContext {
function target(uint256 value)
external
returns (uint256 _value, address erc2771Sender, address msgSender)
Expand All @@ -20,12 +13,4 @@ contract MockFallback is IFallback, HandlerContext {
erc2771Sender = _msgSender();
msgSender = msg.sender;
}

function isModuleType(uint256 typeID) external view returns (bool) {
return typeID == 3;
}

function isInitialized(address smartAccount) external view returns (bool) {
return false;
}
}
54 changes: 0 additions & 54 deletions accounts/safe7579/test/mocks/MockRegistry.sol

This file was deleted.

11 changes: 0 additions & 11 deletions accounts/safe7579/test/mocks/MockTarget.sol

This file was deleted.

35 changes: 5 additions & 30 deletions accounts/safe7579/test/mocks/MockValidator.sol
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {
IValidator,
PackedUserOperation,
VALIDATION_SUCCESS
} from "erc7579/interfaces/IERC7579Module.sol";

contract MockValidator is IValidator {
function onInstall(bytes calldata data) external override { }

function onUninstall(bytes calldata data) external override { }
import { PackedUserOperation } from "erc7579/interfaces/IERC7579Module.sol";
import { MockValidator as MockValidatorBase } from
"@rhinestone/modulekit/src/mocks/MockValidator.sol";

contract MockValidator is MockValidatorBase {
function validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
)
external
override
returns (uint256)
returns (ValidationData)
{
bytes4 execSelector = bytes4(userOp.callData[:4]);

return VALIDATION_SUCCESS;
}

function isValidSignatureWithSender(
address sender,
bytes32 hash,
bytes calldata data
)
external
view
override
returns (bytes4)
{ }

function isModuleType(uint256 typeID) external view returns (bool) {
return typeID == 1;
}

function isInitialized(address smartAccount) external view returns (bool) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IHook } from "erc7579/interfaces/IERC7579Module.sol";
import { ERC7579FallbackBase } from "../Modules.sol";

contract MockHook is IHook {
contract MockFallback is ERC7579FallbackBase {
function onInstall(bytes calldata data) external override { }

function onUninstall(bytes calldata data) external override { }

function preCheck(
address msgSender,
bytes calldata msgData
)
external
returns (bytes memory hookData)
{ }
function postCheck(bytes calldata hookData) external returns (bool success) { }
function targetFunction() external returns (bool) {
return true;
}

function isModuleType(uint256 typeID) external view returns (bool) {
return typeID == 4;
return typeID == TYPE_FALLBACK;
}

function isInitialized(address smartAccount) external view returns (bool) {
Expand Down
3 changes: 2 additions & 1 deletion packages/modulekit/src/mocks/MockHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ contract MockHook is ERC7579HookBase {
bytes calldata msgData
)
external
virtual
override
returns (bytes memory hookData)
{ }

function postCheck(bytes calldata) external override returns (bool success) {
function postCheck(bytes calldata) external virtual override returns (bool success) {
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/modulekit/src/mocks/MockValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract MockValidator is ERC7579ValidatorBase {
bytes32 userOpHash
)
external
virtual
override
returns (ValidationData)
{
Expand All @@ -29,6 +30,7 @@ contract MockValidator is ERC7579ValidatorBase {
)
external
view
virtual
override
returns (bytes4)
{
Expand Down

0 comments on commit 98e8d7b

Please sign in to comment.