EnumerableSetMock.sol 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.7.0;
  3. import "../utils/EnumerableSet.sol";
  4. // Bytes32Set
  5. contract EnumerableBytes32SetMock {
  6. using EnumerableSet for EnumerableSet.Bytes32Set;
  7. event OperationResult(bool result);
  8. EnumerableSet.Bytes32Set private _set;
  9. function contains(bytes32 value) public view returns (bool) {
  10. return _set.contains(value);
  11. }
  12. function add(bytes32 value) public {
  13. bool result = _set.add(value);
  14. emit OperationResult(result);
  15. }
  16. function remove(bytes32 value) public {
  17. bool result = _set.remove(value);
  18. emit OperationResult(result);
  19. }
  20. function length() public view returns (uint256) {
  21. return _set.length();
  22. }
  23. function at(uint256 index) public view returns (bytes32) {
  24. return _set.at(index);
  25. }
  26. }
  27. // AddressSet
  28. contract EnumerableAddressSetMock {
  29. using EnumerableSet for EnumerableSet.AddressSet;
  30. event OperationResult(bool result);
  31. EnumerableSet.AddressSet private _set;
  32. function contains(address value) public view returns (bool) {
  33. return _set.contains(value);
  34. }
  35. function add(address value) public {
  36. bool result = _set.add(value);
  37. emit OperationResult(result);
  38. }
  39. function remove(address value) public {
  40. bool result = _set.remove(value);
  41. emit OperationResult(result);
  42. }
  43. function length() public view returns (uint256) {
  44. return _set.length();
  45. }
  46. function at(uint256 index) public view returns (address) {
  47. return _set.at(index);
  48. }
  49. }
  50. // UintSet
  51. contract EnumerableUintSetMock {
  52. using EnumerableSet for EnumerableSet.UintSet;
  53. event OperationResult(bool result);
  54. EnumerableSet.UintSet private _set;
  55. function contains(uint256 value) public view returns (bool) {
  56. return _set.contains(value);
  57. }
  58. function add(uint256 value) public {
  59. bool result = _set.add(value);
  60. emit OperationResult(result);
  61. }
  62. function remove(uint256 value) public {
  63. bool result = _set.remove(value);
  64. emit OperationResult(result);
  65. }
  66. function length() public view returns (uint256) {
  67. return _set.length();
  68. }
  69. function at(uint256 index) public view returns (uint256) {
  70. return _set.at(index);
  71. }
  72. }