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.