I expect GetX to return 1 as this was supposed to be set during the upgrade process. However, it returns 0. Is this call functionality actually working, or am I doing something wrong?
Code to reproduce
FooV1
contract FooV1 {
uint256 public X;
function GetX() public view returns(uint256) {
return X;
}
}
FooV2
contract FooV2 {
uint256 public X;
function GetX() public view returns(uint256) {
return X;
}
function SetX(uint256 x) public{
X = x;
}
}
Thanks, this worked, but it calls it with msg.sender as address(0) which means a function marked as onlyOwner, or containing calls that depend on msg.sender being the deployer, will fail.
Is this a problem with the functionality not passing on the from value, or is there a way I can specify this in the call to upgradeProxy?
There is no way for msg.sender to be address(0) in this context. But it could be some address other than the one you're expecting. If you're using transparent proxies it will be the address of the ProxyAdmin instance.
If your contract was Ownable previously, then using an onlyOwner function will probably not work because the owner is probably not the ProxyAdmin.
If you're trying to make your contract Ownable in this upgrade, you will have a hard time initializing the owner variable because Ownable's initializer will refuse to run. This is something we're improving for next version.