EnumerableSetMock.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.6.0;
  3. import "../utils/EnumerableSet.sol";
  4. // AddressSet
  5. contract EnumerableAddressSetMock {
  6. using EnumerableSet for EnumerableSet.AddressSet;
  7. event OperationResult(bool result);
  8. EnumerableSet.AddressSet private _set;
  9. function contains(address value) public view returns (bool) {
  10. return _set.contains(value);
  11. }
  12. function add(address value) public {
  13. bool result = _set.add(value);
  14. emit OperationResult(result);
  15. }
  16. function remove(address 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 (address) {
  24. return _set.at(index);
  25. }
  26. }
  27. // UintSet
  28. contract EnumerableUintSetMock {
  29. using EnumerableSet for EnumerableSet.UintSet;
  30. event OperationResult(bool result);
  31. EnumerableSet.UintSet private _set;
  32. function contains(uint256 value) public view returns (bool) {
  33. return _set.contains(value);
  34. }
  35. function add(uint256 value) public {
  36. bool result = _set.add(value);
  37. emit OperationResult(result);
  38. }
  39. function remove(uint256 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 (uint256) {
  47. return _set.at(index);
  48. }
  49. }