Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
leekt committed Jun 3, 2024
1 parent 4e7ee0e commit a38a8fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
18 changes: 11 additions & 7 deletions src/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
}
}

function initialize(ValidationId _rootValidator, IHook hook, bytes calldata validatorData, bytes calldata hookData, bytes[] calldata initConfig)
external
{
function initialize(
ValidationId _rootValidator,
IHook hook,
bytes calldata validatorData,
bytes calldata hookData,
bytes[] calldata initConfig
) external {
ValidationStorage storage vs = _validationStorage();
require(ValidationId.unwrap(vs.rootValidator) == bytes21(0), "already initialized");
if (ValidationId.unwrap(_rootValidator) == bytes21(0)) {
Expand All @@ -109,9 +113,9 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
ValidationConfig memory config = ValidationConfig({nonce: uint32(1), hook: hook});
vs.currentNonce = 1;
_installValidation(_rootValidator, config, validatorData, hookData);
for(uint256 i = 0; i<initConfig.length; i++) {
(bool success, ) = address(this).call(initConfig[i]);
if(!success) {
for (uint256 i = 0; i < initConfig.length; i++) {
(bool success,) = address(this).call(initConfig[i]);
if (!success) {
revert InitConfigError(i);
}
}
Expand Down Expand Up @@ -367,7 +371,7 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
selectorData.length := calldataload(sub(selectorData.offset, 32))
}
_installValidation(vId, config, validatorData, hookData);
if(selectorData.length == 4) {
if (selectorData.length == 4) {
// NOTE: we don't allow configure on selector data on v3.1, but using bytes instead of bytes4 for selector data to make sure we are future proof
_setSelector(vId, bytes4(selectorData[0:4]), true);
}
Expand Down
29 changes: 8 additions & 21 deletions src/sdk/KernelTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -339,25 +339,16 @@ abstract contract KernelTestBase is Test {
bytes[] memory configs = new bytes[](1);
MockValidator mv = new MockValidator();
configs[0] = abi.encodeWithSelector(
Kernel.installModule.selector,
1,
address(mv),
abi.encodePacked(
address(0),
abi.encode(
hex"",
hex"",
hex""
)
)
Kernel.installModule.selector, 1, address(mv), abi.encodePacked(address(0), abi.encode(hex"", hex"", hex""))
);
initConfig = configs;
kernel = Kernel(payable(factory.getAddress(initData(), bytes32(0))));
address deployed = factory.createAccount(initData(), bytes32(0));
assertEq(deployed, address(kernel));
assertEq(kernel.currentNonce(), 1);
assertEq(ValidationId.unwrap(kernel.rootValidator()), ValidationId.unwrap(rootValidation));
ValidationManager.ValidationConfig memory config = kernel.validationConfig(ValidatorLib.validatorToIdentifier(mv));
ValidationManager.ValidationConfig memory config =
kernel.validationConfig(ValidatorLib.validatorToIdentifier(mv));
assertEq(config.nonce, 1);
assertEq(address(config.hook), address(1));
}
Expand Down Expand Up @@ -699,7 +690,7 @@ abstract contract KernelTestBase is Test {
abi.encode(
hex"", // validator data
hex"", // hook data
hex"" // selector data
hex"" // selector data
)
)
),
Expand All @@ -708,20 +699,15 @@ abstract contract KernelTestBase is Test {
);
entrypoint.handleOps(ops, payable(address(0xdeadbeef)));
}

function _uninstallValidator(IValidator validator) internal {
vm.deal(address(kernel), 1e18);
PackedUserOperation[] memory ops = new PackedUserOperation[](1);
ops[0] = _prepareUserOp(
VALIDATION_TYPE_ROOT,
false,
false,
abi.encodeWithSelector(
kernel.uninstallModule.selector,
1,
address(validator),
hex""
),
abi.encodeWithSelector(kernel.uninstallModule.selector, 1, address(validator), hex""),
true,
true
);
Expand All @@ -731,7 +717,8 @@ abstract contract KernelTestBase is Test {
function testValidatorInstall() external whenInitialized {
MockValidator mv = new MockValidator();
_installValidator(mv);
ValidationManager.ValidationConfig memory config = kernel.validationConfig(ValidatorLib.validatorToIdentifier(mv));
ValidationManager.ValidationConfig memory config =
kernel.validationConfig(ValidatorLib.validatorToIdentifier(mv));
assertEq(config.nonce, 1);
assertEq(address(config.hook), address(1));
_uninstallValidator(mv);
Expand Down

0 comments on commit a38a8fb

Please sign in to comment.