EnumerableMapMock.sol 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. }