EnumerableMapMock.sol 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../utils/structs/EnumerableMap.sol";
  4. // UintToAddressMap
  5. contract UintToAddressMapMock {
  6. using EnumerableMap for EnumerableMap.UintToAddressMap;
  7. event OperationResult(bool result);
  8. EnumerableMap.UintToAddressMap private _map;
  9. function contains(uint256 key) public view returns (bool) {
  10. return _map.contains(key);
  11. }
  12. function set(uint256 key, address value) public {
  13. bool result = _map.set(key, value);
  14. emit OperationResult(result);
  15. }
  16. function remove(uint256 key) public {
  17. bool result = _map.remove(key);
  18. emit OperationResult(result);
  19. }
  20. function length() public view returns (uint256) {
  21. return _map.length();
  22. }
  23. function at(uint256 index) public view returns (uint256 key, address value) {
  24. return _map.at(index);
  25. }
  26. function tryGet(uint256 key) public view returns (bool, address) {
  27. return _map.tryGet(key);
  28. }
  29. function get(uint256 key) public view returns (address) {
  30. return _map.get(key);
  31. }
  32. function getWithMessage(uint256 key, string calldata errorMessage) public view returns (address) {
  33. return _map.get(key, errorMessage);
  34. }
  35. }
  36. // AddressToUintMap
  37. contract AddressToUintMapMock {
  38. using EnumerableMap for EnumerableMap.AddressToUintMap;
  39. event OperationResult(bool result);
  40. EnumerableMap.AddressToUintMap private _map;
  41. function contains(address key) public view returns (bool) {
  42. return _map.contains(key);
  43. }
  44. function set(address key, uint256 value) public {
  45. bool result = _map.set(key, value);
  46. emit OperationResult(result);
  47. }
  48. function remove(address key) public {
  49. bool result = _map.remove(key);
  50. emit OperationResult(result);
  51. }
  52. function length() public view returns (uint256) {
  53. return _map.length();
  54. }
  55. function at(uint256 index) public view returns (address key, uint256 value) {
  56. return _map.at(index);
  57. }
  58. function tryGet(address key) public view returns (bool, uint256) {
  59. return _map.tryGet(key);
  60. }
  61. function get(address key) public view returns (uint256) {
  62. return _map.get(key);
  63. }
  64. function getWithMessage(address key, string calldata errorMessage) public view returns (uint256) {
  65. return _map.get(key, errorMessage);
  66. }
  67. }
  68. // Bytes32ToBytes32Map
  69. contract Bytes32ToBytes32MapMock {
  70. using EnumerableMap for EnumerableMap.Bytes32ToBytes32Map;
  71. event OperationResult(bool result);
  72. EnumerableMap.Bytes32ToBytes32Map private _map;
  73. function contains(bytes32 key) public view returns (bool) {
  74. return _map.contains(key);
  75. }
  76. function set(bytes32 key, bytes32 value) public {
  77. bool result = _map.set(key, value);
  78. emit OperationResult(result);
  79. }
  80. function remove(bytes32 key) public {
  81. bool result = _map.remove(key);
  82. emit OperationResult(result);
  83. }
  84. function length() public view returns (uint256) {
  85. return _map.length();
  86. }
  87. function at(uint256 index) public view returns (bytes32 key, bytes32 value) {
  88. return _map.at(index);
  89. }
  90. function tryGet(bytes32 key) public view returns (bool, bytes32) {
  91. return _map.tryGet(key);
  92. }
  93. function get(bytes32 key) public view returns (bytes32) {
  94. return _map.get(key);
  95. }
  96. function getWithMessage(bytes32 key, string calldata errorMessage) public view returns (bytes32) {
  97. return _map.get(key, errorMessage);
  98. }
  99. }
  100. // UintToUintMap
  101. contract UintToUintMapMock {
  102. using EnumerableMap for EnumerableMap.UintToUintMap;
  103. event OperationResult(bool result);
  104. EnumerableMap.UintToUintMap private _map;
  105. function contains(uint256 key) public view returns (bool) {
  106. return _map.contains(key);
  107. }
  108. function set(uint256 key, uint256 value) public {
  109. bool result = _map.set(key, value);
  110. emit OperationResult(result);
  111. }
  112. function remove(uint256 key) public {
  113. bool result = _map.remove(key);
  114. emit OperationResult(result);
  115. }
  116. function length() public view returns (uint256) {
  117. return _map.length();
  118. }
  119. function at(uint256 index) public view returns (uint256 key, uint256 value) {
  120. return _map.at(index);
  121. }
  122. function tryGet(uint256 key) public view returns (bool, uint256) {
  123. return _map.tryGet(key);
  124. }
  125. function get(uint256 key) public view returns (uint256) {
  126. return _map.get(key);
  127. }
  128. function getWithMessage(uint256 key, string calldata errorMessage) public view returns (uint256) {
  129. return _map.get(key, errorMessage);
  130. }
  131. }
  132. // Bytes32ToUintMap
  133. contract Bytes32ToUintMapMock {
  134. using EnumerableMap for EnumerableMap.Bytes32ToUintMap;
  135. event OperationResult(bool result);
  136. EnumerableMap.Bytes32ToUintMap private _map;
  137. function contains(bytes32 key) public view returns (bool) {
  138. return _map.contains(key);
  139. }
  140. function set(bytes32 key, uint256 value) public {
  141. bool result = _map.set(key, value);
  142. emit OperationResult(result);
  143. }
  144. function remove(bytes32 key) public {
  145. bool result = _map.remove(key);
  146. emit OperationResult(result);
  147. }
  148. function length() public view returns (uint256) {
  149. return _map.length();
  150. }
  151. function at(uint256 index) public view returns (bytes32 key, uint256 value) {
  152. return _map.at(index);
  153. }
  154. function tryGet(bytes32 key) public view returns (bool, uint256) {
  155. return _map.tryGet(key);
  156. }
  157. function get(bytes32 key) public view returns (uint256) {
  158. return _map.get(key);
  159. }
  160. function getWithMessage(bytes32 key, string calldata errorMessage) public view returns (uint256) {
  161. return _map.get(key, errorMessage);
  162. }
  163. }