Memory.test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. async function fixture() {
  5. const mock = await ethers.deployContract('$Memory');
  6. return { mock };
  7. }
  8. describe('Memory', function () {
  9. beforeEach(async function () {
  10. Object.assign(this, await loadFixture(fixture));
  11. });
  12. describe('free pointer', function () {
  13. it('sets free memory pointer', async function () {
  14. const ptr = ethers.toBeHex(0xa0, 32);
  15. await expect(this.mock.$setFreeMemoryPointer(ptr)).to.not.be.reverted;
  16. });
  17. it('gets free memory pointer', async function () {
  18. await expect(this.mock.$getFreeMemoryPointer()).to.eventually.equal(
  19. ethers.toBeHex(0x80, 32), // Default pointer
  20. );
  21. });
  22. });
  23. describe('pointer conversions', function () {
  24. it('asBytes32', async function () {
  25. const ptr = ethers.toBeHex('0x1234', 32);
  26. await expect(this.mock.$asBytes32(ptr)).to.eventually.equal(ptr);
  27. });
  28. it('asPointer', async function () {
  29. const ptr = ethers.toBeHex('0x1234', 32);
  30. await expect(this.mock.$asPointer(ptr)).to.eventually.equal(ptr);
  31. });
  32. });
  33. });