I try to use OpenZeppelin SDK to make my contracts upgradeable using the SimpleProxy approach. I need to test my contracts for upgrade compatibility (e.g prevent mistakes about unstructured storage during upgrading the contracts to a new version). According to OpenZeppelin docs, I can write these types of tests by something like this
But in the above code, I must import both versions and this means I need to add the version number to the end of the contract's name and create a copy whenever I want to upgrade the contract. But what if I want to only modify the old contract and use a version control system like git?
If this is not possible, how to deal with these versions and files? when I want to upgrade a contract, need to update all of the imports and parent contracts for every child contract? If I want to put the latest version of each contract in a separate directory, do I need to update all import paths whenever upgrading a contract?
It seems like you are using Truffle to have a test, and you want to compile some contracts with two different compiler versions, maybe you can change your truffle config like following:
module.exports = {
compilers: {
solc: {
version: βpragmaβ
}
},
// β¦ the rest of your config goes here
};
I think you have misunderstood. My question is about contract versions (using proxy contract pattern and open zeppelin upgrade) for improvement or bug fixing in the future, not solidity version!
Assume I have this directory structure and AnotherContract inherits MyContract:
So I must import MyContractV2.sol in AnotherContractV2.sol file:
import "./MyContractV2.sol";
If I want to change AnotherContractV2.sol, I must make a copy from AnotherContractV2.sol and rename it to AnotherContractV3.sol. Also, move AnotherContractV2.sol to old_versions dir. The new directory structure is:
Because of this, I need to update import paths.
If I want AnotherContractV2.sol to be still valid and compilable, the import path in this file must be updated to:
import "../MyContractV2.sol";
Upgrading MyContractV2.sol to MyContractV3.sol in the future needs even more code changing. This makes an extra effort for upgrading contracts to a new version, especially in bigger projects.
If I won't add a version number to the end of file names and keep only the last versions like this directory structure:
it means, I have no older versions and can't test upgrade compatibility in my test files. (In tests I need to deploy an old version, and upgrade it to the new version)