Skip to main content
Notice removed Draw attention by CommunityBot
Bounty Ended with tenbits's answer chosen by CommunityBot
added code block
Source Link
Zartaj Afser
  • 4.3k
  • 2
  • 13
  • 33

I am trying to test TimelockController contract from Openzeppelin using their test.

The timelockController imports Address.sol, which has a custom Error called FailedCall. Now for my case, I have created my own TimelockController just by inheriting this OZ TimelockController.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol"; contract PushTimelockController is TimelockControllerUpgradeable { function initialize( uint256 minDelay, address[] memory proposers, address[] memory executors, address admin ) public initializer { __TimelockController_init(minDelay, proposers, executors, admin); } } 

The problem now is while expecting some functions to revert with custom error FailedCall using this syntax:

await expect( this.mock .connect(this.executor) .executeBatch( operation.targets, operation.values, operation.payloads, operation.predecessor, operation.salt, ), ).to.be.revertedWithCustomError(this.mock, 'FailedCall'); }) 

where this.mock is the PushTimelockController, hardhat is unable to locate the custom error, throwing this error:

Error: The given contract doesn't have a custom error named 'FailedCall' 

This might be because my PushTimelockController is inheriting TimelockController which is again inheriting fromusing Address.sol, and hardhat is unable to read the custom errors defined in Address.sol.

What can be a workaround? Do I need to get a contract instance of Address.sol just for the errors or is there any other way?

I am trying to test TimelockController contract from Openzeppelin using their test.

The timelockController imports Address.sol, which has a custom Error called FailedCall. Now for my case, I have created my own TimelockController just by inheriting this OZ TimelockController.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol"; contract PushTimelockController is TimelockControllerUpgradeable { function initialize( uint256 minDelay, address[] memory proposers, address[] memory executors, address admin ) public initializer { __TimelockController_init(minDelay, proposers, executors, admin); } } 

The problem now is while expecting some functions to revert with custom error FailedCall using this syntax:

await expect( this.mock .connect(this.executor) .executeBatch( operation.targets, operation.values, operation.payloads, operation.predecessor, operation.salt, ), ).to.be.revertedWithCustomError(this.mock, 'FailedCall'); }) 

where this.mock is the PushTimelockController, hardhat is unable to locate the custom error, throwing this error:

Error: The given contract doesn't have a custom error named 'FailedCall' 

This might be because my PushTimelockController is inheriting TimelockController which is again inheriting from Address.sol, and hardhat is unable to read the custom errors defined in Address.sol.

What can be a workaround? Do I need to get a contract instance of Address.sol just for the errors or is there any other way?

I am trying to test TimelockController contract from Openzeppelin using their test.

The timelockController imports Address.sol, which has a custom Error called FailedCall. Now for my case, I have created my own TimelockController just by inheriting this OZ TimelockController.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol"; contract PushTimelockController is TimelockControllerUpgradeable { function initialize( uint256 minDelay, address[] memory proposers, address[] memory executors, address admin ) public initializer { __TimelockController_init(minDelay, proposers, executors, admin); } } 

The problem now is while expecting some functions to revert with custom error FailedCall using this syntax:

await expect( this.mock .connect(this.executor) .executeBatch( operation.targets, operation.values, operation.payloads, operation.predecessor, operation.salt, ), ).to.be.revertedWithCustomError(this.mock, 'FailedCall'); }) 

where this.mock is the PushTimelockController, hardhat is unable to locate the custom error, throwing this error:

Error: The given contract doesn't have a custom error named 'FailedCall' 

This might be because my PushTimelockController is inheriting TimelockController which is using Address.sol, and hardhat is unable to read the custom errors defined in Address.sol.

What can be a workaround? Do I need to get a contract instance of Address.sol just for the errors or is there any other way?

Notice added Draw attention by Zartaj Afser
Bounty Started worth 50 reputation by Zartaj Afser
Source Link
Zartaj Afser
  • 4.3k
  • 2
  • 13
  • 33

Hardhat doesn't recognize custom errors from inherited Contracts

I am trying to test TimelockController contract from Openzeppelin using their test.

The timelockController imports Address.sol, which has a custom Error called FailedCall. Now for my case, I have created my own TimelockController just by inheriting this OZ TimelockController.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol"; contract PushTimelockController is TimelockControllerUpgradeable { function initialize( uint256 minDelay, address[] memory proposers, address[] memory executors, address admin ) public initializer { __TimelockController_init(minDelay, proposers, executors, admin); } } 

The problem now is while expecting some functions to revert with custom error FailedCall using this syntax:

await expect( this.mock .connect(this.executor) .executeBatch( operation.targets, operation.values, operation.payloads, operation.predecessor, operation.salt, ), ).to.be.revertedWithCustomError(this.mock, 'FailedCall'); }) 

where this.mock is the PushTimelockController, hardhat is unable to locate the custom error, throwing this error:

Error: The given contract doesn't have a custom error named 'FailedCall' 

This might be because my PushTimelockController is inheriting TimelockController which is again inheriting from Address.sol, and hardhat is unable to read the custom errors defined in Address.sol.

What can be a workaround? Do I need to get a contract instance of Address.sol just for the errors or is there any other way?