Problem adding new initialize function to upgradeable contract in tutorial

Hi,

So I have got further with the tutorial for creating and deploying an upgradeable contract. As per the tutorial (https://docs.zeppelinos.org/docs/upgrading.html) I have managed to deploy the initial contract, add the new increment function and all looks good. However when I try and add a new state variable and initialization function (initializeT) then I get the following errors when trying to access the variable from the truffle console:

truffle(development)> mc = await MyContract.at('0x66eB4e0368B726d4737fFaa9a3d16AE225F06493')
undefined
truffle(development)> mc.s()
'hitchiker'
truffle(development)> (await mc.x()).toString()
'44'
truffle(development)> (await mc.t()).toString()
Error: Invalid number of parameters for "t". Got 0 expected 2!

The contract was upgraded as follows:

rick@archlinux  ~/dev/zos  npx zos update MyContract --init initializeT --args 99
Using session with network development, sender address 0xED609586F5bE1ADc8d3f9f5a7cEA8Dab45a42A53, timeout 600 seconds
Upgrading proxy to logic contract 0x3203620c4aF995FB247C001885708ebf77E45d45 and initializing by calling initializeT with:

  • _t (uint256): “99”
    Upgrading proxy at 0x66eB4e0368B726d4737fFaa9a3d16AE225F06493 and calling initializeT with:
  • _t (uint256): “99”…
    TX receipt received: 0x9b834a4431be17d3772f0da6de215544fe3def1c407630db6b3bfbcf43979309
    Instance at 0x66eB4e0368B726d4737fFaa9a3d16AE225F06493 upgraded
    0x66eB4e0368B726d4737fFaa9a3d16AE225F06493
    Updated zos.dev-5777.json

Any ideas where I am going wrong here?

Cheers
Rick

1 Like

Hi @roy.batty

I followed the tutorial and am getting the same error as you Error: Invalid number of parameters for "t". Got 0 expected 2! when calling (await mc.t()).toString()

npx zos --version 2.2.3
npx truffle version Truffle v5.0.18 (core: 5.0.18)
npx ganache-cli Ganache CLI v6.4.3 (ganache-core: 2.5.5)

Running console.log(mc.methods) shows 't(uint256,string)' and doesn’t include a method for 't()'

I assume I am missing something in the upgrade process.

1 Like

Interesting… is it a coincidence that the method signature shown, 't(uint256, sttring)' is similar to the initial implementation of the initialize function in the first deployment of the contract?

FYI - my versions:
zos: 2.2.3
truffle: 5.0.18
ganache: 6.3.0

1 Like

Moved to #support:zeppelinos

1 Like

Hey folks! Could I ask you to test with a slightly older truffle version, such as 5.0.0, and see what happens? Thanks!

2 Likes

@roy.batty

I retried successfully with an earlier version of truffle and ganache-cli
npx zos --version 2.2.3
npx truffle version Truffle v5.0.2 (core: 5.0.2)
npx ganache-cli Ganache CLI v6.3.0 (ganache-core: 2.4.0)

This gave me an output as expected

truffle(local)> (await mc.t()).toString()
'99'
2 Likes

I have logged as an issue https://github.com/zeppelinos/zos/issues/906

1 Like

Hi @abcoathup @spalladino, thanks for following up with this… I will also try a different version of truffle.

Would this be a case of removing any existing truffle via ‘npm uninstall’ and then doing an ‘npm install truffle@5.0.0’?

Can I ask what the implications of this issue are? Does it mean that the upgradeability would not work if we were to inadvertently use an older version of truffle with zos?

Thanks
Rick

1 Like

Hi @roy.batty

To change versions of truffle it is just npm uninstall truffle and npm install truffle@5.0.4

I restarted the tutorial (deleted contents of MyContract.sol, deleted zos.dev...json and the build directory) and didn’t run into any issues. The tutorial currently states to use truffle@5.0.4. I also used ganache-cli 6.3.0.

The implications of something like this is that if you ever experienced an issue with a smart contract whilst testing an upgrade (either locally or on a testnet) then you could report on the forum to get a solution. Once you had a solution (which could be as simple as use a specific version) you could then retest locally and on testnets before upgrading on mainnet.

Let me know if you have any questions.

1 Like

Great, thanks @abcoathup… will let you know if all working with the previous truffle…

Hopefully the issue can be resolved so that future developers don’t experience any issues :pray:

Cheers
Rick

1 Like

Just to confirm I can also see that this is not an issue if I use an older version of truffle (5.0.0 in my case)… so something in a recent truffle update seems to have broken things…

Cheers
Rick

1 Like

Hey @roy.batty, thanks for reporting this! I've managed to reproduce this in a sample project without zOS at all. It would seem that the version of truffle that breaks this is 5.0.13 (.12 worked fine for me). I've filed this issue to report it, feel free to add any further info there.

This only seems to affect the ABI of the compiled artifact, not the bytecode nor the AST. So the contracts you are deploying or upgrading should be unaffected. This should only impact your client code, since when you try to call the contract, the truffle-contract object will have an incorrect ABI registered.

3 Likes

Thanks @spalladino. Looks like a fix is already in the works based on the comments in github :slight_smile:

Cheers
Rick

2 Likes

Issue https://github.com/trufflesuite/truffle/issues/2048 now fixed in Truffle v5.0.20

Reran tutorial with Truffle 5.0.20 successfully

1 Like

Should we change the post marked as solution to the latest one? The post from @abcoathup that mentions the version of Truffle that fixes this…

1 Like

I've added a quote to my reply and changed to mark as the solution.

Thanks @roy.batty good idea.

1 Like