Write test cases for modifier

Hi Team,
Is there any way to test the contract modifiers in the hardhat development env.

Please guide.

Thanks.

You need to define an auxiliary contract that uses the modifiers, and then test against this contract.

@frangio thanks for the revert.
do you have any sample references for the Auxiliary Contract?

For example in order to test the modifier onlyOwner you could define a contract like:

contract TestOwnable {
  function withOnlyOwner() public onlyOwner {}
}

And then in your tests you can create an instance of this contract and invoke the function.

1 Like

@frangio thanks, but keeping this non-functional, does it make sense?

Not sure if I understand the question.