@@ -88,13 +88,63 @@ contract MinimalAccountTest is Test {
8888 abi.encodeWithSelector (MinimalAccount.execute.selector , dest, value, functionData);
8989
9090 (PackedUserOperation memory packedUserOperation ,) =
91- sendPackedUserOp.generateSignedUserOperation (executeCallData, helperConfig.getConfig ());
91+ sendPackedUserOp.generateSignedUserOperation (executeCallData, helperConfig.getConfig (), address (minimalAccount) );
9292 bytes32 userOperationHash = IEntryPoint (helperConfig.getConfig ().entryPoint).getUserOpHash (packedUserOperation);
9393
9494 address actualSigner = ECDSA.recover (userOperationHash.toEthSignedMessageHash (), packedUserOperation.signature);
9595
9696 assertEq (actualSigner, minimalAccount.owner ());
9797 }
9898
99- // function testValidationOfUserOps() public {}
99+
100+
101+ //1. Sign UserOps
102+ // 2. Call Validate userOps
103+ // 3. Assert the return is correct
104+ //
105+ function testValidationOfUserOps () public {
106+ assertEq (usdc.balanceOf (address (minimalAccount)), 0 );
107+ address dest = address (usdc);
108+ uint256 value = 0 ;
109+ bytes memory functionData = abi.encodeWithSelector (ERC20Mock .mint.selector , address (minimalAccount), AMOUNT);
110+
111+ bytes memory executeCallData =
112+ abi.encodeWithSelector (MinimalAccount.execute.selector , dest, value, functionData);
113+
114+ (PackedUserOperation memory packedUserOperation ,) =
115+ sendPackedUserOp.generateSignedUserOperation (executeCallData, helperConfig.getConfig (), address (minimalAccount));
116+ bytes32 userOperationHash = IEntryPoint (helperConfig.getConfig ().entryPoint).getUserOpHash (packedUserOperation);
117+ uint256 missingAccountFunds = 1e18 ;
118+ // ACT
119+ vm.prank (helperConfig.getConfig ().entryPoint);
120+ uint256 validationData = minimalAccount.validateUserOp (packedUserOperation,userOperationHash,missingAccountFunds);
121+ assertEq (validationData,0 );
122+
123+ }
124+
125+
126+ function testEntryPointCanExecuteCommands () public {
127+ assertEq (usdc.balanceOf (address (minimalAccount)), 0 );
128+ address dest = address (usdc);
129+ uint256 value = 0 ;
130+ bytes memory functionData = abi.encodeWithSelector (ERC20Mock .mint.selector , address (minimalAccount), AMOUNT);
131+
132+ bytes memory executeCallData =
133+ abi.encodeWithSelector (MinimalAccount.execute.selector , dest, value, functionData);
134+
135+ (PackedUserOperation memory packedUserOperation ,) =
136+ sendPackedUserOp.generateSignedUserOperation (executeCallData, helperConfig.getConfig (), address (minimalAccount));
137+ // bytes32 userOperationHash = IEntryPoint(helperConfig.getConfig().entryPoint).getUserOpHash(packedUserOperation);
138+ // uint256 missingAccountFunds = 1e18;
139+
140+ PackedUserOperation[] memory ops = new PackedUserOperation [](1 );
141+ ops[0 ] = packedUserOperation;
142+ // ACT
143+ vm.deal (address (minimalAccount),1e18 );
144+ vm.prank (randomUser);
145+ IEntryPoint (helperConfig.getConfig ().entryPoint).handleOps (ops,payable (randomUser));
146+
147+ //Assert
148+ assertEq (usdc.balanceOf (address (minimalAccount)), AMOUNT);
149+ }
100150}
0 commit comments