Skip to content

Commit

Permalink
Bring over custom errors definitions for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Dec 23, 2024
1 parent 6680f8c commit 7ec3998
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
48 changes: 48 additions & 0 deletions contracts/test/TestPaymasterRevertCustomError.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.23;

import "@account-abstraction/contracts/core/BasePaymaster.sol";

/**
* test postOp revert with custom error
*/
error CustomError(string customReason);

contract TestPaymasterRevertCustomError is BasePaymaster {
bytes32 private constant INNER_OUT_OF_GAS = hex"deaddead";

enum RevertType {
customError,
entryPointError
}

RevertType private revertType;

// solhint-disable no-empty-blocks
constructor(IEntryPoint _entryPoint) BasePaymaster(_entryPoint)
{}

function _validatePaymasterUserOp(PackedUserOperation calldata userOp, bytes32, uint256)
internal virtual override view
returns (bytes memory context, uint256 validationData) {
validationData = 0;
context = abi.encodePacked(userOp.sender);
}

function setRevertType(RevertType _revertType) external {
revertType = _revertType;
}

function _postOp(PostOpMode, bytes calldata, uint256, uint256) internal view override {
if (revertType == RevertType.customError){
revert CustomError("this is a long revert reason string we are looking for");
}
else if (revertType == RevertType.entryPointError){
// solhint-disable-next-line no-inline-assembly
assembly {
mstore(0, INNER_OUT_OF_GAS)
revert(0, 32)
}
}
}
}
9 changes: 6 additions & 3 deletions test/testutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import {
} from 'ethers/lib/utils'
import { BigNumber, BigNumberish, Contract, ContractReceipt, Signer, Wallet } from 'ethers'
import {
EntryPoint__factory,
IERC20,
SimpleAccount,
SimpleAccountFactory,
SimpleAccountFactory__factory,
SimpleAccount__factory,
SimpleAccountFactory, EntryPoint__factory
TestERC20__factory,
TestPaymasterRevertCustomError__factory
} from '../typechain'
import { BytesLike, Hexable } from '@ethersproject/bytes'
// import { JsonRpcProvider } from '@ethersproject/providers'
Expand Down Expand Up @@ -162,8 +165,8 @@ export function rethrow (): (e: Error) => void {

const decodeRevertReasonContracts = new Interface([
...EntryPoint__factory.createInterface().fragments,
// ...TestPaymasterRevertCustomError__factory.createInterface().fragments,
// ...TestERC20__factory.createInterface().fragments, // for OZ errors,
...TestPaymasterRevertCustomError__factory.createInterface().fragments,
...TestERC20__factory.createInterface().fragments, // for OZ errors,
'error ECDSAInvalidSignature()'
]) // .filter(f => f.type === 'error'))

Expand Down

0 comments on commit 7ec3998

Please sign in to comment.