// SPDX-License-Identifier: GNU GPLv3 pragma solidity 0.8.17; import {PRBTest} from "@prb/test/PRBTest.sol"; contract RevertWithString { function sampleRevert(uint256 amount) external pure { require(amount > 10, "Not enough amount"); } } contract RevertWithError { error NotEnoughAmount(); function sampleRevert(uint256 amount) external pure { if (amount < 10) revert NotEnoughAmount(); } } contract RevertWithErrorAssembly { /// @dev 'bytes4(keccak256("NotEnoughAmount()"))' uint256 private constant _NOT_ENOUGH_AMOUNT_SELECTOR = 0xe008b5f9; function sampleRevert(uint256 amount) external pure { assembly { if lt(amount, 10) { mstore(0x00, _NOT_ENOUGH_AMOUNT_SELECTOR) revert(0x1c, 0x04) } } } } /// Testing revert gas cost handling contract RevertGasUsageTest is PRBTest { RevertWithString testStringContract; RevertWithError testErrorContract; RevertWithErrorAssembly testErrorAssemblyContract; function setUp() public { testStringContract = new RevertWithString(); testErrorContract = new RevertWithError(); testErrorAssemblyContract = new RevertWithErrorAssembly(); } function testFail_RevertWithString() public view { testStringContract.sampleRevert(1); } function testFail_RevertWithError() public view { testErrorContract.sampleRevert(1); } function testFail_RevertWithErrorAssembly() public view { testErrorAssemblyContract.sampleRevert(1); } }