Testing Governor contract in HardHat -vs- Remix

Hi - I've got an instance of Governor.sol, a timelock controller & an ERC20 deployed on Rinkeby and am gearing up for my 'real' deployment to Polygon. Even tho the contracts are 100% unchanged from what the wizard makes, because of all the configs that are possible, I'm going to compile a testscript in hardhat to make sure my configs do what I expect. So... I brought the 3 contracts into a hardhat project & did an npm install of OZ contracts. So far, so good! But it won't compile - it's saying something is amiss with Governor.sol.

As another test, I dropped the contracts into Remix & everything compiles there. Huh... I'm wondering if anybody has any insight as to what could be wrong in hardhat. It doesn't look like a dependency issue from node or anything. It's specifically saying the Governor contract itself has issues:

TypeError: Function needs to specify overridden contract "Governor".
--> contracts/DDAOGov.sol:52:9:
|
52 | override(IGovernor, GovernorVotes)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: This contract:
--> @openzeppelin/contracts/governance/Governor.sol:29:1:
|
29 | abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receiver, IERC1155Receiver {
| ^ (Relevant source part starts here and spans across multiple lines).

TypeError: Invalid contract specified in override list: "GovernorVotes".
--> contracts/DDAOGov.sol:52:9:
|
52 | override(IGovernor, GovernorVotes)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: This contract:
--> @openzeppelin/contracts/governance/extensions/GovernorVotes.sol:14:1:
|
14 | abstract contract GovernorVotes is Governor {
| ^ (Relevant source part starts here and spans across multiple lines).

Any ideas on what could cause this would be helpful. The contracts were generated by the Wizard & the npm install of OZ contracts were all done on 5/1/22. Thanks
Chris

Still hoping for help from someone at OZ. the contracts I'm using are 100% from the Wizard and I'm getting a compile error. I was able to get around it by changing the getVotes function to override (Governor, IGovernor) instead of the wizard generated: override(IGovernor, GovernorVotes).
But this brings up 2 things:
1st) HardHat is now warning me:

Contract code size exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable
on mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.

2nd) Am I overriding the wrong thing here? Am I screwing up the world? I need some guidance - I'm not sure what I'm supposed to do here - sounds like this may not be my issue but an OZ bug. Or something silly with hardhat. I'm wondering what other's opinions might be. Thanks!

Hi @chrisb, the Wizard was recently updated to support Contracts v4.6.0 and the getVotes function was removed as part of that PR. (The version that you used was probably targeting v4.5.x).

If you could try generating the code from Wizard again, it should compile now. Sorry for the inconvenience.

For the code size issue, have you tried enabling the optimizer?

Eric - thank you! Good to know I'm not crazy - I sometimes think so as I travel on this steep web3 development learning curve. I'll grab new wizard generated contracts today. -- peace!
Chris

1 Like