0

contract1.sol:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

abstract contract Contract1 {
    error Error1(address account);
}

contract2.sol:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Contract1} from "./contract1.sol";

contract Contract2 is Contract1 {    
    error Error2(address account);

    function customError1() public view {
        revert Error1(msg.sender);
    }

    function customError2() public view {
        revert Error2(msg.sender);
    }
}

test script:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {Contract2} from "../src/contract2.sol";

contract ErrorTest is Test {
    Contract2 public contract2;

    function setUp() public {
        contract2 = new Contract2();
    }

    function test_customError1() public {
        vm.expectRevert(abi.encodeWithSelector(Contract2.Error1.selector, msg.sender));
        vm.prank(address(123));
        contract2.customError1();
    }

    function test_customError2() public {
        vm.expectRevert(abi.encodeWithSelector(Contract2.Error2.selector, msg.sender));
        vm.prank(address(123));
        contract2.customError2();
    }
}

Error Message:

Error: 
Compiler run failed:
Error (9582): Member "Error1" not found or not visible after argument-dependent lookup in type(contract Contract2).
  --> test/test.t.sol:15:48:
   |
15 |         vm.expectRevert(abi.encodeWithSelector(Contract2.Error1.selector, msg.sender));
   |                                           

Test for error 2 is OK, but not for error 1. Please assist. Thank you for your time.

1 Answer 1

1

Just "import contract1" and use "contract1.Error1" will be able to solve this issue.

2
  • Yeah seeing this now. That's great. I've deleted my answer, so as to avoid any confusion. Thanks. Commented Mar 19 at 6:54
  • 1
    Thank you for your help, man. Commented Mar 19 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.