MultipleInheritanceInitializableMocks.sol 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.7.0;
  3. import "../proxy/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 initializer virtual {
  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 initializer virtual {
  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(uint256 _mother, string memory _gramps, uint256 _father, uint256 _child) public initializer {
  59. SampleMother.initialize(_mother);
  60. SampleFather.initialize(_gramps, _father);
  61. child = _child;
  62. }
  63. }