StorageSlotMock.sol 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 setBoolean(bytes32 slot, bool value) public {
  7. slot.getBooleanSlot().value = value;
  8. }
  9. function setAddress(bytes32 slot, address value) public {
  10. slot.getAddressSlot().value = value;
  11. }
  12. function setBytes32(bytes32 slot, bytes32 value) public {
  13. slot.getBytes32Slot().value = value;
  14. }
  15. function setUint256(bytes32 slot, uint256 value) public {
  16. slot.getUint256Slot().value = value;
  17. }
  18. function getBoolean(bytes32 slot) public view returns (bool) {
  19. return slot.getBooleanSlot().value;
  20. }
  21. function getAddress(bytes32 slot) public view returns (address) {
  22. return slot.getAddressSlot().value;
  23. }
  24. function getBytes32(bytes32 slot) public view returns (bytes32) {
  25. return slot.getBytes32Slot().value;
  26. }
  27. function getUint256(bytes32 slot) public view returns (uint256) {
  28. return slot.getUint256Slot().value;
  29. }
  30. mapping(uint256 => string) public stringMap;
  31. function setString(bytes32 slot, string calldata value) public {
  32. slot.getStringSlot().value = value;
  33. }
  34. function setStringStorage(uint256 key, string calldata value) public {
  35. stringMap[key].getStringSlot().value = value;
  36. }
  37. function getString(bytes32 slot) public view returns (string memory) {
  38. return slot.getStringSlot().value;
  39. }
  40. function getStringStorage(uint256 key) public view returns (string memory) {
  41. return stringMap[key].getStringSlot().value;
  42. }
  43. mapping(uint256 => bytes) public bytesMap;
  44. function setBytes(bytes32 slot, bytes calldata value) public {
  45. slot.getBytesSlot().value = value;
  46. }
  47. function setBytesStorage(uint256 key, bytes calldata value) public {
  48. bytesMap[key].getBytesSlot().value = value;
  49. }
  50. function getBytes(bytes32 slot) public view returns (bytes memory) {
  51. return slot.getBytesSlot().value;
  52. }
  53. function getBytesStorage(uint256 key) public view returns (bytes memory) {
  54. return bytesMap[key].getBytesSlot().value;
  55. }
  56. }