22pragma solidity ^ 0.8.0 ;
33
44import "src/Kernel.sol " ;
5+ import "src/factory/KernelFactory.sol " ;
56import "forge-std/Test.sol " ;
67import "src/mock/MockValidator.sol " ;
78import "src/mock/MockPolicy.sol " ;
@@ -13,34 +14,6 @@ import "src/mock/MockFallback.sol";
1314import "src/core/ValidationManager.sol " ;
1415import "./erc4337Util.sol " ;
1516
16- contract SimpleProxy {
17- bytes32 constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc ;
18-
19- constructor (address _target ) {
20- assembly {
21- sstore (IMPLEMENTATION_SLOT, _target)
22- }
23- }
24-
25- function _getImplementation () internal view returns (address target ) {
26- bytes32 slot = IMPLEMENTATION_SLOT;
27- assembly {
28- target := sload (slot)
29- }
30- }
31-
32- receive () external payable {
33- (bool success ,) = _getImplementation ().delegatecall ("" );
34- require (success, "delegatecall failed " );
35- }
36-
37- fallback (bytes calldata ) external payable returns (bytes memory ) {
38- (bool success , bytes memory ret ) = _getImplementation ().delegatecall (msg .data );
39- require (success, "delegatecall failed " );
40- return ret;
41- }
42- }
43-
4417contract MockCallee {
4518 uint256 public value;
4619
@@ -51,6 +24,7 @@ contract MockCallee {
5124
5225abstract contract KernelTestBase is Test {
5326 Kernel kernel;
27+ KernelFactory factory;
5428 IEntryPoint entrypoint;
5529 ValidationId rootValidation;
5630
@@ -88,22 +62,36 @@ abstract contract KernelTestBase is Test {
8862 // todo selectorData
8963
9064 modifier whenInitialized () {
91- kernel.initialize (
92- rootValidation, rootValidationConfig.hook, rootValidationConfig.validatorData, rootValidationConfig.hookData
65+ bytes memory initData = abi.encodeWithSelector (
66+ Kernel.initialize.selector ,
67+ rootValidation,
68+ rootValidationConfig.hook,
69+ rootValidationConfig.validatorData,
70+ rootValidationConfig.hookData
9371 );
72+ address deployed = factory.createAccount (initData, bytes32 (0 ));
73+ assertEq (deployed, address (kernel));
9474 assertEq (kernel.currentNonce (), 1 );
9575 _;
9676 }
9777
9878 function setUp () public {
9979 entrypoint = IEntryPoint (EntryPointLib.deploy ());
10080 Kernel impl = new Kernel (entrypoint);
81+ factory = new KernelFactory (address (impl));
10182 callee = new MockCallee ();
102- kernel = Kernel (payable (address (new SimpleProxy (address (impl)))));
10383 mockHook = new MockHook ();
10484 _setRootValidationConfig ();
10585 _setEnableValidatorConfig ();
10686 _setEnablePermissionConfig ();
87+ bytes memory initData = abi.encodeWithSelector (
88+ Kernel.initialize.selector ,
89+ rootValidation,
90+ rootValidationConfig.hook,
91+ rootValidationConfig.validatorData,
92+ rootValidationConfig.hookData
93+ );
94+ kernel = Kernel (payable (factory.getAddress (initData, bytes32 (0 ))));
10795 }
10896
10997 // things to override on test
@@ -133,20 +121,6 @@ abstract contract KernelTestBase is Test {
133121 permissionConfig.signerData = "signer " ;
134122 }
135123
136- // kernel initialize scenario
137- function testInitialize () external {
138- ValidationId vId = ValidatorLib.validatorToIdentifier (mockValidator);
139-
140- kernel.initialize (vId, IHook (address (0 )), hex "" , hex "" );
141- assertTrue (kernel.rootValidator () == vId);
142- ValidationManager.ValidationConfig memory config;
143- config = kernel.validationConfig (vId);
144- assertEq (config.nonce, 1 );
145- assertEq (address (config.hook), address (1 ));
146- assertEq (mockValidator.isInitialized (address (kernel)), true );
147- assertEq (kernel.currentNonce (), 1 );
148- }
149-
150124 // root validator cases
151125 function _rootValidatorFailurePreCondition () internal virtual {
152126 mockValidator.sudoSetSuccess (false );
@@ -173,7 +147,7 @@ abstract contract KernelTestBase is Test {
173147 assertEq (0 , callee.value ());
174148 }
175149
176- function getRootSignature (bytes32 hash ) internal returns (bytes memory ) {
150+ function getRootSignature (bytes32 hash ) internal returns (bytes memory ) {
177151 return abi.encodePacked ("rootSig " , hash);
178152 }
179153
@@ -308,7 +282,7 @@ abstract contract KernelTestBase is Test {
308282 abi.encodePacked (kernel.execute.selector ),
309283 getEnableSig (bytes32 (0 ), true ),
310284 getValidatorSig (op, true )
311- )
285+ )
312286 });
313287 }
314288
@@ -338,7 +312,7 @@ abstract contract KernelTestBase is Test {
338312 abi.encodePacked (kernel.execute.selector ),
339313 getEnableSig (bytes32 (0 ), true ),
340314 getPermissionSig (op, true )
341- )
315+ )
342316 });
343317 }
344318
0 commit comments