Problem as sometimes initialize() can't be called

Hello @nventuro,

Yes sorry…

I will describe the scenario:

State 1
Let’s say everything is going well, I run oz create
I get something like

All contracts have been deployed
? Do you want to call a function on the instance after creating
 it? Yes
? Select which function (Use arrow keys)
❯   * initialize()
  * initialize(name: string, symbol: string)
* initialize(sender: address) 

(note the order, initialize() is first)

I run my truffle tests & even beyond that everything works fine.

State 2
I have made some minor changes like adding a function at the end of the contract.
If I don’t oz upgradeI usually clean up everything (artifacts & co) rm build/contracts/* .openzeppelin/dev-*
I run oz create, everything goes well, but I notice that the functions order have changed… no problem it deploy and initialize anyway because I select my own initializer (initialize())

All contracts have been deployed
? Do you want to call a function on the instance after creating
 it? Yes
? Select which function (Use arrow keys)
❯   * initialize(sender: address) 
  * initialize(name: string, symbol: string)
* initialize() 

Then this time everything go wrong with the truffle tests because when it run let init = await instance.initialize({from: accounts[0]});

Error: invalid address (arg="sender", coderType="address", value={"from":"0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"})
     at PromiEvent (/home/me/.npm-global/lib/node_modules/truffle/build/webpack:/packages/contract/lib/promievent.js:6:1)
      at TruffleContract.initialize (/home/me/.npm-global/lib/node_modules/truffle/build/webpack:/packages/contract/lib/execute.js:157:1)
      at Context.it (test/thing.truffle.test1.js:15:31)
      at process._tickCallback (internal/process/next_tick.js:68:7)

when I do

$ oz send-tx
? Pick a network development
? Pick an instance Thing at 0xA57B8a5584442B467b4689F1144D269d096A3daF
? Select which function pause()
✖ Calling: 'pause' with no arguments
Error while trying to send transaction to 0xA57B8a5584442B467b4689F1144D269d096A3daF. Error: Returned error: VM Exception while processing transaction: revert PauserRole: caller does not have the Pauser role

Here is my 'initialize()` (the only one in my contract)

    function initialize() public initializer {
        ERC721.initialize();
        ERC721Enumerable.initialize();
        ERC721Metadata.initialize("XXX", "XXX");
        ERC721MetadataMintable.initialize(msg.sender);
        Pausable.initialize(msg.sender);
        Ownable.initialize(msg.sender); 
        ReentrancyGuard.initialize();
    }

It took me a lot of time to notice that every time things go wrong I noticed the order changed in oz interactive command…

What it could be is that sometimes for eg ERC721.initialize() will be called instead of MyContract.initialize() ??? (I only see 1 initialize() in the oz interactive command).

Anyway my simple solution is to initialize with a initialize2() I hope it is ok.

Apart from that I am a very happy user of OpenZeppelin SDK :slight_smile:

1 Like