Hi,
Firstly thank to this detailed awesome tutorial; UUPS Proxies: Tutorial (Solidity + JavaScript)
When "initialize" function has parameters, how to change next version these values ? Example ERC165 interface id. I created manually without interface object via bytes4 & keccak. I should change this in updated version, how to I do?
I guess, I can write both previus version and next version changable function for my contract TYPE_HASH storage value. But is it correctly way? I am not sure.
What do you thinks about this ?
I want to put splitted my codes, maybe it is helpful more than my question.
// contracts/Version.sol
contract Version is Initializable, ERC165Upgradeable, UUPSUpgradeable, OwnableUpgradeable {
// ERC164 Interface Id
bytes4 TYPE_HASH;
// Contract owner
address COWNER;
// ...
function initialize(bytes4 type_hash, uint256 continueIndex) initializer public {
TYPE_HASH = type_hash;
COWNER = msg.sender;
// ...
__ERC165_init();
__Ownable_init();
}
// ...
function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
return
interfaceId == TYPE_HASH ||
super.supportsInterface(interfaceId);
}
}
// contracts/Version_v2.sol
contract Version_v2 is Version {
function version() public pure returns(string memory) {
return "v2";
}
}
// tests/sample-test.js
beforeEach(async () => {
let Version_Factory = await hre.ethers.getContractFactory("Version");
Version = await upgrades.deployProxy(Version_Factory, ["0x4d74b2d4", BigNumber.from(0)], {kind: 'uups'});
});
// ...
it("UUPS Test", async function (){
let Version_v2_Factory = await hre.ethers.getContractFactory("Version_v2");
Version_v2 = await upgrades.upgradeProxy(Version, Version_v2_Factory);
expect(await Version_v2.version()).to.equal("v2");
});
Thank you for interest.
Good works.