ModuleKit
Testing
Simulating UserOps

How to use ModuleKit to test ERC-4337 restrictions

The ModuleKit is integrated with the ERC-4337 Validation library in order to make it effortless to ensure modules comply with the restrictions required by the ERC-4337 mempool. You can find the restrictions in the ERC-7562 specifications (opens in a new tab). Note: alternatively to the below, you can also use the simulateUserOp function to simulate only specific UserOperations.

Write your tests

When you write your tests, you can use the makeAccountInstance function to create an account instance. Then, you can use this instance to execute transactions, for example:

// Create an account instance
AccountInstance memory instance = makeAccountInstance("account1");
 
// Execute a UserOperation on the account
instance.exec({ target: address(1), value: 1 wei, callData: "" });

Run your tests with simulation

To do this, run:

SIMULATE=true forge test

If your tests are successful, you are compliant with the ERC-4337 restrictions. Otherwise, you will receive an error message.

Note that we do not yet test the banned opcodes restrictions, but we will add this feature soon.