EnumerableMapMock.sol 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. contract Bytes32ToBytes32MapMock {
  69. using EnumerableMap for EnumerableMap.Bytes32ToBytes32Map;
  70. event OperationResult(bool result);
  71. EnumerableMap.Bytes32ToBytes32Map private _map;
  72. function contains(bytes32 key) public view returns (bool) {
  73. return _map.contains(key);
  74. }
  75. function set(bytes32 key, bytes32 value) public {
  76. bool result = _map.set(key, value);
  77. emit OperationResult(result);
  78. }
  79. function remove(bytes32 key) public {
  80. bool result = _map.remove(key);
  81. emit OperationResult(result);
  82. }
  83. function length() public view returns (uint256) {
  84. return _map.length();
  85. }
  86. function at(uint256 index) public view returns (bytes32 key, bytes32 value) {
  87. return _map.at(index);
  88. }
  89. function tryGet(bytes32 key) public view returns (bool, bytes32) {
  90. return _map.tryGet(key);
  91. }
  92. function get(bytes32 key) public view returns (bytes32) {
  93. return _map.get(key);
  94. }
  95. function getWithMessage(bytes32 key, string calldata errorMessage) public view returns (bytes32) {
  96. return _map.get(key, errorMessage);
  97. }
  98. }