Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests/e2e-evm): Restructure ABI tests for extensibility & reduce duplication #2031

Open
wants to merge 11 commits into
base: nd-implement-basic-precompile-calling
Choose a base branch
from
Open
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 }]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tyty I did not know about this configuration

}
}
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice reduction in scope 👍


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");
}
}
Loading
Loading