Check that upgraded contract doesn't violate storageDiff

I see that using oz upgrade will list out errors or warnings in red. Things like: “avoid deleting variables” or “only add variables at the end”, but then the deployment still happens. I’m wondering if there is a check that can be done before upgrade or maybe a flag with upgrade that will halt the upgrade if an error is detected.

I thought maybe oz check would serve this purpose but it seems to just give compiler errors.

1 Like

Hi @cthacker,

Welcome to the community :wave:

When doing an oz upgrade the warning is shown in red but at this stage the logic contract has already been deployed to the network.

The user can exit out of the upgrade prior to selecting which proxy to upgrade, so that no actual upgrade occurs, but it does result in a deployment of a logic contract.

$ oz upgrade
? Pick a network development
Nothing to compile, all contracts are up to date.
- New variable 'uint256 _b' was inserted in contract Example in contracts/Example.sol:1. You should only add new variables at the end of your contract.
See https://docs.openzeppelin.com/sdk/2.5/writing-contracts#modifying-your-contracts for more info.
✓ Contract Example deployed
All contracts have been deployed
? Which instances would you like to upgrade? (Use arrow keys)
❯ All instances
  Choose by name
  Choose by address                     

To test I used the following Example contracts:

Example.sol (original version)

pragma solidity ^0.5.0;

contract Example {
    uint256 private _a;

    function getA() public view returns(uint256) {
        return _a;
    }
}

Example.sol (new version)

pragma solidity ^0.5.0;

contract Example {
    uint256 private _b;
    uint256 private _a;

    function getA() public view returns(uint256) {
        return _a;
    }

    function getB() public view returns(uint256) {
        return _b;
    }
}

I assume the development process for an upgrade should include testing on a local network, testing on a public test network, testing against a local fork of mainnet prior to upgrading on mainnet.

I still can see the value of a way to check for these issues without deploying.
I have logged as an issue: https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1311

Thanks for reporting. :pray:

1 Like

Wow, quick reply – thank you!

I agree good testing is needed for any contract one would deploy. I guess I was just double checking that I hadn’t missed a feature somewhere. Thank you for creating the issue as well.

1 Like

Hi @cthacker,

Feel free to ask all the questions that you need.

If you have a moment it would be great to introduce yourself or share what you are working on with the community.