Skip to content

Commit

Permalink
Merge pull request #140 from rhinestonewtf/fix/simulation-revert
Browse files Browse the repository at this point in the history
Fix/simulation revert
  • Loading branch information
kopy-kat authored Aug 15, 2024
2 parents 2b81e80 + 258b5df commit ab2ece9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test": "forge test",
"test:lite": "FOUNDRY_PROFILE=lite forge test",
"test:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge test",
"test:accounts": "forge test && ACCOUNT_TYPE=SAFE forge test && ACCOUNT_TYPE=KERNEL forge test",
"test:accounts": "forge test && ACCOUNT_TYPE=SAFE forge test && ACCOUNT_TYPE=KERNEL forge test && ACCOUNT_TYPE=NEXUS forge test",
"changeset": "changeset",
"changeset:release": "pnpm build && changeset publish",
"changeset:version": "changeset version && pnpm install --lockfile-only"
Expand All @@ -30,7 +30,7 @@
"@ERC4337/account-abstraction": "github:kopy-kat/account-abstraction#develop",
"@ERC4337/account-abstraction-v0.6": "github:eth-infinitism/account-abstraction#v0.6.0",
"@prb/math": "^4.0.2",
"@rhinestone/erc4337-validation": "^0.0.1-alpha.4",
"@rhinestone/erc4337-validation": "^0.0.1-alpha.5",
"@rhinestone/module-bases": "github:rhinestonewtf/module-bases",
"@rhinestone/safe7579": "github:rhinestonewtf/safe7579#v1.0.0",
"@rhinestone/sentinellist": "github:rhinestonewtf/sentinellist",
Expand Down
42 changes: 15 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/test/helpers/KernelHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ contract KernelHelpers is HelperBase {
address txValidator
)
internal
deployAccountForAction(instance)
{
ValidationId vId = ValidatorLib.validatorToIdentifier(IValidator(txValidator));
bytes4 selector;
Expand Down
9 changes: 7 additions & 2 deletions src/test/utils/ERC4337Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ library ERC4337Helpers {
);

function exec4337(PackedUserOperation[] memory userOps, IEntryPoint onEntryPoint) internal {
uint256 isExpectRevert = getExpectRevert();

// ERC-4337 specs validation
if (envOr("SIMULATE", false) || getSimulateUserOp()) {
userOps[0].simulateUserOp(address(onEntryPoint));
bool simulationSuccess = userOps[0].simulateUserOp(address(onEntryPoint));

if (isExpectRevert == 0) {
require(simulationSuccess, "UserOperation simulation failed");
}
}
// Record logs to determine if a revert happened
recordLogs();
Expand All @@ -41,7 +47,6 @@ library ERC4337Helpers {
bytes memory userOpCalldata = abi.encodeCall(IEntryPoint.handleOps, (userOps, beneficiary));
(bool success,) = address(onEntryPoint).call(userOpCalldata);

uint256 isExpectRevert = getExpectRevert();
if (isExpectRevert == 0) {
require(success, "UserOperation execution failed");
}
Expand Down
46 changes: 45 additions & 1 deletion test/Diff.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
CALLTYPE_SINGLE
} from "src/external/ERC7579.sol";
import { getAccountType } from "src/test/utils/Storage.sol";
import { toString } from "src/test/utils/Vm.sol";

contract ERC7579DifferentialModuleKitLibTest is BaseTest {
using ModuleKitHelpers for *;
Expand Down Expand Up @@ -102,6 +101,51 @@ contract ERC7579DifferentialModuleKitLibTest is BaseTest {
assertEq(receiver.balance, value, "Receiver should have 10 gwei");
}

function testexec__RevertWhen__ValidationFails() public {
// Create userOperation fields
address receiver = makeAddr("receiver");
uint256 value = 10 gwei;
bytes memory callData = "";

// Create userOperation
instance.expect4337Revert();
// Create userOperation
instance.getExecOps({
target: receiver,
value: value,
callData: callData,
txValidator: makeAddr("invalidValidator")
}).execUserOps();
}

function testexec__RevertWhen__ValidationReverts() public {
address revertingValidator = makeAddr("revertingValidator");
vm.etch(revertingValidator, address(validator).code);

instance.installModule({
moduleTypeId: MODULE_TYPE_VALIDATOR,
module: revertingValidator,
data: ""
});

vm.etch(revertingValidator, hex"fd");

// Create userOperation fields
address receiver = makeAddr("receiver");
uint256 value = 10 gwei;
bytes memory callData = "";

// Create userOperation
instance.expect4337Revert();
// Create userOperation
instance.getExecOps({
target: receiver,
value: value,
callData: callData,
txValidator: revertingValidator
}).execUserOps();
}

function testexec__RevertWhen__UserOperationFails() public {
// Create userOperation fields
bytes memory callData = abi.encodeWithSelector(MockTarget.setAccessControl.selector, 2);
Expand Down

0 comments on commit ab2ece9

Please sign in to comment.