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

fix: various bug fixes on safe and kernel support #122

Merged
merged 12 commits into from
Jun 6, 2024
2 changes: 0 additions & 2 deletions src/test/ModuleKitHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ library ModuleKitHelpers {
internal
returns (UserOpData memory userOpData)
{
data = getInstallModuleData(instance, moduleTypeId, module, data);
userOpData = instance.getInstallModuleOps(
moduleTypeId, module, data, address(instance.defaultValidator)
);
Expand All @@ -53,7 +52,6 @@ library ModuleKitHelpers {
internal
returns (UserOpData memory userOpData)
{
data = getUninstallModuleData(instance, moduleTypeId, module, data);
userOpData = instance.getUninstallModuleOps(
moduleTypeId, module, data, address(instance.defaultValidator)
);
Expand Down
20 changes: 6 additions & 14 deletions src/test/helpers/ERC7579Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract ERC7579Helpers is HelperBase {
/**
* get callData to uninstall validator on ERC7579 Account
*/
function uninstallValidator(
function getUninstallValidatorData(
address account,
address validator,
bytes memory initData
Expand All @@ -23,7 +23,7 @@ contract ERC7579Helpers is HelperBase {
view
virtual
override
returns (bytes memory callData)
returns (bytes memory data)
{
// get previous validator in sentinel list
address previous;
Expand All @@ -40,17 +40,13 @@ contract ERC7579Helpers is HelperBase {
if (array[i] == validator) previous = array[i - 1];
}
}
initData = abi.encode(previous, initData);

callData = abi.encodeCall(
IERC7579Account.uninstallModule, (MODULE_TYPE_VALIDATOR, validator, initData)
);
data = abi.encode(previous, initData);
}

/**
* get callData to uninstall executor on ERC7579 Account
*/
function uninstallExecutor(
function getUninstallExecutorData(
address account,
address executor,
bytes memory initData
Expand All @@ -59,7 +55,7 @@ contract ERC7579Helpers is HelperBase {
view
virtual
override
returns (bytes memory callData)
returns (bytes memory data)
{
// get previous executor in sentinel list
address previous;
Expand All @@ -76,10 +72,6 @@ contract ERC7579Helpers is HelperBase {
if (array[i] == executor) previous = array[i - 1];
}
}
initData = abi.encode(previous, initData);

callData = abi.encodeCall(
IERC7579Account.uninstallModule, (MODULE_TYPE_EXECUTOR, executor, initData)
);
data = abi.encode(previous, initData);
}
}
117 changes: 62 additions & 55 deletions src/test/helpers/HelperBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,17 @@ abstract contract HelperBase {
returns (bytes memory callData)
{
if (moduleType == MODULE_TYPE_VALIDATOR) {
return installValidator(account, module, initData);
initData = getInstallValidatorData(account, module, initData);
} else if (moduleType == MODULE_TYPE_EXECUTOR) {
return installExecutor(account, module, initData);
initData = getInstallExecutorData(account, module, initData);
} else if (moduleType == MODULE_TYPE_HOOK) {
return installHook(account, module, initData);
initData = getInstallHookData(account, module, initData);
} else if (moduleType == MODULE_TYPE_FALLBACK) {
return installFallback(account, module, initData);
initData = getInstallFallbackData(account, module, initData);
} else {
revert("Invalid module type");
}
callData = abi.encodeCall(IERC7579Account.installModule, (moduleType, module, initData));
}

/**
Expand All @@ -130,158 +131,145 @@ abstract contract HelperBase {
returns (bytes memory callData)
{
if (moduleType == MODULE_TYPE_VALIDATOR) {
return uninstallValidator(account, module, initData);
initData = getUninstallValidatorData(account, module, initData);
} else if (moduleType == MODULE_TYPE_EXECUTOR) {
return uninstallExecutor(account, module, initData);
initData = getUninstallExecutorData(account, module, initData);
} else if (moduleType == MODULE_TYPE_HOOK) {
return uninstallHook(account, module, initData);
initData = getUninstallHookData(account, module, initData);
} else if (moduleType == MODULE_TYPE_FALLBACK) {
return uninstallFallback(account, module, initData);
initData = getUninstallFallbackData(account, module, initData);
} else {
revert("Invalid module type");
}
callData = abi.encodeCall(IERC7579Account.uninstallModule, (moduleType, module, initData));
}

/**
* get callData to install validator on ERC7579 Account
*/
function installValidator(
function getInstallValidatorData(
address, /* account */
address validator,
bytes memory initData
)
public
pure
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
callData = abi.encodeCall(
IERC7579Account.installModule, (MODULE_TYPE_VALIDATOR, validator, initData)
);
data = initData;
}

/**
* get callData to uninstall validator on ERC7579 Account
*/
function uninstallValidator(
function getUninstallValidatorData(
address account,
address validator,
bytes memory initData
)
public
view
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
callData = abi.encodeCall(
IERC7579Account.uninstallModule, (MODULE_TYPE_VALIDATOR, validator, initData)
);
data = initData;
}

/**
* get callData to install executor on ERC7579 Account
*/
function installExecutor(
function getInstallExecutorData(
address, /* account */
address executor,
bytes memory initData
)
public
pure
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
callData = abi.encodeCall(
IERC7579Account.installModule, (MODULE_TYPE_EXECUTOR, executor, initData)
);
data = initData;
}

/**
* get callData to uninstall executor on ERC7579 Account
*/
function uninstallExecutor(
function getUninstallExecutorData(
address account,
address executor,
bytes memory initData
)
public
view
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
callData = abi.encodeCall(
IERC7579Account.uninstallModule, (MODULE_TYPE_EXECUTOR, executor, initData)
);
data = initData;
}

/**
* get callData to install hook on ERC7579 Account
*/
function installHook(
function getInstallHookData(
address, /* account */
address hook,
bytes memory initData
)
public
view
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
callData = abi.encodeCall(IERC7579Account.installModule, (MODULE_TYPE_HOOK, hook, initData));
data = initData;
}

/**
* get callData to uninstall hook on ERC7579 Account
*/
function uninstallHook(
function getUninstallHookData(
address, /* account */
address hook,
bytes memory initData
)
public
pure
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
callData =
abi.encodeCall(IERC7579Account.uninstallModule, (MODULE_TYPE_HOOK, hook, initData));
data = initData;
}

/**
* get callData to install fallback on ERC7579 Account
*/
function installFallback(
function getInstallFallbackData(
address, /* account */
address fallbackHandler,
bytes memory initData
)
public
pure
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
callData = abi.encodeCall(
IERC7579Account.installModule, (MODULE_TYPE_FALLBACK, fallbackHandler, initData)
);
data = initData;
}

/**
* get callData to uninstall fallback on ERC7579 Account
*/
function uninstallFallback(
function getUninstallFallbackData(
address, /* account */
address fallbackHandler,
bytes memory initData
)
public
pure
virtual
returns (bytes memory callData)
returns (bytes memory data)
{
fallbackHandler = fallbackHandler; //avoid solhint-no-unused-vars
callData = abi.encodeCall(
IERC7579Account.uninstallModule, (MODULE_TYPE_FALLBACK, fallbackHandler, initData)
);
data = initData;
}

/**
Expand Down Expand Up @@ -359,7 +347,6 @@ abstract contract HelperBase {
address txValidator
)
public
view
virtual
returns (uint256 nonce)
{
Expand Down Expand Up @@ -397,30 +384,50 @@ abstract contract HelperBase {
}

function getInstallModuleData(
AccountInstance memory,
uint256,
address,
AccountInstance memory instance,
uint256 moduleType,
address module,
bytes memory data
)
public
view
virtual
returns (bytes memory)
{
return data;
if (moduleType == MODULE_TYPE_VALIDATOR) {
return getInstallValidatorData(instance.account, module, data);
} else if (moduleType == MODULE_TYPE_EXECUTOR) {
return getInstallExecutorData(instance.account, module, data);
} else if (moduleType == MODULE_TYPE_HOOK) {
return getInstallHookData(instance.account, module, data);
} else if (moduleType == MODULE_TYPE_FALLBACK) {
return getInstallFallbackData(instance.account, module, data);
} else {
revert("Invalid module type");
}
}

function getUninstallModuleData(
AccountInstance memory,
uint256,
address,
AccountInstance memory instance,
uint256 moduleType,
address module,
bytes memory data
)
public
view
virtual
returns (bytes memory)
{
return data;
if (moduleType == MODULE_TYPE_VALIDATOR) {
return getUninstallValidatorData(instance.account, module, data);
} else if (moduleType == MODULE_TYPE_EXECUTOR) {
return getUninstallExecutorData(instance.account, module, data);
} else if (moduleType == MODULE_TYPE_HOOK) {
return getUninstallHookData(instance.account, module, data);
} else if (moduleType == MODULE_TYPE_FALLBACK) {
return getUninstallFallbackData(instance.account, module, data);
} else {
revert("Invalid module type");
}
}
}
Loading
Loading