Skip to content

Commit

Permalink
lint: Ignore solhint issues for mock contracts
Browse files Browse the repository at this point in the history
Most of these issues are intentional and are okay to ignore. This also
sets the solhint ignoreConstructors option to true for the
func-visibility rule, as we are using solidity >=0.7.0
  • Loading branch information
drklee3 committed Oct 10, 2024
1 parent 0f248d2 commit 8a90bbc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
5 changes: 4 additions & 1 deletion tests/e2e-evm/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "solhint:recommended"
"extends": "solhint:recommended",
"rules": {
"func-visibility": ["warn", { "ignoreConstructors": true }]
}
}
15 changes: 11 additions & 4 deletions tests/e2e-evm/contracts/ABI_BasicTests.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ contract Caller {
(bool success, bytes memory result) = to.call{value: msg.value}(data);

if (!success) {
if (result.length == 0) revert();
// solhint-disable-next-line gas-custom-errors
if (result.length == 0) revert("reverted with no reason");

// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, result), mload(result))
}
Expand All @@ -24,11 +26,14 @@ contract Caller {
// TODO: Callcode

function functionDelegateCall(address to, bytes calldata data) external {
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = to.delegatecall(data);

if (!success) {
if (result.length == 0) revert();
// solhint-disable-next-line gas-custom-errors
if (result.length == 0) revert("reverted with no reason");

// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, result), mload(result))
}
Expand All @@ -39,8 +44,10 @@ contract Caller {
(bool success, bytes memory result) = to.staticcall(data);

if (!success) {
if (result.length == 0) revert();
// solhint-disable-next-line gas-custom-errors
if (result.length == 0) revert("reverted with no reason");

// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, result), mload(result))
}
Expand All @@ -52,7 +59,7 @@ contract Caller {
// High level caller
//
contract NoopCaller {
NoopNoReceiveNoFallback target;
NoopNoReceiveNoFallback private target;

constructor(NoopNoReceiveNoFallback _target) {
target = _target;
Expand Down
19 changes: 10 additions & 9 deletions tests/e2e-evm/contracts/ABI_DisabledTests.sol
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "./ABI_BasicTests.sol";
import "./ABI_BasicTests.sol" as ABI_BasicTests;

//
// Disabled contract that is payable and callable with any calldata (receive + fallback)
//
contract NoopDisabledMock is NoopReceivePayableFallback{
contract NoopDisabledMock is ABI_BasicTests.NoopReceivePayableFallback {
// solc-ignore-next-line func-mutability
function noopNonpayable() external {
mockRevert();
mockRevert();
}
function noopPayable() external payable {
mockRevert();
mockRevert();
}
// solc-ignore-next-line func-mutability
function noopView() external view {
mockRevert();
mockRevert();
}
function noopPure() external pure {
mockRevert();
mockRevert();
}
receive() external payable {
mockRevert();
mockRevert();
}
fallback() external payable {
mockRevert();
mockRevert();
}

//
// Mimic revert + revert reason
//
function mockRevert() private pure {
revert("call not allowed to disabled contract");
// solhint-disable-next-line reason-string, gas-custom-errors
revert("call not allowed to disabled contract");
}
}

0 comments on commit 8a90bbc

Please sign in to comment.