MultipleInheritanceInitializableMocks.sol 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../proxy/utils/Initializable.sol";
  4. // Sample contracts showing upgradeability with multiple inheritance.
  5. // Child contract inherits from Father and Mother contracts, and Father extends from Gramps.
  6. //
  7. // Human
  8. // / \
  9. // | Gramps
  10. // | |
  11. // Mother Father
  12. // | |
  13. // -- Child --
  14. /**
  15. * Sample base intializable contract that is a human
  16. */
  17. contract SampleHuman is Initializable {
  18. bool public isHuman;
  19. function initialize() public initializer {
  20. isHuman = true;
  21. }
  22. }
  23. /**
  24. * Sample base intializable contract that defines a field mother
  25. */
  26. contract SampleMother is Initializable, SampleHuman {
  27. uint256 public mother;
  28. function initialize(uint256 value) public virtual initializer {
  29. SampleHuman.initialize();
  30. mother = value;
  31. }
  32. }
  33. /**
  34. * Sample base intializable contract that defines a field gramps
  35. */
  36. contract SampleGramps is Initializable, SampleHuman {
  37. string public gramps;
  38. function initialize(string memory value) public virtual initializer {
  39. SampleHuman.initialize();
  40. gramps = value;
  41. }
  42. }
  43. /**
  44. * Sample base intializable contract that defines a field father and extends from gramps
  45. */
  46. contract SampleFather is Initializable, SampleGramps {
  47. uint256 public father;
  48. function initialize(string memory _gramps, uint256 _father) public initializer {
  49. SampleGramps.initialize(_gramps);
  50. father = _father;
  51. }
  52. }
  53. /**
  54. * Child extends from mother, father (gramps)
  55. */
  56. contract SampleChild is Initializable, SampleMother, SampleFather {
  57. uint256 public child;
  58. function initialize(
  59. uint256 _mother,
  60. string memory _gramps,
  61. uint256 _father,
  62. uint256 _child
  63. ) public initializer {
  64. SampleMother.initialize(_mother);
  65. SampleFather.initialize(_gramps, _father);
  66. child = _child;
  67. }
  68. }