Memory.t.sol 692 B

123456789101112131415161718192021
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {Test} from "forge-std/Test.sol";
  4. import {Memory} from "@openzeppelin/contracts/utils/Memory.sol";
  5. contract MemoryTest is Test {
  6. using Memory for *;
  7. // - first 0x80 bytes are reserved (scratch + FMP + zero)
  8. uint256 constant START_PTR = 0x80;
  9. // - moving the free memory pointer to far causes OOG errors
  10. uint256 constant END_PTR = type(uint24).max;
  11. function testGetsetFreeMemoryPointer(uint256 seed) public pure {
  12. bytes32 ptr = bytes32(bound(seed, START_PTR, END_PTR));
  13. ptr.asPointer().setFreeMemoryPointer();
  14. assertEq(Memory.getFreeMemoryPointer().asBytes32(), ptr);
  15. }
  16. }