StorageSlotMock.sol 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {StorageSlot} from "../utils/StorageSlot.sol";
  4. contract StorageSlotMock {
  5. using StorageSlot for *;
  6. function setBooleanSlot(bytes32 slot, bool value) public {
  7. slot.getBooleanSlot().value = value;
  8. }
  9. function setAddressSlot(bytes32 slot, address value) public {
  10. slot.getAddressSlot().value = value;
  11. }
  12. function setBytes32Slot(bytes32 slot, bytes32 value) public {
  13. slot.getBytes32Slot().value = value;
  14. }
  15. function setUint256Slot(bytes32 slot, uint256 value) public {
  16. slot.getUint256Slot().value = value;
  17. }
  18. function setInt256Slot(bytes32 slot, int256 value) public {
  19. slot.getInt256Slot().value = value;
  20. }
  21. function getBooleanSlot(bytes32 slot) public view returns (bool) {
  22. return slot.getBooleanSlot().value;
  23. }
  24. function getAddressSlot(bytes32 slot) public view returns (address) {
  25. return slot.getAddressSlot().value;
  26. }
  27. function getBytes32Slot(bytes32 slot) public view returns (bytes32) {
  28. return slot.getBytes32Slot().value;
  29. }
  30. function getUint256Slot(bytes32 slot) public view returns (uint256) {
  31. return slot.getUint256Slot().value;
  32. }
  33. function getInt256Slot(bytes32 slot) public view returns (int256) {
  34. return slot.getInt256Slot().value;
  35. }
  36. mapping(uint256 key => string) public stringMap;
  37. function setStringSlot(bytes32 slot, string calldata value) public {
  38. slot.getStringSlot().value = value;
  39. }
  40. function setStringStorage(uint256 key, string calldata value) public {
  41. stringMap[key].getStringSlot().value = value;
  42. }
  43. function getStringSlot(bytes32 slot) public view returns (string memory) {
  44. return slot.getStringSlot().value;
  45. }
  46. function getStringStorage(uint256 key) public view returns (string memory) {
  47. return stringMap[key].getStringSlot().value;
  48. }
  49. mapping(uint256 key => bytes) public bytesMap;
  50. function setBytesSlot(bytes32 slot, bytes calldata value) public {
  51. slot.getBytesSlot().value = value;
  52. }
  53. function setBytesStorage(uint256 key, bytes calldata value) public {
  54. bytesMap[key].getBytesSlot().value = value;
  55. }
  56. function getBytesSlot(bytes32 slot) public view returns (bytes memory) {
  57. return slot.getBytesSlot().value;
  58. }
  59. function getBytesStorage(uint256 key) public view returns (bytes memory) {
  60. return bytesMap[key].getBytesSlot().value;
  61. }
  62. }