From 7ec3998518b884a3d8f78d15be42b5f67f2b71a9 Mon Sep 17 00:00:00 2001 From: Alex Forshtat Date: Mon, 23 Dec 2024 20:39:26 +0100 Subject: [PATCH] Bring over custom errors definitions for tests --- .../test/TestPaymasterRevertCustomError.sol | 48 +++++++++++++++++++ test/testutils.ts | 9 ++-- 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 contracts/test/TestPaymasterRevertCustomError.sol diff --git a/contracts/test/TestPaymasterRevertCustomError.sol b/contracts/test/TestPaymasterRevertCustomError.sol new file mode 100644 index 0000000..6b634e0 --- /dev/null +++ b/contracts/test/TestPaymasterRevertCustomError.sol @@ -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) + } + } + } +} diff --git a/test/testutils.ts b/test/testutils.ts index bbbf47d..542a42b 100644 --- a/test/testutils.ts +++ b/test/testutils.ts @@ -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' @@ -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'))