Solidity is the primary language for writing smart contracts on blockchain platforms like Celo. However, once a contract is deployed on the blockchain, it is immutable, meaning it cannot be modified or upgraded. To overcome this limitation, a common pattern used is the Proxy pattern, allowing for contracts to be upgraded. This challenge will focus on implementing this pattern.
Design a simple proxy contract and an upgradeable contract that will interact with each other. The challenge is as follows:
- Write an
Upgradeablecontract with a version number and a simple function to return the version number.
- Write a
Proxycontract that can delegate calls to the
Upgradeablecontract and upgrade the
Upgradeablecontract to a new version.
Proxycontract should only allow itself to upgrade the
Proxycontract to forward calls to the current
- To upgrade the
Proxycontract should change the address to which it forwards calls.
requireto ensure that only the
Proxycontract can upgrade the
- Correctness: The contract should compile without errors and fulfill all the requirements.
- Readability: The contract should be well-documented, with comments explaining the code.
- Testability: You should also provide examples of how to test each function of the contract.
Remember, handling real contracts on a blockchain requires extreme care and extensive testing. The upgrade pattern helps manage and upgrade contracts, but improper handling can lead to severe issues.
For a comprehensive understanding of Celo smart contracts and Solidity, please refer to the Celo and Solidity documentation.
Please reply with a link to your PR on GitHub - celo-academy/Upgradeable-Contracts-in-Solidity-The-Proxy-Pattern-Coding-Challenge, including your proxy and upgradeable contracts. Also, include any notes or comments you think are necessary to understand your design and choices. Lastly, provide a brief explanation about how each function of the contract should be tested.