Suggestion: add note for overloaded "initialize" function

It seems quite common to end up with multiple “initialize” functions when inheriting from OpenZeppelin, especially now with the advent of GSN.

I’m using truffle and I discovered I was not able to call the exact “initialize” function I wanted using the standard @truffle/contract api. This was due to a problem explained by gnidan in this GitHub thread.

I think it would be nice to add a red flag in the docs for those OpenZeppelin contracts that are highly likely to cause this issue with function overloading (Ownable, GSNRecipient, GSNBouncerSignature, etc).

1 Like

Hi @PaulRBerg,

I wanted to reproduce the issue. Were you calling initialize function in testing using Truffle or somewhere else?

Do you have any code to show the issue? (Otherwise I was going to use the code below).

Do you think this flag needs to be in the API documentation for those contracts, or is there somewhere specific that you think would be useful?

pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/Initializable.sol";

// Import interface and library from OpenZeppelin contracts
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/GSN/bouncers/GSNBouncerSignature.sol";

contract Counter is Initializable, Ownable, GSNRecipient, GSNBouncerSignature {
  uint256 public value;

  function increase() public {
    value++;
  }

  function initialize(address owner) initializer public {
      Ownable.initialize(owner);
      GSNBouncerSignature.initialize(owner);
  }
}

Yeah it’s weird so I tried to reproduce it in this repo: https://github.com/PaulRBerg/truffle-oz-overload

But the 2nd test in there doesn’t fail.

In sablier, in the payroll package, I had to use this quirky api to make it work:

await this.payroll.methods["initialize(address,address,address)"](ownerAddress, signerAddress, sablierAddress, opts);
1 Like

Hi @PaulRBerg,

I thought that specifying the function signature was the only way in truffle to call an overloaded function (from Truffle 5 onwards, prior to that calling overloaded functions wasn’t supported).

I haven’t been able to reproduce the issue, so not sure what we can add to the documentation. Let me know if you have more thoughts on this.